Weired COBOL output.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.

Topic author
Johny Garg
New Member
Posts: 2
Joined: Sat Nov 22, 2014 10:00 pm

Weired COBOL output.

Postby Johny Garg » Tue Aug 01, 2017 6:24 pm


Please see this:

Code: Select all

           05 WS-A PIC S9(9) COMP-3.
           05 WS-B PIC 9(9).99.
    MOVE 0.4012 TO WS-A.
    DISPLAY "A to B: " WS-B.

Code: Select all

output is 0000000000.00

Should not the output be 0000000000.40?

User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1275
Joined: Fri Jun 28, 2013 1:22 am
Location: East Dubuque Illinois
Has thanked: 2 times
Been thanked: 90 times

Re: Weired COBOL output.

Postby Robert Sample » Tue Aug 01, 2017 6:59 pm

No, the output is what it should be. Moving 0.4012 to WS-A changes the value to zero. Why? Because A has no decimal digits (if not specified, the decimal point is to the RIGHT of the last digit in a PICTURE). Hence the .4012 gets discarded and the value moved to WS-B is 0.

Update: your output does not match the PICTURE clause, too. Your output has 10 digits before the decimal point but WS-B is defined with 9 digits before the decimal point. If you want to post output, post the ACTUAL output, not whatever you interpret the output to be -- many times, your interpretation may not be right and you lose critical information by editing the output (such as adding an extra digits to the output).

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”

Who is online

Users browsing this forum: CommonCrawl [Bot] and 2 guests