Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
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.
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:
X?00000154216C? where the ?C? is held as the sign. ?C? = Positive, ?D? = negative, and ?F? = unsigned.
X?F0F0F0F0F0F1F5F4F2F1C6? Where the ?F? is the ZONE, and has no real impact on the number, ?C? is held as the sign, as above.
X?F0F06BF0F0F16BH5H4H24BF1F6? This is a Display format, the X?6B? = ?,? AND X?4B? = ?.?. This would display, or print as ?00,001,542.16?.
X?0000000000025A68?. The sign is the high order Bite 0 = pos 1 = neg. Below are the Binary values for +1542.16 and -1542.16
To convert from the Zoned-Decimal format to the others is pretty straight forward.
MOVE WS-PACKED-DECIMAL TO WS-ZONED-DECIMAL.
MOVE WS-PACKED-DECIMAL TO WS-BINARY.
MOVE WS-PACKED-DECIMAP TO WS-NUMERIC-EDITED.