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



TSO Programming, ISPF, SDF, SDSF and PDF, FTP, TCP/IP Concepts, SNA & SNA/IP etc...

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

Postby fornanthakumar » Thu May 03, 2012 4:03 pm

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.
Regards,
Nanthu.Y.
fornanthakumar
 
Posts: 70
Joined: Fri Oct 22, 2010 1:58 pm
Has thanked: 0 time
Been thanked: 0 time

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

 

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

Postby Akatsukami » Thu May 03, 2012 4:30 pm

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.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

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

Postby Robert Sample » Thu May 03, 2012 5:04 pm

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).
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

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

Postby fornanthakumar » Thu May 03, 2012 6:27 pm

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.
Regards,
Nanthu.Y.
fornanthakumar
 
Posts: 70
Joined: Fri Oct 22, 2010 1:58 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby Robert Sample » Thu May 03, 2012 6:36 pm

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.

These users thanked the author Robert Sample for the post:
gouravar (Sat Nov 01, 2014 3:38 pm)
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

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

Postby fornanthakumar » Thu May 03, 2012 6:46 pm

Thank you very much robert..
Regards,
Nanthu.Y.
fornanthakumar
 
Posts: 70
Joined: Fri Oct 22, 2010 1:58 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby Akatsukami » Thu May 03, 2012 6:50 pm

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.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

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

Postby gouravar » Sat Nov 01, 2014 3:59 pm

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..
gouravar
 
Posts: 7
Joined: Tue Jun 12, 2012 10:36 pm
Has thanked: 3 times
Been thanked: 0 time

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

Postby BillyBoyo » Sat Nov 01, 2014 4:38 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times


Return to TSO & ISPF

 


  • Related topics
    Replies
    Views
    Last post