IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to calculate the space used by COMP variables


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Amit Manas Dubey
Currently Banned

New User


Joined: 15 Dec 2006
Posts: 22
Location: Mumbai

PostPosted: Sat Dec 23, 2006 9:06 pm
Reply with quote

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
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Sat Dec 23, 2006 9:19 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Amit Manas Dubey
Currently Banned

New User


Joined: 15 Dec 2006
Posts: 22
Location: Mumbai

PostPosted: Sat Dec 23, 2006 9:34 pm
Reply with quote

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 ?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Sat Dec 23, 2006 9:44 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Amit Manas Dubey
Currently Banned

New User


Joined: 15 Dec 2006
Posts: 22
Location: Mumbai

PostPosted: Sat Dec 23, 2006 10:27 pm
Reply with quote

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 !!
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Sat Dec 23, 2006 11:03 pm
Reply with quote

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:
???????
Back to top
View user's profile Send private message
Amit Manas Dubey
Currently Banned

New User


Joined: 15 Dec 2006
Posts: 22
Location: Mumbai

PostPosted: Sat Dec 23, 2006 11:25 pm
Reply with quote

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 !! icon_biggrin.gif
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Sat Dec 23, 2006 11:27 pm
Reply with quote

I'm not quite that fast.... icon_lol.gif
Back to top
View user's profile Send private message
sandip_mainframe
Warnings : 2

New User


Joined: 20 Sep 2006
Posts: 63
Location: pune

PostPosted: Tue Dec 26, 2006 11:51 am
Reply with quote

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.
Back to top
View user's profile Send private message
Selvamani

New User


Joined: 19 Dec 2006
Posts: 21
Location: California

PostPosted: Wed Dec 27, 2006 4:21 am
Reply with quote

Sandeep,

I remember that 1 byte = 4 bits. If this is correct, Then your calculation needs to be relooked.

Am I correct?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Wed Dec 27, 2006 4:31 am
Reply with quote

Selvamani wrote:
I remember that 1 byte = 4 bits.
No, one byte is 8 bits
Quote:
Am I correct?
no icon_smile.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Dec 27, 2006 4:31 am
Reply with quote

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).
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Wed Dec 27, 2006 3:20 pm
Reply with quote

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
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Repeat n times by substuting SEQNUM i... DFSORT/ICETOOL 2
No new posts Preserve changes to ISPF Panel Variables TSO/ISPF 5
No new posts Get RECORD LENGTH, allocated space of... CLIST & REXX 7
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top