XTPACK: Writing a Packed Number With Up to 31 Significant Digits to an Output File

How to:

The XTPACK function stores packed numbers with up to 31 significant digits in an alphanumeric field, retaining decimal data. This permits writing a short or long packed field of any length, 1 to 16 bytes, to an output file.

Syntax: How to Store Packed Values in an Alphanumeric Field

XTPACK(in_value, outlength, outdec, output)

where:

infield

Numeric

Is the packed value.

outlength

Numeric

Is the length of the alphanumeric field that will hold the converted packed field. Can be from 1 to 16.

outdec

Numeric

Is the number of decimal positions for output.

output

Alphanumeric

Is the name of the field to contain the result or the format of the field enclosed in single quotation marks.

Example: Writing a Long Packed Number to an Output File

The following request creates a long packed decimal field named LONGPCK. ALPHAPCK (format A13) is the result of applying XTPACK to the long packed field. PCT_INC, LONGPCK, and ALPHAPCK are then written to a SAVE file named XTOUT.

DEFINE FILE EMPLOYEE
LONGPCK/P25.2 = PCT_INC + 11111111111111111111;
ALPHAPCK/A13 = XTPACK(LONGPCK,13,2,'A13');
END
TABLE FILE EMPLOYEE
PRINT PCT_INC LONGPCK ALPHAPCK
WHERE PCT_INC GT 0
  ON TABLE SAVE AS XTOUT
END

The SAVE file has the following fields and formats:

ALPHANUMERIC RECORD NAMED  XTOUT
FIELDNAME                         ALIAS         FORMAT        LENGTH
PCT_INC                           PI            F6.2            6
LONGPCK                                         P25.2          25
ALPHAPCK                                        A13            13
TOTAL                                                          44
SAVED...