How to display sign only in case of negative number in cobol



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

How to display sign only in case of negative number in cobol

Postby gauthamnagpur18 » Fri Apr 08, 2016 6:24 pm

Hi,

I need help on signed integer concept.

I have defined output variable as PIC S9(07)V99 SIGN LEADING SEPARATE.

By this way, we are getting sign before the number .

I got requirement to display sign only in the case of negative. In case of positive, number should not come with positive sign.

Thanks in advance.
gauthamnagpur18
 
Posts: 93
Joined: Sat Oct 23, 2010 1:28 pm
Location: Chennai, India
Has thanked: 3 times
Been thanked: 3 times

Re: How to display sign only in case of negative number in c

Postby BillyBoyo » Fri Apr 08, 2016 6:45 pm

You use a numeric-edited PICture, and specify at least on "-" (minus sign) in an appropriate place. The "-" position will appear as that character for a negative value, but space will appear instead if positive.

If you want "+" to appear instead of space, and still have the "-" for negative values, you'd use a "+" (plus sign) in the PICture instead.

These users thanked the author BillyBoyo for the post:
gauthamnagpur18 (Sat Apr 09, 2016 10:45 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to display sign only in case of negative number in c

Postby Terry Heinze » Fri Apr 08, 2016 7:17 pm

In the COBOL Language Reference Manual, see DATA DIVISION, PICTURE Clause, Fixed insertion editing.
.... Terry

These users thanked the author Terry Heinze for the post:
gauthamnagpur18 (Sat Apr 09, 2016 10:45 pm)
Terry Heinze
 
Posts: 239
Joined: Wed Dec 04, 2013 11:08 pm
Location: Richfield, MN, USA
Has thanked: 12 times
Been thanked: 11 times

Re: How to display sign only in case of negative number in c

Postby gauthamnagpur18 » Sat Apr 09, 2016 10:44 pm

Hi,

Thanks all for your help.It worked out.

I have declared variable as PIC -9(07)V99.

:D :D :D
gauthamnagpur18
 
Posts: 93
Joined: Sat Oct 23, 2010 1:28 pm
Location: Chennai, India
Has thanked: 3 times
Been thanked: 3 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post