Page 1 of 1
Display +,- sign for amounts field in COBOL.
Posted: Mon Oct 23, 2023 12:05 am
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.
Re: Display +,- sign for amounts field in COBOL.
Posted: Mon Oct 23, 2023 4:09 am
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.
Re: Display +,- sign for amounts field in COBOL.
Posted: Mon Oct 23, 2023 4:39 am
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.