Display +,- sign for amounts field in COBOL.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Sanjay Mainframe
Registered Member
Posts: 10
Joined: Tue Mar 18, 2014 11:16 am

Display +,- sign for amounts field in COBOL.

Post by Sanjay Mainframe »

Hi,

I want to display +,- sign for amounts field and decimal point and don’t want to suppress leading zeroes . How to declare this output variable? Please advise.
User avatar
zum13
Registered Member
Posts: 85
Joined: Thu May 04, 2023 12:58 am

Re: Display +,- sign for amounts field in COBOL.

Post by zum13 »

Hello.

Declare it as "PIC +9(nn)" where "nn" is the length you need. You can also do something like "+999,999,999" if you want the output delimited with commas.

The "9" causes the number to be displayed no matter what. A "Z" is used if you want leading zeros to be suppressed.

The "+" forces both the "+" and "-" symbols to be displayed. If you specify "-", then a negative number will show as "-", but a positive number will only give a space.
User avatar
zum13
Registered Member
Posts: 85
Joined: Thu May 04, 2023 12:58 am

Re: Display +,- sign for amounts field in COBOL.

Post by zum13 »

...just realised I missed the bit about the decimal point. You do that just by splitting the "PIC +9(nn)" definiton with a decimal point, e.g. "PIC +9(5).99" will give you a seven digit number with two decimal places.
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.”