What is the difference between COMP and COMP-3?
What is the difference between COMP and COMP-3?
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?
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?
Re: What is the difference between COMP and COMP-3?
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.
- Akatsukami
- 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?
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
- Robert Sample
- Global Moderator
- Posts: 1903
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: What is the difference between COMP and COMP-3?
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.
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.
No, you have described Zoned Decimal signs -- NOT COMP! And as pointed out a COMP-3 variable length depends upon the PICTURE digits.And COMP has sign over punched at it last nibble
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.
Re: What is the difference between COMP and COMP-3?
Thanks.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.
Can we not display them without really moving to some other type variable and still make it human readable?
- enrico-sorichetti
- Global Moderator
- Posts: 843
- Joined: Wed Sep 11, 2013 3:57 pm
Re: What is the difference between COMP and COMP-3?
did You care to try to understand the answer You were given ?Can we not display them without really moving to some other type variable and still make it human readable?
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
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

- Robert Sample
- Global Moderator
- Posts: 1903
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: What is the difference between COMP and COMP-3?
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.Can we not display them without really moving to some other type variable and still make it human readable?
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