PCKOUT: Writing a Packed Number of Variable Length

How to:

Available Languages: reporting, Maintain

The PCKOUT function writes a packed-decimal number of variable length to an extract file. When a request saves a packed number to an extract file, it typically writes it as an 8- or 16-byte field regardless of its format specification. With PCKOUT, you can vary the field's length between 1 to 16 bytes.

Syntax: How to Write a Packed Number of Variable Length

PCKOUT(in_value, length, output)

where:

in_value

Numeric

Is the input field that contains the values. It can be in packed, integer, single- or double-precision floating point format. If it is not in integer format, it is rounded to the nearest whole number.

length

Numeric

Is the length of the output value, from 1 to 16 bytes.

output

Alphanumeric

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks. The function returns the field as alphanumeric although it contains packed data.

Example: Writing a Packed Number of Variable Length

PCKOUT converts the CURR_SAL field to a 5-byte packed field and stores the result in SHORT_SAL:

DEFINE FILE EMPLOYEE
SHORT_SAL/A5 = PCKOUT(CURR_SAL, 5, SHORT_SAL);
END
TABLE FILE EMPLOYEE
PRINT LAST_NAME SHORT_SAL HIRE_DATE
ON TABLE SAVE
END

The resulting extract file is:

 NUMBER OF RECORDS IN TABLE=       12 LINES=     12 
 
ALPHANUMERIC  RECORD  NAMED  SAVE 
FIELDNAME                          ALIAS         FORMAT          LENGTH 
LAST_NAME                          LN            A15               15 
SHORT_SAL                                        A5                 5 
HIRE_DATE                          HDT           I6YMD              6 
TOTAL                                                              26