Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Assignments →  Value Assignments 

UNPACK

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


UNPACK source TO destination. 

Effect

This statement converts the content of the data object source in accordance with special rules and assigns the converted content to the data object destination. source expects the data type p of length 16 without decimal places. Operands of data type decfloat16 or decfloat34 cannot be used. The data type of destination must be character-like and flat.

The conversion is performed according to the following rules:

  • If the data type of source is not of type p with length 16 and without decimal places, then the content of source is converted to this data type. Contrary to the rules described in Conversion Rules for Elementary Data Types, any decimal separator in source is completely ignored.
  • The digits of the interim result are assigned to data object destination right-aligned and without a sign. Any surplus positions in destination are padded with zeros on the left. If the length of destination is not sufficient, the assigned value is truncated on the left.


Notes

  • The function of the statement UNPACK is 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".
  • The statement PACK packing is obsolete and can be replaced by MOVE.
  • If destination is 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.

Example

After the assignments are made, char1 and 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. 

Exceptions


Catchable Exceptions

CX_SY_CONVERSION_NO_NUMBER

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

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