Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Assignments →  Special 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 zeroes 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 used for packing is obsolete and can be replaced by a regular assignment.
  • If destination is specified as an untyped field symbol or as an untyped formal parameter and is not flat and character-like when the statement is executed, an exception is raised only in deep types in obsolete non-Unicode programs. Flat types, on the other hand, are handled like the character-like type c.

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. 

char1 = pack. 
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