What is the difference between COMP and COMP-3?

All sort of Mainframes Interview Questions.
Post Reply
Pragya
Registered Member
Posts: 65
Joined: Wed Jun 19, 2013 9:49 am

What is the difference between COMP and COMP-3?

Post by Pragya »

Hi,

What is the difference between COMP and COMP-3? How can we display them.

My answer was one is binary and other is packed decimal. But Interviewer was not very happy.

I was not sure on how to display them, can someone please tell?
Priya
Registered Member
Posts: 50
Joined: Tue Jul 02, 2013 11:43 pm

Re: What is the difference between COMP and COMP-3?

Post by Priya »

You need to move them to edit characters to display them. COMP is of 2 bytes and COMP-3 is 8 bytes. And COMP has sign over punched at it last nibble where as for COMP-3 it will take extra half byte for sign.
User avatar
Akatsukami
Global Moderator
Global Moderator
Posts: 122
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL
Contact:

Re: What is the difference between COMP and COMP-3?

Post by Akatsukami »

COMP-3 is not eight bytes; it is ROUND((number-of-digits+1)/2) bytes.
"I come to the conclusion that, men loving according to their own will and fearing according to that of the prince, a wise prince should establish himself on that which is in his own control and not in that of others." -- Niccolò Machiavelli
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1886
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: What is the difference between COMP and COMP-3?

Post by Robert Sample »

Priya, you managed to mess up pretty much EVERYTHING you said. A COMP variable may be 2 bytes or 4 bytes or 8 bytes depending upon the PICTURE. The sign, if used (COMP variables can be unsigned), is the first bit of the value.
And COMP has sign over punched at it last nibble
No, you have described Zoned Decimal signs -- NOT COMP! And as pointed out a COMP-3 variable length depends upon the PICTURE digits.

123 as a 2-byte COMP variable will be X'007B'. 123 as PIC S9(03) COMP-3 variable will be X'123C'. 123 as a 3-byte signed zoned decimal variable will be X'F1F2C3'. All of this is CLEARLY explained in the Enterprise COBOL Language Reference manual.

Also, you can use DISPLAY -- but signed values may require interpretation since the values will be converted to zoned decimal and hence 123 would display as 12C (C3 being the EBCDIC C character). For human-readable values, move each to a numeric edited variable (such as PIC S9(03) SIGN LEADING SEPARATE or PIC +++9) and display the numeric edited variable.
Pragya
Registered Member
Posts: 65
Joined: Wed Jun 19, 2013 9:49 am

Re: What is the difference between COMP and COMP-3?

Post by Pragya »

Robert Sample wrote: Wed Nov 08, 2017 6:37 pmPriya, you managed to mess up pretty much EVERYTHING you said. A COMP variable may be 2 bytes or 4 bytes or 8 bytes depending upon the PICTURE. The sign, if used (COMP variables can be unsigned), is the first bit of the value.And COMP has sign over punched at it last nibbleNo, you have described Zoned Decimal signs -- NOT COMP! And as pointed out a COMP-3 variable length depends upon the PICTURE digits.

123 as a 2-byte COMP variable will be X'007B'. 123 as PIC S9(03) COMP-3 variable will be X'123C'. 123 as a 3-byte signed zoned decimal variable will be X'F1F2C3'. All of this is CLEARLY explained in the Enterprise COBOL Language Reference manual.

Also, you can use DISPLAY -- but signed values may require interpretation since the values will be converted to zoned decimal and hence 123 would display as 12C (C3 being the EBCDIC C character). For human-readable values, move each to a numeric edited variable (such as PIC S9(03) SIGN LEADING SEPARATE or PIC +++9) and display the numeric edited variable.
Thanks.

Can we not display them without really moving to some other type variable and still make it human readable?
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 825
Joined: Wed Sep 11, 2013 3:57 pm

Re: What is the difference between COMP and COMP-3?

Post by enrico-sorichetti »

Can we not display them without really moving to some other type variable and still make it human readable?
did You care to try to understand the answer You were given ?
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 8-)
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1886
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: What is the difference between COMP and COMP-3?

Post by Robert Sample »

Can we not display them without really moving to some other type variable and still make it human readable?
Yes -- as long as the human understands 12C is a +123 and 12L is -123 on the DISPLAY. If this is not acceptable, you MUST move the data to a different variable to DISPLAY it.
Pragya
Registered Member
Posts: 65
Joined: Wed Jun 19, 2013 9:49 am

Re: What is the difference between COMP and COMP-3?

Post by Pragya »

Thanks Robert.
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 “Interview Questions.”