Get Example source ABAP code based on a different SAP table
ID PACK • PACK ABAP Statement • TO PACK (obsolete)
PACK> Short Reference >
ABAP_SYNTAX_OBS PACK source TO destination.>
What does it do? 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 contrast to the conversion rules for elementary data types>, any decimal separators in source> are ignored. This assigns the converted content to the data object destination>. 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. If destination> has the data type p>, the intermediate result is assigned to it from right to left. Surplus places are cut off on the left, and the decimal places are determined by the data type of destination>. If destination> 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 p >>.
Latest notes:
The function of the statement PACK> is 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 numeric value. This conversion is generally known as packing>.
If the source field contains a number without a decimal separator, and the target field has dobj2> of data type p> with sufficient length and without decimal places, the result of the PACK> statement matches the result of a regular statement>.
The statement UNPACK>> does not demonstrate the same behavior as a regular assignment> and is therefore not yet obsolete. ABAP_HINT_END
ABAP_EXAMPLE_BAD ABEXA 00484 ABAP_EXAMPLE_END
ABAP_EXAMPLE_GOOD ABEXA 00485 ABAP_EXAMPLE_END
Runtime Exceptions
Catchable Exceptions CX_SY_CONVERSION_NO_NUMBER>>
Reason for error:
Source field cannot be interpreted as a number
Runtime error:
CONVT_NO_NUMBER> CX_SY_CONVERSION_OVERFLOW>>
Reason for error:
Overflow during conversion (type p>)
Runtime error:
BCD_OVERFLOW>
Non-catchable Exceptions
Reason for error:
Source field (type p>) contains an incorrect BCD format