View previous topic :: View next topic
|
Author |
Message |
Shobana Bhaskar
New User
Joined: 02 Mar 2007 Posts: 35 Location: Pennsylvania, US
|
|
|
|
Hi,
Can anyone tell me how COMP and COMP-3 values are stored? How storage bytes are calculated? |
|
Back to top |
|
|
rammraju
New User
Joined: 05 Mar 2005 Posts: 65 Location: Hyderabad
|
|
|
|
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 |
|
|
naveen_amudalapelly Warnings : 1 New User
Joined: 15 Oct 2004 Posts: 16
|
|
|
|
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 |
|
|
cooldebi
New User
Joined: 19 Apr 2006 Posts: 18 Location: mumbai
|
|
|
|
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 |
|
|
Shobana Bhaskar
New User
Joined: 02 Mar 2007 Posts: 35 Location: Pennsylvania, US
|
|
|
|
Thanks a lot friends... |
|
Back to top |
|
|
|