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, then 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 interim result are assigned to data object
destinationright-aligned and without a sign. Any surplus positions in
destinationare padded with zeros 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 decimal place corresponds to the second half byte of code of a digit in most character representations. This transformation is generally known as "Unpacking".
PACKpacking is obsolete and can be replaced by
destinationis specified as an untyped field symbol or an untyped formal parameter and is not flat and character-like when the statement is executed, this results in an exception (that cannot be handled) in Unicode programs. In non-Unicode programs, an exception only occurs if deep types are used, while flat types are handled like character-like types.
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.
MOVE pack TO char1.
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