Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Assignments →  Special Assignments 

UNPACK

Quick 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, 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 intermediate result are assigned right-justified to the data object destination and without a sign. Any surplus places 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 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.

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

Handleable 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-Handleable Exceptions

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