IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Behaviour of COMP-3


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Harsha1525

New User


Joined: 22 Dec 2009
Posts: 24
Location: hyderabad

PostPosted: Wed Feb 27, 2013 2:41 pm
Reply with quote

My fields declaration is like this:
Code:

01 WS-COMP3-POSITIVE        PIC S9(4) COMP-3 VALUE +1234.
01 WS-COMP3-NEGATIVE        PIC S9(4) COMP-3 VALUE -1234.

According to my understanding COMP-3 fields store the data in following way:
Code:
Value                COMP-3,HEX
+1234                01 23 4C
-1234                01 23 4D

this is my display code.
Code:

DISPLAY 'WS-COMP3-POSITIVE IS'WS-COMP3-POSITIVE.
DISPLAY 'WS-COMP3-NEGATIVE IS'WS-COMP3-NEGATIVE.


while displaying it follow the EBCDIC conversion technique and it display a value
if I display above two fields I am expecting values like
WS-COMP3-POSITIVE IS 123<
WS-COMP3-NEGATIVE IS 123( because 4C in ebcdic is < and 4D is (
but my surprise my spool output is like this
WS-COMP3-POSITIVE IS 1234
WS-COMP3-NEGATIVE IS 123M
unable to understand this behaviour for the comp-3 ?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Feb 27, 2013 3:19 pm
Reply with quote

Is this really Homework? If not, it should be in the Cobol part of the forum.

X'01234C' is correct, as is the negative one. How it appears when you DISPLAY it, you have to think about.

Taking the negative as an example, what you have suggested is the expected output is a mix of hex values (the "23"), characters represented by hex values (the "(") and an non-directly accessible half byte (the "1"). So, it is unlikely that you'd get that output. More than unlikely.

So, what is DISPLAY doing? It takes your packed-decimal, turns it into a USAGE DISPLAY. If it is signed, the sign will be represented by an "overpunch" which will make the last number look like something else. In the Cobol forum, there is a "sticky" which shows you want those values with overpunches mean.

Your "appears as 1234" example is not what I'd expect. Did you record this accurately? For a signed field with a positive value you'd get "123D".
Back to top
View user's profile Send private message
Harsha1525

New User


Joined: 22 Dec 2009
Posts: 24
Location: hyderabad

PostPosted: Wed Feb 27, 2013 5:17 pm
Reply with quote

Bill, Thank you for your time.
Bill Woodger wrote:

Is this really Homework? If not, it should be in the Cobol part of the forum.

it is kind of self home work.last time when i asked similar questions argued that looking like homework. so i posted here icon_sad.gif


Bill Woodger wrote:

Your "appears as 1234" example is not what I'd expect. Did you record this accurately? For a signed field with a positive value you'd get "123D".

if my declaration is only PIC S9(4) then it is displaying as
Code:
WS-SIGN-POSITIVE  IS 123D
WS-SIGN-NEGATIVE  IS 123M 

I can understand why because last digit "4" it store like below
for the positive value it is C4 for the negative value it is D4

As C4 represent D it display 123D
As D4 represent M it display 123M

if i apply same interpretation to COMP-3 it should be
WS-COMP3-POSITIVE IS 123<
WS-COMP3-NEGATIVE IS 123(
but actual result is not.

I am with z/OS V1.13. i believe it does not have to do anything with this version. couple of times i misunderstood in the past by reading old version manualss
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Feb 27, 2013 5:33 pm
Reply with quote

Quote:
f i apply same interpretation to COMP-3 it should be
WS-COMP3-POSITIVE IS 123<
WS-COMP3-NEGATIVE IS 123(
but actual result is not.
This would be true if -- and only if -- you are looking at the actual binary representation of the data in the variable. Since COBOL converts a USAGE COMP-3 value to USAGE DISPLAY as part of the processing for the DISPLAY statement, the only way you would see the < or ( would be to write the COMP-3 variable to a file and then browse / view / edit the file in TSO/ISPF. And if you did this, you would NOT see '123' but rather X'01' and X'23' characters.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Feb 27, 2013 6:16 pm
Reply with quote

As Robert says, when you DISPLAY a packed-decimal (or binary) it is converted to a zoned-decimal (or USAGE DISPLAY) field, so behaves in the same way as your plain PIC S9(4).

The conversion "flips" the sign from the packed-decimal sign.

X'01234C' (as a PIC S9(4) COMP-3/PACKED-DECIMAL) becomes X'F1F2F3C4", exactly what you get in your plain PIC S9(4).

I'm still curious about the 1234 result you showed. Was that a typo?
Back to top
View user's profile Send private message
Harsha1525

New User


Joined: 22 Dec 2009
Posts: 24
Location: hyderabad

PostPosted: Thu Feb 28, 2013 3:10 pm
Reply with quote

Robert Sample wrote:
Since COBOL converts a USAGE COMP-3 value to USAGE DISPLAY as part of the processing for the DISPLAY statement.

Thank you Robert. i agree with above statement. and Cobol should be following some pattern behind the scenes .for the S9(N) pattern is perfectly matching with the way it storing internally unlike Comp-3.
Back to top
View user's profile Send private message
Harsha1525

New User


Joined: 22 Dec 2009
Posts: 24
Location: hyderabad

PostPosted: Thu Feb 28, 2013 3:16 pm
Reply with quote

Bill Woodger wrote:
I'm still curious about the 1234 result you showed. Was that a typo?


I do not have the luck. it is displaying 1234 only. and curious thing is, it is not the case with negative numbers. what I am trying to do is I run this code in different shop then I see the result.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Feb 28, 2013 4:59 pm
Reply with quote

Can you double-check that the actual WS-COMP3-POSITIVE is signed in the program you are running.

Can you post your compile options (value of NUMPROC, OPT, ZWB).

Does anything else at all reference WS-COMP3-POSITIVE?
Back to top
View user's profile Send private message
Harsha1525

New User


Joined: 22 Dec 2009
Posts: 24
Location: hyderabad

PostPosted: Thu Feb 28, 2013 5:54 pm
Reply with quote

Bill Woodger wrote:
Can you double-check that the actual WS-COMP3-POSITIVE is signed in the program you are running.


yes it is signed. and code i am executing i copied and pasted in my question

Quote:
Can you post your compile options (value of NUMPROC, OPT, ZWB).

I do not know meaning of below compiler options, I am going to google it but for the quick reference I am making them available to the forum
Code:

NUMPROC(NOPFD)
TRUNC(OPT)
ZWB


Quote:
Does anything else at all reference WS-COMP3-POSITIVE?

No, no other piece of code refer this one
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Feb 28, 2013 6:02 pm
Reply with quote

Harsha1525 wrote:

I do not know meaning of below compiler options, I am going to google it but for the quick reference I am making them available to the forum
Code:

NUMPROC(NOPFD)
TRUNC(OPT)
ZWB

Instead of relying on Google, you may find it preferable to bookmark the Application Development Help Center link.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Feb 28, 2013 7:02 pm
Reply with quote

Well, once I changed my mickey-mouse program to use packed-decimal, rather than just include it in the name of the field, I got the same output :-)

It must be documented, then, I thought:

Language Reference wrote:
If identifier-1 is a binary, internal decimal, or internal floating-point data item, identifier-1 is converted automatically to external format as follows:
Binary and internal decimal items are converted to zoned decimal.
Negative signed values cause a low-order sign overpunch.


Implication that positive signed values are not "overpunched". So X'01234C' gets you 1234.

I'm sure this is "new" behaviour as around about 34 years ago I took up the habit of using "numeric-edited" fields if I wanted to DISPLAY the value of a COMP-3. I can't be certain, but I do think that positives used to be "overpunched".

OK, whatever, now they're certainly not. X'01234C' gets you 1234, X'01234D' gets you 123M, in a packed-decimal.

Same numeric signed values in a USAGE DISPLAY field (ordinary PIC S9(4), for instance), gets you an "overpunch" for both positive and negative. So 123D and 123M for positive and negative respectively.

Learn something new every day. Sorry for confusing things earlier. In the end your question may have helped me more than you :-) Thanks!
Back to top
View user's profile Send private message
Harsha1525

New User


Joined: 22 Dec 2009
Posts: 24
Location: hyderabad

PostPosted: Mon Mar 04, 2013 11:53 am
Reply with quote

Thank you all.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
Search our Forums:

Back to Top