PIC 9(3) vs PIC S9(3).

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
KavalJeet
Registered Member
Posts: 48
Joined: Wed Jun 19, 2013 9:47 am

PIC 9(3) vs PIC S9(3).

Post by KavalJeet »

Hi,

If both of these have positive numbers - is PIC 9(3) same as PIC S9(3)?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1896
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: PIC 9(3) vs PIC S9(3).

Post by Robert Sample »

It depends upon what you mean by "same". If you are asking about the values, then yes both will have positive values. If you mean are the hexadecimal internal representations the same, the answer is then that they are NOT the same. PIC 9(3) is an unsigned variable so 123 would be stored as X'F1F2F3' whereas PIC S9(3) is a signed variable so 123 would be stored as X'F1F2C3'. Both would DISPLAY as 123. Information on how COBOL stores values can be found in the Language Reference manual which you should be able to access at your site.
KavalJeet
Registered Member
Posts: 48
Joined: Wed Jun 19, 2013 9:47 am

Re: PIC 9(3) vs PIC S9(3).

Post by KavalJeet »

Thanks Robert. Yes, i needed to know about their internal representation.

Is there some easy reference for this concept?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1896
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: PIC 9(3) vs PIC S9(3).

Post by Robert Sample »

The Enterprise COBOL Programming Reference manual has a chapter on internal representation of data, so that should be where you start.
dick scherrer
Former Team Member
Posts: 62
Joined: Wed Aug 07, 2013 6:43 pm

Re: PIC 9(3) vs PIC S9(3).

Post by dick scherrer »

Keep in mind that while both support positive values, if the 2 definitions are in different group fields, a comparison of the 2 groups will often compare not equal.
Depends on if the value has an F sign or a C sign. . .

While reading the manual, suggest you experiment with a bit of test code.
Hope this helps,
d
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.”