Reading floating point numbers from a file in COBOL

I have fixed point numbers in a file, one in each line, in this format S9(6)V9(2), but when they are actually read, I get errors non numerictrying to put them into mathematical operations. Moreover, when I try to display them in the program, the number written in the file as 567123.45 is stored in the variable as +567123.04 . And, for example, the number from the file 123.45 is stored in the variable as +123.45.00 , and this causes the following error during the mathematical operation 'WS-VALUE' not numeric: '123.45 0'. Why is this? I am using OpenCobolIDE 4.7.4 for Windows.

EDIT: The file has records of the following form, separated by new lines (read by writing READafter writing):

  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). 
+4
source share
1 answer

The reason is because you are trying to remove field editing. 567123.45in the data does not match PIC S9(6)V9(2), but -9(6).9(2).are the internal stored data and print data. A.

A simple change of definition and use MOVE WS-VALUE TO WS-VALUE-INTERNAL(which is defined the way you want) can work with a specific compiler (and specific data), but I would go the other way:

, - ( ). , , WS-CLIENT IS NUMERIC, WS-VALUE, , , MOVE FUNCTION NUMVAL(WS-VALUE) TO WS-VALUE-INTERNAL.

+5

Source: https://habr.com/ru/post/1649461/


All Articles