Click here to Skip to main content
15,566,625 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm learning COBOL. I have a text file with a numeric field that has a decimal point in it. I have defined the field as PIC 9(5)V99. When a record is read and the field as a decimal point it I get this error not numeric: '.00 '. But if I remove the decimal point from the field in that record, there is not an error. I don't have the option to request a file without the decimal point in that field.

What I have tried:

I tried using PIC 9(5).99. But then I get the compiler error

field is not a numeric value

This is not a problem using Microfocus cobol.
Posted
Updated 3-Jun-17 2:24am

1 solution

Declaring your variable type as PIC 9(5).99 seems perfectly legal - why should the compiler flag an error!

But if you had
myvar pic 9(5)V99
the 'V' is only an implied decimal point - variable myvar can hold only digits.
Coding: move 147.25 to myvar - this will set myvar to 0014725 and if you wrote this to a text file the contents would be 0014725 and not 147.25.

I can suggest a VERY UGLY solution but it may (mostly will) work.

in
data division.
working-storage section.
01 file-buffer pic x(8) justified right.
01 r-file-buffer redefines file-buffer.
10 f-int-part pic 9(5).
10 filler pic x
10 f-fract-part pic 99.

01 numvar pic 9(5)V99.
01 r-numvar redefines numvar.
10 numvar-int pic 9(5).
10 numvar-fract pic 99.

procedure division.
read myfile into file-buffer.
move f-int-part to numvar-int.
move f-fract-part to numvar-fract.


It's 20+ years since I did anything in COBOL.
 
Share this answer
 
Comments
JohnnyG62 4-Jun-17 22:46pm    
Some one showed me a solution for this. I want to document in case this will help others.

I changed the PIC for the input file

LASTSALEAMTIN TO PIC X(13).

Then I added a field in working storage
01 LASTSALE PIC 9(9)V99.

Then added this to the procedure division
MOVE FUNCTION NUMVAL(LASTSALEAMTIN) to LASTSALE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900