how to the a binary field PIC S9(4) COMP.



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

how to the a binary field PIC S9(4) COMP.

Postby helen2000 » Tue Apr 11, 2017 9:02 pm

Hello,

there is a filed WS-AAA PIC S9(4) COMP, if there is a statement MOVE -32767 TO WS-AAA, do you have some idea how to check
the real value in memory for WS-AAA , thanks,

Helen
helen2000
 
Posts: 85
Joined: Sat Aug 08, 2009 9:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to the a binary field PIC S9(4) COMP.

Postby Robert Sample » Tue Apr 11, 2017 9:27 pm

First, the value stored in memory will depend upon the compile option TRUNC. TRUNC(STD) limits a binary (COMP) variable's value to the PICTURE size, while TRUNC(BIN) allows the binary (COMP) variable's value to reflect the memory size instead of the PICTURE size.

Second, if you read the COBOL Language Definition and Programming Guide manuals, you do not have to "check the real value in memory" because you will know with TRUNC(BIN) it will be X'8001' and with TRUNC(STD) it will be X'F531'.

If you really want to see the actual memory usage, you can call CEE3DMP (make sure you use compile option TEST or TEST(h,SYM) as appropriate).
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: how to the a binary field PIC S9(4) COMP.

Postby helen2000 » Tue Apr 11, 2017 9:44 pm

thank you Robert for your quick response,
could you tell me what is difference TRUNC(BIN) and TRUNC(STD)?
helen2000
 
Posts: 85
Joined: Sat Aug 08, 2009 9:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to the a binary field PIC S9(4) COMP.

Postby Robert Sample » Tue Apr 11, 2017 10:10 pm

Since I've already told you the difference, I highly recommend you bookmark http://www-01.ibm.com/support/docview.wss?uid=swg27036733 and learn how to look things up on your own. The Language Reference and Programming Guide manuals are ones you'll need to reference frequently to find out how Enterprise COBOL treats variables (among other things). The Programming Guide goes through EVERY possible compiler option and what the various values mean, while the Language Reference is the definitive source of how COBOL on the mainframe handles language constructs. From there, you may wind up needing other manuals (such as the Language Environment manuals) but start with the basics.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: how to the a binary field PIC S9(4) COMP.

Postby helen2000 » Thu Apr 20, 2017 3:22 am

Hello Robert,

as your suggestion, I read the link you mentioned, and I built a sample for WS-AAA binary field PIC S9(4) COMP.
after "move -4096 to WS-AAA", I checked the dump and got the hex value x'F000' for WS-AAA, it's correct,
but when I display WS-AAA, got the output result is 4090,
it's wired, do you know why? thanks,

Helen
helen2000
 
Posts: 85
Joined: Sat Aug 08, 2009 9:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to the a binary field PIC S9(4) COMP.

Postby BillyBoyo » Thu Apr 20, 2017 3:45 am

You have to read more carefully. You don't get 4090 you get 409O. Do you see the difference? The letter O is showing that you have a negative number ending with six.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: how to the a binary field PIC S9(4) COMP.

Postby helen2000 » Fri Apr 21, 2017 9:57 am

thanks BillyBoyo for your detail explain, do you know why the letter O stand for "a negative number ending with 6"? thanks again,
helen2000
 
Posts: 85
Joined: Sat Aug 08, 2009 9:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: how to the a binary field PIC S9(4) COMP.

Postby enrico-sorichetti » Fri Apr 21, 2017 11:12 am

do you know why the letter O stand for "a negative number ending with 6"?

because the designers of the architecture decided so :ugeek:

anyway the IBM Principle of Operations will tell all You might want to know about how numeric data is stored

http://www-01.ibm.com/support/docview.w ... 7dee&aid=1

( not the last one but more than enough )
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: how to the a binary field PIC S9(4) COMP.

Postby Robert Sample » Fri Apr 21, 2017 5:12 pm

do you know why the letter O stand for "a negative number ending with 6"?
The Language Reference manual explains, in detail, the internal representation of numbers for zoned decimal, packed decimal, and binary. Read it.

Asking "why" questions is rarely worthwhile on this or any forum. Assuming your question is a "how" question (as in how does O represent a negative 6), you have your answer already. Assuming your question is a "why" question (as in why zoned decimals code the sign in the last byte, or why D was chosen for negative numbers), Enrico's answer is the best you'll get. Why design decisions were made the way we see them requires going back more than 50 years and also requires a knowledge of prior coding systems such as BCD. Rather than ask why, just accept that this is the way it is and move on.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: how to the a binary field PIC S9(4) COMP.

Postby BillyBoyo » Fri Apr 21, 2017 10:31 pm

ACCEPT and DISPLAY in Enterprise COBOL and prior IBM Mainframe COBOLs are very limited (and Standard) in their operation. They are not intended for general-purpose use in producing/consuming formatted data.

If you define a numeric-edited field and MOVE the binary value to that, and then DISPLAY the numeric-edited field, you'll get a much more "friendly" output.

01 to-show-a-signed-binary PIC -99999. (five digits in case you have TRUNC(BIN), else four).

If you were to DISPLAY a binary defined with decimal places, you wouldn't get any in your output. Again, define a numeric edited field to show those if you ever have them.

Without using numeric-edited fields, you are getting output which distinguishes between + and -, but without showing you are sign (which sign would you want, leading, trailing, CR/DB)?

If you try it, you'll find a similar thing with zoned-decimal and packed-decimal. Instead of relying on the default values for the representation of DISPLAY, use numeric-edited if you want to see the value which would be represented on a report or screen, and REDEFINES the field as a PIC (or have the fields subordinate to a group-item) and DISPLAY that field (and use HEX when looking at the output) if you want to see the internal representation - the value prior to what was produced by the editing (useful if you feel there may be bad data in your field).
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post