Weired COBOL output.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Johny Garg
New Member
Posts: 2
Joined: Sat Nov 22, 2014 10:00 pm

Weired COBOL output.

Post by Johny Garg »

Hi,

Please see this:

Code: Select all

01 WS-COUNTER.
           05 WS-A PIC S9(9) COMP-3.
           05 WS-B PIC 9(9).99.
PROCEDURE DIVISION.
    MOVE 0.4012 TO WS-A.
    MOVE WS-A TO WS-B.
    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: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Weired COBOL output.

Post by Robert Sample »

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).
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

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