$Pack

From m204wiki
(Redirected from $PACK)
Jump to navigation Jump to search

The $PACK function returns the packed decimal representation of the character string.

Syntax

The format for the $PACK function is:

$PACK(value,precision [,scale] [,'UNSIGNED'] )

where:

  • value is a character string that can be a field name, a %variable, or any type of string expression.
  • precision is the number of digits required in the number to be returned. The valid range is between 1 to 16. The precision argument is required.
  • scale specifies the number of digits to be returned to the right of the decimal point. The scale argument is optional. If the scale argument is omitted, the returned result is an integer.
  • UNSIGNED specifies that the packed decimal data has a sign code of X'F' regardless of the sign of the data value. The UNSIGNED argument is optional. If the UNSIGNED argument is omitted, the data contains the appropriate code for the sign of the data value.

Usage

$PACK can be used as an item in an assignment to a %variable that is written to a sequential USE data set.

$PACK should not be used as an operand in an arithmetic expression, because the value returned cannot be correctly interpreted as a number.

Model 204 pads the result with leading integer or trailing fractional zeros as appropriate. If the value string is too long for the precision, or if the value is nonnumeric, $PACK returns binary ones.

Model 204 interprets the value returned by $PACK as a character string.

If the precision argument is omitted or if the value is outside the valid range, the following message is issued:

M204.2139: $PACK PRECISION MUST BE IN RANGE 1-16

Example

If you specify these statements:

%X = '123.4' %A = $PACK(%X,8,3,'UNSIGNED')

the result in %A would be X'0123400F'. When you use the UNSIGNED argument, the result would be identical if %X were assigned a value of -123, because $PACK operates on the absolute value of the number supplied.