Page 1 of 1

How 1234 will be in COMP, COMP-1, COMP-2, COMP-3?

Posted: Mon Apr 07, 2014 2:28 pm
by utkarsh
Hi,

I've been asked this in an interview - explain the internal format of 1234 in COMP, COMP-1, COMP-2, COMP-3? I'm not sure how to answer that. Can someone please explain and help.

And what will be the size of 1234 in all computational definitions?

Re: How 1234 will be in COMP, COMP-1, COMP-2, COMP-3?

Posted: Mon Apr 07, 2014 2:50 pm
by William Collins
Size for USAGE COMP depends on your PICture. If you have PIC 9(4) then it is two bytes, a half-word. What you would see, is the binary value which gives 1234, preceded by zeros if necessary. COMP-1/COMP-2 are floating-point. They are fixed size and cannot have a PICture. COMP-3 size again depends on the PICture. For PIC 9(4) it would be X'01234F'.

Easiest thing for you to do, is have a little program, define and REDEFINES (as PIC X(n)) each field that you want and then DISPLAY the REDEFINES field, look at the output in HEX. Otherwise refer to the manual, understand, memorize and probably never need to know for COMP-1 and COMP-2

Re: How 1234 will be in COMP, COMP-1, COMP-2, COMP-3?

Posted: Mon Apr 07, 2014 5:51 pm
by Robert Sample
COMP variables are 2, 4, or 8 bytes long depending upon the PICTURE clause. COMP-1 variables are 4 bytes long. COMP-2 variables are 8 bytes long. COMP-3 variable length depends upon the specific PICTURE clause used but will generally be 1/2 the number of digits in the PICTURE clause (plus 1 if the number of digits is even).