Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Obsolete Language Elements →  Obsolete Assignments 

PACK

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Obsolete Syntax

PACK source TO destination.

Effect

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 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 interim result is assigned to it from left to right. Surplus characters 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 interim result is converted to the data type of destination in accordance with the rules in the conversion table for source field type p.


Notes

  • The function of the statement PACK is based on the fact that the second half-byte of a digit's code in most characters represented in BCD represented matches the corresponding 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 dobj2 of data type p with sufficient length and without decimal places, the result of the PACK statement matches the result of the statement MOVE.
  • The statement UNPACK does not demonstrate the same behavior as MOVE and is therefore not yet obsolete.

Bad example

DATA: txt TYPE c LENGTH 30, 
      num TYPE p. 

PACK txt TO num.

Good example

DATA: txt TYPE c LENGTH 30, 
      num TYPE p. 

MOVE txt TO num.

Exceptions


Catchable Exceptions

  • Cause: Source field cannot be interpreted as a number
    Runtime Error: CONVT_NO_NUMBER

CX_SY_CONVERSION_OVERFLOW

  • Cause: Overflow during conversion (type p)
    Runtime Error: BCD_OVERFLOW


Non-Catchable Exceptions

  • Cause: Source field (type p) contains an incorrect BCD format
    Runtime Error: BCD_BADDATA