DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Hi Sandesh,
There is no format in COBOL that is discussed as ?Unpacked Decimal?. What you meant, I?m sure, is ?Zoned Decimal? OR ?NUMERIC-EDITED? . There is also Binary, and Floating Point, but I don?t think this is what you meant.
I?ll briefly discuss Packed-Decimal, Zoned-Decimal, Numeric-Edited, and Binary. The Floating-Point format should wait until another time after you well understand these four.
Code: |
01 WS-PACKED-DECIMAL PIC S9(11)V99 COMP-3 VALUE 1542.16.
01 WS-ZONED-DECIMAL PIC S9(11)V99.
01 WS-BINARY PIC S9(11)V99 COMP.
01 WS-NUMERIC-EDIT PIC 99,999,999.99.
|
In a Packed-decimal, Zoned-decimal, Binary, the ?Decimal Point? is assumed, and is not held in the stored value. Numeric-Edited, on the other hand contains all of the editing characters in the stored value.
The hex value stored in each of these formats, assuming the 1542.16 value is:
Packed-Decimal:
X?00000154216C? where the ?C? is held as the sign. ?C? = Positive, ?D? = negative, and ?F? = unsigned.
Zoned_Decimal:
X?F0F0F0F0F0F1F5F4F2F1C6? Where the ?F? is the ZONE, and has no real impact on the number, ?C? is held as the sign, as above.
Numeric_Edited:
X?F0F06BF0F0F16BH5H4H24BF1F6? This is a Display format, the X?6B? = ?,? AND X?4B? = ?.?. This would display, or print as ?00,001,542.16?.
Binary:
X?0000000000025A68?. The sign is the high order Bite 0 = pos 1 = neg. Below are the Binary values for +1542.16 and -1542.16
B?0000000000000000000000000000000000000000000000100101101001101000?
B?1111111111111111111111111111111111111111111111011010010110011000?
To convert from the Zoned-Decimal format to the others is pretty straight forward.
Code: |
MOVE WS-PACKED-DECIMAL TO WS-ZONED-DECIMAL.
MOVE WS-PACKED-DECIMAL TO WS-BINARY.
MOVE WS-PACKED-DECIMAP TO WS-NUMERIC-EDITED.
|
If there is confusion, please come back.
Dave |
|