4

I have fixed-point numbers in file, one in each line, in this format S9(6)V9(2) but when they are actually read, I'm getting non numeric errors while trying to put them in math operations. What is more, when I try to display them in program, a number that is written in file as 567123.45 is saved in variable as +567123.04. And for example the number from file 123.45 is saved in variable as +123.45.00 and it provokes the following error 'WS-VALUE' not numeric: '123.45 0' during a math operation. Why is that? I'm using OpenCobolIDE 4.7.4 for Windows.

EDIT: File has records of the following form separated by new lines (read by READ operation record after record):

  01 WS-OPERATION.
     05 WS-ID PIC A(2).
     05 WS-CLIENT PIC 9(5).
     05 WS-COUNTRY PIC A(4).
     05 WS-VALUE PIC S9(6)V9(2). 
Quentin
  • 1,090
  • 13
  • 24
  • First: these aren't floating point items as only `USAGE FLOAT...` are floating point items. These are actually fixed point items. Questions: What compiler do you use? I assume the standard shipped GnuCOBOL 1.1 - If you changed the compiler paths you find this info in Menu ?->About OpenCobolIDE. How do you read the file, how does the file and its record description look like? How does the `DISPLAY` statement look like? – Simon Sobisch Jul 28 '16 at 20:52
  • Yes, I'm using version 1.1.0. I've edited the post about the file structure. – Quentin Jul 28 '16 at 21:06
  • I highly suggest to edit the "floating-point" part to "fixed-point", too. – Simon Sobisch Jul 28 '16 at 21:17
  • Your records are not fixed-length, are they? Even if they are, the data is "left-justified" in the field, isn't it? Can you add some actual, as it appear, full data records to your question, please? – Bill Woodger Jul 29 '16 at 15:53
  • To answer your specific question `Why is that?`, it's because `+123.45.00` is not valid numeric; numeric field values won't have two decimal points. And it isn't in `S9(6)V9(2)` form. – user2338816 Aug 02 '16 at 05:59
  • @Quentin, does the provided answer work for you? If yes: please mark it as answer, if no: please comment on the answer what you miss. – Simon Sobisch Aug 08 '16 at 08:44

1 Answers1

5

The reason is that you try to un-edit a field. 567123.45 in the data is not conforming to PIC S9(6)V9(2) but to -9(6).9(2). - internal stored data vs. print-data.

Simply changing the definition and use MOVE WS-VALUE TO WS-VALUE-INTERNAL (which is defined like you want to) may work with a specific compiler (and specific data) but I'd go a different route:

I'd suggest to always validate the data before doing something with it (the file may be broken or external edited). At least check the simple numeric data like WS-CLIENT for IS NUMERIC and either do a full validation on the data field WS-VALUE or at least use MOVE FUNCTION NUMVAL(WS-VALUE) TO WS-VALUE-INTERNAL.

Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38