Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to calculate the space used by COMP variables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to calculate the space used by COMP variables
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: 3158
Location: Tucson AZ

PostPosted: Sat Dec 23, 2006 9:19 pm    Post subject: Re: Usage COMP in COBOL variables
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Sat Dec 23, 2006 9:44 pm    Post subject:
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Sat Dec 23, 2006 11:03 pm    Post subject:
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Sat Dec 23, 2006 11:27 pm    Post subject:
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: 61
Location: pune

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

PostPosted: Wed Dec 27, 2006 4:31 am    Post subject: Re: How to calculate the space used by COMP variables
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

Site Director


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

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

PostPosted: Wed Dec 27, 2006 3:20 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts How to calculate an specific transact... lind sh CICS 2 Tue Sep 13, 2016 9:20 pm
No new posts Need help to populate date in COMP-3 ... chetanambi DFSORT/ICETOOL 3 Tue Jun 21, 2016 12:25 pm
No new posts Is it possible to pass variables of s... Csongor CLIST & REXX 2 Fri Jun 10, 2016 7:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us