UNPACK source TO destination.
This statement converts the content of the data object
source in accordance
with special rules and assigns the converted content to the data object
source expects the data type
p of length 16 without
Operands of data type
decfloat34 cannot be used. The data type of
destination must be character-like and
The conversion is performed according to the following rules:
If the data type of
sourceis not of type
pwith length 16 and without decimal places, the content of
sourceis converted to this data type. Contrary to the rules described in Conversion Rules for Elementary Data Types, any decimal separator in
sourceis completely ignored.
The digits of the intermediate result are assigned right-justified to the data object
destinationand without a sign. Any surplus places in
destinationare padded with zeroes on the left. If the length of
destinationis not sufficient, the assigned value is truncated on the left.
The function of the statement
UNPACKis based on the fact that the BCD representation of a place corresponds to the second half byte of code of a digit in most character representations. This transformation is generally known as "Unpacking".
PACKused for packing is obsolete and can be replaced by a regular assignment.
After the assignments are made,
char2 contain the values "123,456" and "0000123456".
DATA: pack TYPE p LENGTH 8 DECIMALS 3 VALUE '123.456', char1 TYPE c LENGTH 10, char2 TYPE c LENGTH 10. char1 = pack. UNPACK pack TO char2.
Cause: Source field cannot be interpreted as a number
Cause: Overflow during conversion (type
Cause: Source field (type
p) contains an incorrect BCD format