Wednesday 19 August 2015

Understanding COMP COMP-1 COMP-2 COMP-3

COMP
Data is stored as pure binary format.
The PIC clause of COMP data item should not contain other than 9 or S.
Depending on the size of data item, data is stored either in Half-word (2 bytes) or full-word (4 bytes).
9(1) – 9(4) occupies 2 bytes
9(5) – 9(9) occupies 4 bytes
S9(10) – S9(18) occupies 8 bytes
Example:
01 WS-VAR                    S9(2) COMP.
Occupies 2 bytes and data is stored in pure binary format internally.
COMP-1
This is used for single precision floating point items.
The data is represented in one word in floating point form.
It doesn’t have PIC clause and occupies 4 bytes.
Sign is present in the first bit of leftmost byte and the remaining 7 bits contain exponent. The last 3 bytes contain mantissa
Example: 
01 WS-VAR        USAGE IS COMP-1.
COMP-2
This is used for Double precision floating point items.
The data item is represented in two words in floating point form.
It doesn’t not have PIC clause and occupies 8 bytes.
Sign is present in the first bit in the left most byte and the remaining 7 bits contain exponent. The last 7 bytes contains mantissa.
Example: 

01 WS-VAR        USAGE IS COMP-2.
COMP-3
The data item is represented in Packed Decimal format
One digit takes half a byte.
The total length of the data item is
((n/2)+1), if n is EVEN
((n+1)/2), if n is ODD
The PIC clause allows S,9 and V.
We cannot move LOW-VALUES to these data items which results in Compilation error
COMP-3 values can be seen in PS by using HEX ON
Example: 
01 WS-VAR               PIC S9(05) COMP-3 VALUE +52636
WS-VAR will be displayed as
comp3
Total number of bytes consumed by WS-VAR is (5+1)/2 = 3 bytes

No comments:

Post a Comment