Page 1 of 1

What is the difference between COMP and COMP-3?

Posted: Wed Nov 08, 2017 10:40 am
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?

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

Posted: Wed Nov 08, 2017 11:03 am
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.

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

Posted: Wed Nov 08, 2017 5:33 pm
by Akatsukami
COMP-3 is not eight bytes; it is ROUND((number-of-digits+1)/2) bytes.

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

Posted: Wed Nov 08, 2017 6:37 pm
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.

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

Posted: Thu Feb 15, 2018 12:02 pm
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?

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

Posted: Thu Feb 15, 2018 2:46 pm
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 ?

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

Posted: Thu Feb 15, 2018 6:04 pm
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.

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

Posted: Mon May 28, 2018 3:03 pm
by Pragya
Thanks Robert.