PACK source TO destination.
This statement, which is forbidden in classes, converts the content of the data object
source to the data type
p of length 16 without
decimal places. In contradiction to the
conversion rules for elementary data types,
any decimal separators in
source are ignored. This assigns the converted content to the data object
The data type of
source must be character-like,
flat, and its content must be
interpretable as a numeric value. The data type of
destination must be flat.
destination has the data type
p, the intermediate
result is assigned to it from left to right. Surplus places are cut off on the left, and the decimal
places are determined by the data type of
does not have the data type
p, the intermediate result is converted to the
data type of
destination in accordance with the rules in the conversion table for source field type
The function of the statement
PACKis based on the fact that the second half-byte of the code of a digit in most character representations matches the BCD representation of the associated number value. This conversion is generally known as "packing".
If the source field contains a number without a decimal separator, and the target field has
dobj2of data type
pwith sufficient length and without decimal places, the result of the
PACKstatement matches the result of a regular statement.
UNPACKdoes not demonstrate the same behavior as a regular assignment and is therefore not yet obsolete.
DATA: txt TYPE c LENGTH 30, num TYPE p. PACK txt TO num.
DATA: txt TYPE c LENGTH 30, num TYPE p. num = txt.
Cause: Source field cannot be interpreted as a number
Cause: Overflow during conversion (type
Cause: Source field (type
p) contains an incorrect BCD format