Reading floating-point numbers from file in COBOL



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Reading floating-point numbers from file in COBOL

Postby Quentin » Fri Jul 29, 2016 2:08 am

I have floating-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.
Quentin
 
Posts: 2
Joined: Fri Jul 29, 2016 2:02 am
Has thanked: 0 time
Been thanked: 0 time

Re: Reading floating-point numbers from file in COBOL

Postby Akatsukami » Fri Jul 29, 2016 2:49 am

As this is a mainframe help board, you are unlikely to get a definitive answer here (even if you had shown code, representative data, etc.) One thing I will note, however, is that even on a toy computer, those are not floating-point numbers.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Reading floating-point numbers from file in COBOL

Postby Quentin » Fri Jul 29, 2016 2:56 am

Yes, sorry, those are fixed-point numbers.

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
 
Posts: 2
Joined: Fri Jul 29, 2016 2:02 am
Has thanked: 0 time
Been thanked: 0 time

Re: Reading floating-point numbers from file in COBOL

Postby Robert Sample » Fri Jul 29, 2016 2:59 am

I see several issues:
1. "Floating point" is a very specific type of data and you apparently have no clue what it is. With COBOL, you declare floating point as COMP-1 or COMP-2 -- nothing else. Using a PICTURE clause means you do NOT have floating point values.
2. If your data is in a file as 567123.45 and you declared that is PIC 9(6)V9(2) then yes of course your data will be 567123.04 -- apparently you do not know what a V in a PICTURE means, either.
3. Is your 123.45 value stored left-justified with trailing blanks? If so, then your PIC does not match the data (which is also part of point 2) and hence the results you got are normal and expected.

A floating point value would look like +5.671345E+05 (or some variation thereof). If your version of COBOL supports intrinsic functions, you may want to investigate the NUMVAL function. In any case, I STRONGLY recommend you spend a lot of time reading the COBOL user's guide for your version of COBOL.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post