# How to calculate the space used by COMP variables

Author Message
Amit Manas Dubey
Currently Banned

New User

Joined: 15 Dec 2006
Posts: 22
Location: Mumbai

 Posted: Sat Dec 23, 2006 9:06 pm Hi Can somebody tell me how can we calculate the space utilized by COMP variables in COBOL ? For example S9(8) COMP - Takes 4 bytes ...Is there a way this can be calculated ?? Also, is there a diff in the no of bytes used by signed and unsigned numeric variables. Thanks Amit
William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

Posted: Sat Dec 23, 2006 9:19 pm

 Amit Manas Dubey wrote: Can somebody tell me how can we calculate the space utilized by COMP variables in COBOL ? For example S9(8) COMP - Takes 4 bytes ...Is there a way this can be calculated ??

Comp is binary and the assembler opcode that does binary arithmetic are register instructions. Register instructions either deal with full words or half words. The registers themselves are full words. Full words are 4 bytes long.
 Quote: Also, is there a diff in the no of bytes used by signed and unsigned numeric variables.

In binary (comp) fields, only the one high bit signifies the sign, no extra length needed.
In packed (comp3) fields the last half byte signifies the sign, always there and no extra length needed.
Amit Manas Dubey
Currently Banned

New User

Joined: 15 Dec 2006
Posts: 22
Location: Mumbai

 Posted: Sat Dec 23, 2006 9:34 pm I saw the manuals....As I understand say S9(4) COMP - can have 9999 as Max value - this when converted to Binary is 10011100001111 + 1 bit for sign = 15 bits .....This will take 2 bytes = 16 bits........ Is my understanding correct ?
William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

Posted: Sat Dec 23, 2006 9:44 pm

 Amit Manas Dubey wrote: I saw the manuals....As I understand say S9(4) COMP - can have 9999 as Max value - this when converted to Binary is 10011100001111 + 1 bit for sign = 15 bits .....This will take 2 bytes = 16 bits........ Is my understanding correct ?
Kinda.....Some compiler (or LE) thingy will force the max number to be no greater than the number of digits specified - S9(4) means 9999 is max. But without that setting, 32767 (7FFF) is possible.
Amit Manas Dubey
Currently Banned

New User

Joined: 15 Dec 2006
Posts: 22
Location: Mumbai

 Posted: Sat Dec 23, 2006 10:27 pm Pls explain a little more...You mean to say that the storage can be coded in Hexadecimal as well...Okies....why not FFFF ?? is it because of signed stuff - 32767 - 0 - + 32767 ? Pls elaborate !!
William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

Posted: Sat Dec 23, 2006 11:03 pm

 Amit Manas Dubey wrote: Pls explain a little more...You mean to say that the storage can be coded in Hexadecimal as well...Okies....why not FFFF ?? is it because of signed stuff - 32767 - 0 - + 32767 ? Pls elaborate !!
Actually it is -32768 (FFFF) +32767 (7FFF) - remember the high bit is the sign.
comp-val pic s9(4) comp.
hex-val redefines comp-val pic x(4).
move x'1000' to hex-val.
display comp-val.
 Code: ???????
Amit Manas Dubey
Currently Banned

New User

Joined: 15 Dec 2006
Posts: 22
Location: Mumbai

 Posted: Sat Dec 23, 2006 11:25 pm Thanks a lot Tom... I am clear on this now...Just curious to know - how do you revert so fast on these posts ? unless u are addicted to this now !!
William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

 Posted: Sat Dec 23, 2006 11:27 pm I'm not quite that fast....
sandip_mainframe
Warnings : 2

New User

Joined: 20 Sep 2006
Posts: 63
Location: pune

 Posted: Tue Dec 26, 2006 11:51 am hi, usage comp it is used for numeric value stored in pure binary form. PIC S9(1) TO PIC S9(4) IT TAKES 2 BYTES = HALF WORD = 16 BITS PIC S(5) TO PIC S9(9) IT TAKES 4 BYTES = FULL WORD = 32 BITS PIC S9(10) TO PIC S9(19) IT TAKES 8 BYTES =DOUBLE WORD = 64 BITS. SANDIP WALSINGE.
Selvamani

New User

Joined: 19 Dec 2006
Posts: 21
Location: California

 Posted: Wed Dec 27, 2006 4:21 am Sandeep, I remember that 1 byte = 4 bits. If this is correct, Then your calculation needs to be relooked. Am I correct?
William Thompson

Global Moderator

Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

Posted: Wed Dec 27, 2006 4:31 am

 Selvamani wrote: I remember that 1 byte = 4 bits.
No, one byte is 8 bits
 Quote: Am I correct?
no
dick scherrer

Moderator Emeritus

Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

 Posted: Wed Dec 27, 2006 4:31 am Hello, 1 byte = 8 bits. . . For example the letter A is made up of these bits 1100 0001 which is read as C1. The numeral 9 is 1111 0101 (F9).
UmeySan

Active Member

Joined: 22 Aug 2006
Posts: 771
Location: Germany

 Posted: Wed Dec 27, 2006 3:20 pm Hi ! Coming back to main question. As Sandip wrote it's like: PIC 9 to 9(4) -> 2 Bytes PIC 9(5) to 9(9) -> 4 Bytes PIC 9(10) to 9(18) -> 8 Bytes With binary, you only have halfbyte, fullbyte and douplebyte. @Sandip: S9(19) ??? Are you really shure ??? Just a little tip. Code alle your desired field in al little programm. Like PIC 9(01) comp / PIC 9(02) comp / and so on. Compile your programm. Then have a look at the listing. PIC S9(9) COMP. BLW=00000+F45,0000035 4C So here you could see, that S9(9) resides in a four byte field. Just 4C. Regards, Umeysan
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics how to calculate SUM value for VB fil... DFSORT/ICETOOL 1 how to calculate SUM for VB file usin... JCL & VSAM 1 COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5 Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2 Merge 2 lines based on Space from a S... DFSORT/ICETOOL 5
Search our Forums:

 IBMMainframes.com is not an official and/or affiliated with IBM® in anyway Board Rules | FAQ | Downloads | Wiki | SiteMap | Contact Us