What is the difference between COMP and COMP-3?

All sort of Mainframes Interview Questions.
Previous topicNext topic

Topic Author
Pragya
Registered Member
Posts: 30
Joined: Wed Jun 19, 2013 9:49 am
Zodiac: Sagittarius

What is the difference between COMP and COMP-3?

Post by Pragya » Wed Nov 08, 2017 10:40 am

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: 26
Joined: Tue Jul 02, 2013 11:43 pm
Zodiac: Scorpio

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

Post by Priya » Wed Nov 08, 2017 11:03 am

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: 119
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL

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

Post by Akatsukami » Wed Nov 08, 2017 5:33 pm

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: 1379
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

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

Post by Robert Sample » Wed Nov 08, 2017 6:37 pm

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.




Topic Author
Pragya
Registered Member
Posts: 30
Joined: Wed Jun 19, 2013 9:49 am
Zodiac: Sagittarius

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

Post by Pragya » Thu Feb 15, 2018 12:02 pm

Robert Sample wrote:
Wed Nov 08, 2017 6:37 pm
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 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: 892
Joined: Wed Sep 11, 2013 3:57 pm

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

Post by enrico-sorichetti » Thu Feb 15, 2018 2:46 pm

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: 1379
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

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

Post by Robert Sample » Thu Feb 15, 2018 6:04 pm

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.



Previous topicNext topic

Return to “Interview Questions.”