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

How COMP and COMP-3 values are stored


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Shobana Bhaskar

New User


Joined: 02 Mar 2007
Posts: 35
Location: Pennsylvania, US

PostPosted: Thu Mar 15, 2007 2:46 pm
Reply with quote

Hi,

Can anyone tell me how COMP and COMP-3 values are stored? How storage bytes are calculated?
Back to top
View user's profile Send private message
rammraju

New User


Joined: 05 Mar 2005
Posts: 65
Location: Hyderabad

PostPosted: Thu Mar 15, 2007 3:12 pm
Reply with quote

Comp stores data in binary format.
They occupy 2, 4, or 8 bytes of storage. If the PICTURE clause is signed, the leftmost bit is used as the sign. EX: A binary number with a PICTURE <=4 decimal digits occupies 2 bytes; 5 to 9 decimal digits occupies 4 bytes, 10 to 18 decimal digits occupies 8 bytes.

Comp-3 stores data in Packed decimal format
Packed-decimal items occupy 1 byte of storage for every 2 decimal digits you code in the PICTURE clause, except that the rightmost byte contains only one digit and the sign.

Hope this is clear
Back to top
View user's profile Send private message
naveen_amudalapelly
Warnings : 1

New User


Joined: 15 Oct 2004
Posts: 16

PostPosted: Thu Mar 15, 2007 3:14 pm
Reply with quote

comp is a binary usage and while comp-3 is packed decimal.
comp value stroes as binary and comp-3 store as hexa decimal format
For example if your number is +100, it stores hex 0C in the
last byte, hex 1C if your number is 101, hex 1D if the number is -101, hex 2D if the number is -102 etc
Back to top
View user's profile Send private message
cooldebi

New User


Joined: 19 Apr 2006
Posts: 18
Location: mumbai

PostPosted: Thu Mar 15, 2007 4:47 pm
Reply with quote

Storage is calculated as:
let 01 WS-x PIC S9(x) usage is comp.
let 01 WS-x PIC S9(x) usage is comp-3
for COMP --> no of bytes = x/2 (usually x is 2,4,8,16)
for COMP-3 --> no of bytes = |(x/2+1/2)| as 1/2 is required for storing sign

suppose u want to store 12 --> in a variable PIC 9(2) usage is comp.

Internally it will be stored as 00001100 in 1 byte (binary representation).

suppose u want to store 12 --> in a variable PIC 9(2) usage is comp-3.

Internally it will be stored as 0001 0010 [quote]1111 0000 (Hexadecimal representation)in 2 bytes.

underlined characters represents the sign nibble for comp-3.. 1111

cheers
Back to top
View user's profile Send private message
Shobana Bhaskar

New User


Joined: 02 Mar 2007
Posts: 35
Location: Pennsylvania, US

PostPosted: Fri Mar 16, 2007 1:13 pm
Reply with quote

Thanks a lot friends... icon_smile.gif
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 INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
Search our Forums:

Back to Top