$Unpack

From m204wiki
Revision as of 15:27, 31 July 2014 by Mlarocca (talk | contribs) (Mlarocca moved page $UNPACK to $Unpack: Lower case change)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The $UNPACK function converts data in packed decimal format into a string that can be stored in a Model 204 file and processed by a request.

Syntax

The format of the $UNPACK function is:

$UNPACK(value [ ,scale] )

where:

  • value is the data to be unpacked. If the data is not a valid packed decimal string of as many as 18 digits, a null string is returned.
  • scale specifies the number of implied decimal places in the packed input. If scale is greater than 18 or less than 0, a null string is returned. If scale is omitted, a default value of zero is used, indicating an integer value.

The resulting unpacked string is preceded by a minus sign if the packed number was negative. If the scale provided is greater than the number of digits in the value, the value is right-justified by the appropriate number of digits, the decimal point is inserted in the appropriate location, and a leading zero is inserted in the units position.

Leading zeros to the left of the decimal point and trailing zeros to the right of the decimal point are truncated unless the result is zero. If there are no significant digits to the right of the decimal point, the decimal point is removed from the result as well.

Examples

These examples assume that %X contains a packed value of X'001234500C'.

Example 1:

%A = $UNPACK(%X,2)

results in %A having a string value of 12345.

Example 2:

%A = $UNPACK(%X,4)

results in %A having a string value of 123.45.

Example 3:

%A = $UNPACK(%X,10)

results in %A having a string value of 0.00012345.