Page 1 of 1

Representation of COMP,COMP-1 and COMP-2 in sequential file

PostPosted: Thu May 03, 2012 4:03 pm
by fornanthakumar
Hi,

How will you represent a COMP(Half-word binary representation, full word binary ) ,COMP-1 and COMP-2 in a sequential file ?

I tried to get SMALLINT data from DB2 but i could not get the access as i am new to the team.

Please assist.

Note : For hexadecimal , each digit will share a half-byte and i know the representation as well.

Re: Representation of COMP,COMP-1 and COMP-2 in sequential f

PostPosted: Thu May 03, 2012 4:30 pm
by Akatsukami
A COBOL COMP value is binary -- or hexadecimal, if you will. As you say that you know the representation, no explication on my part is required.

COMP-1 and COMP-2 are single-precision (word, 4 byte) and double-precision (doubleword,8 byte) floating point, respectively. A very comprehensible explanation is here.

Re: Representation of COMP,COMP-1 and COMP-2 in sequential f

PostPosted: Thu May 03, 2012 5:04 pm
by Robert Sample
Note : For hexadecimal , each digit will share a half-byte and i know the representation as well.
Actually, this is packed decimal (COBOL COMP-3) and totally different than "hexadecimal" (COMP) data. Saying data is "hexadecimal" is a VERY poor choice of terms -- since, technically, every data field is in hexadecimal. Terminology is critical in IT, where similar terms may mean very different things. You should use the appropriate terms (zoned decimal for COBOL USAGE DISPLAY, binary for COBOL USAGE COMP, packed decimal for COBOL USAGE COMP-3, floating point for COBOL USAGE COMP-1 or COMP-2).

Re: Representation of COMP,COMP-1 and COMP-2 in sequential f

PostPosted: Thu May 03, 2012 6:27 pm
by fornanthakumar
Hi,

In DB2, SMALLINT can have range between -32768 to +32767, the equailent HOST Variable in COBOL is S9(4) comp as SMALLINT is half word.

S9(4) can be represent in sequential file, if the value is +1230

13
2}

But how do we represent 32700 in sequential file for a S9(4) comp variable.

Please advise if i am wrong on my statement.

Re: Representation of COMP,COMP-1 and COMP-2 in sequential f

PostPosted: Thu May 03, 2012 6:36 pm
by Robert Sample
Please advise if i am wrong on my statement.
You are wrong -- please understand this!

1230 in a PIC S9(04) COMP COBOL variable would be X'04CE'. Expressed vertically, the value would be
1230 in a PIC S9(04) COMP-3 COBOL variable would be X'01230C'. Expressed vertically, the value would be
32700 in a PIC S9(04) COMP COBOL variable would be X'7FBC'. Expressed vertically, the value would be

Note that the COMP-3 value uses 3 bytes; z/OS only deals with whole bytes so PIC S9(04) COMP-3 and PIC S9(05) COMP-3 are BOTH stored in a 3-byte field.

Re: Representation of COMP,COMP-1 and COMP-2 in sequential f

PostPosted: Thu May 03, 2012 6:46 pm
by fornanthakumar
Thank you very much robert..

Re: Representation of COMP,COMP-1 and COMP-2 in sequential f

PostPosted: Thu May 03, 2012 6:50 pm
by Akatsukami
As Mr. Sample indicates, Nanthu, you are confusing packed-decimal (COBOL COMP-3, DB2 DECIMAL) with straight binary (COBOL COMP/COMP-4/COMP-5, DB2 SMALLINT/INTEGER/BIGINT). Moreover, unless you compile with TRUNC(BIN), a COBOL COMP/COMP-4 is limited to the decimal equivalent defined by the picture; thus, although FOO PIC 999 COMP occupies two bytes, with a theoretical range of -32,768 to 32,767, you can actually only store 0 to 999 in it. Give your host variable USAGE of COMP-5 to be allowed the full range.

Re: Representation of COMP,COMP-1 and COMP-2 in sequential f

PostPosted: Sat Nov 01, 2014 3:59 pm
by gouravar
Robert Sample wrote:
Please advise if i am wrong on my statement.
You are wrong -- please understand this!

1230 in a PIC S9(04) COMP COBOL variable would be X'04CE'. Expressed vertically, the value would be
1230 in a PIC S9(04) COMP-3 COBOL variable would be X'01230C'. Expressed vertically, the value would be
32700 in a PIC S9(04) COMP COBOL variable would be X'7FBC'. Expressed vertically, the value would be

Note that the COMP-3 value uses 3 bytes; z/OS only deals with whole bytes so PIC S9(04) COMP-3 and PIC S9(05) COMP-3 are BOTH stored in a 3-byte field.


Can anyone please tell me how much bytes 32700 would take if we are storing it as Comp variable. as explained here it would require 2 bytes, but every where I have seen comp variable with 9(5) to 9(9) require 4 bytes..

Re: Representation of COMP,COMP-1 and COMP-2 in sequential f

PostPosted: Sat Nov 01, 2014 4:38 pm
by BillyBoyo
There are two types of binary available in Enterprise COBOL. One is the standard binary which does base-10 truncation to the PICture definition. These have a USAGE of COMP, COMP-4 or BINARY.

PIC 9 COMP, maximum value 9.
PIC 99 COMP-4, maximum value 99.
PIC 9(4) BINARY, maximum value 999.

The other type is "native binary" whose value is only limited to field-size and which truncates to field-size. This has USAGE of COMP-5.

PIC 9 COMP-5, maxumum value ((2^16)-1) = 32767
PIC 99 COMP-5, maxumum value ((2^16)-1) = 32767
PIC 9(4) COMP-5, maxumum value ((2^16)-1) = 32767

With COMP-5 the PICture just defines the field-size. 1-4 is two bytes, 5-9 is four bytes, 10+ is eight bytes.

To hold your value with COMP, COMP-4 or BINARY, you'd need PIC 9(5) at least, which would be four bytes of storage.

To hold your value with COMP-5, you'd need PIC 9 -9(4) at least, which would be two bytes of storage.

Compiler option TRUNC can also be involved. TRUNC(BIN) will treat all binary definitions (COMP, COMP-4 and BINARY) the same as it treats COMP-5. COMP-5 typically causes the compiler to generate more instructions, so is "slower". Some sites have TRUNC(BIN) as their compiler setting. If so, you're stuck with that.