UNPACK
Short Reference
Syntax
UNPACK source TO destination.
Effect
This statement converts the content of the data object source
according to a specific rule and assigns the converted content to data object
destination. For source, the data type p of length 16 without
decimal places is expected. The data type of destination must be character-type and
flat.
The conversion is performed according to the following rules:
-
If the data type of source is not of the 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 +/- sign. Any additional places in destination
are filled with leading zeros. If the length of destination is not sufficient, the assigned variable is truncated from the left.
Notes
-
The function of the statement UNPACK is based on the fact, that the
BCD display of a
decimal place corresponds to the second
half-byte of code of a digit in the most character representations. This conversion is commonly called "unpacking".
-
The statement PACK to pack is obsolete and can be replaced by MOVE.
-
If destination is specified as untyped field symbol or
as untyped formal parameter and is not flat and not character-type during execution of the statement, then an untreatable exception occurs in
Unicode programs. In
non-Unicode programs, an exception occurs only with
deep types, whereas flat types are treated as character-type types.
Example
After the assignments,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.
Catchable Exceptions
CX_SY_CONVERSION_NO_NUMBER
-
Cause: source field is not interpretable as number
Runtime Error: CONVT_OVERFLOW (catchable)
CX_SY_CONVERSION_OVERFLOW
-
Cause: Overflow at conversion (type P)
Runtime Error: BCD_OVERFLOW (catchable)
Non-Catchable Exceptions
-
Cause: source field (type P) contains an incorrect BCD-Format
Runtime Error: BCD_BADDATA