Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

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    Post subject: How to calculate the space used by COMP variables 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: 3158
Location: Tucson AZ

Posted: Sat Dec 23, 2006 9:19 pm    Post subject: Re: Usage COMP in COBOL variables

 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    Post subject: 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: 3158
Location: Tucson AZ

Posted: Sat Dec 23, 2006 9:44 pm    Post subject:

 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    Post subject: 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: 3158
Location: Tucson AZ

Posted: Sat Dec 23, 2006 11:03 pm    Post subject:

 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    Post subject: 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: 3158
Location: Tucson AZ

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

New User

Joined: 20 Sep 2006
Posts: 61
Location: pune

 Posted: Tue Dec 26, 2006 11:51 am    Post subject: Re: How to calculate the space used by COMP variables 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    Post subject: Re: How to calculate the space used by COMP variables 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: 3158
Location: Tucson AZ

Posted: Wed Dec 27, 2006 4:31 am    Post subject: Re: How to calculate the space used by COMP variables

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

Site Director

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

 Posted: Wed Dec 27, 2006 4:31 am    Post subject: 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: 757
Location: Germany

 Posted: Wed Dec 27, 2006 3:20 pm    Post subject: 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
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics SAS Work space - B37 abend santuece1 JCL & VSAM 11 Tue Jun 19, 2018 1:03 am JCL to set Return code when Time Out ... vinu78 JCL & VSAM 6 Wed May 30, 2018 11:27 am VSAM File free space sancraig16 JCL & VSAM 14 Fri Mar 30, 2018 1:02 am VSAM BUFFER SPACE? John Poulakos CICS 17 Thu Mar 22, 2018 2:54 am *MASTER* address space abending at IPL Alan Playford All Other Mainframe Topics 2 Mon Mar 12, 2018 8:02 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us