Available Languages: reporting, Maintain
The CHKPCK function validates the data in a field described as packed format (if available on your platform). The function prevents a data exception from occurring when a request reads a field that is expected to contain a valid packed number but does not.
To use CHKPCK:
CHKPCK(length, in_value, error, output)
Is the length of the packed field. It can be between 1 and 16 bytes.
Is the name of the packed field or the value to be verified as packed decimal. The value must be described as alphanumeric, not packed.
Is the error code that the function returns if a value is not packed. Choose an error code outside the range of data. The error code is first truncated to an integer, then converted to packed format. However, it may appear on a report with a decimal point depending on the output format.
Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.
DEFINE FILE EMPLOYEE PACK_SAL/A8 = IF EMP_ID CONTAINS '123' THEN 'AAA' ELSE PCKOUT(CURR_SAL, 8, 'A8'); END
TABLE FILE EMPLOYEE PRINT DEPARTMENT PACK_SAL BY EMP_ID ON TABLE SAVE AS TESTPACK END
The output is:
NUMBER OF RECORDS IN TABLE= 12 LINES= 12 ALPHANUMERIC RECORD NAMED TESTPACK FIELDNAME ALIAS FORMAT LENGTH EMP_ID EID A9 9 DEPARTMENT DPT A10 10 PACK_SAL A8 8 TOTAL 27
FILE = TESTPACK, SUFFIX = FIX FIELD = EMP_ID ,ALIAS = EID,USAGE = A9 ,ACTUAL = A9 ,$ FIELD = DEPARTMENT,ALIAS = DPT,USAGE = A10,ACTUAL = A10,$ FIELD = PACK_SAL ,ALIAS = PS ,USAGE = A8 ,ACTUAL = A8 ,$
DEFINE FILE TESTPACK GOOD_PACK/P8CM = CHKPCK(8, PACK_SAL, -999, GOOD_PACK); END
TABLE FILE TESTPACK PRINT DEPARTMENT GOOD_PACK BY EMP_ID END
The output is:
EMP_ID DEPARTMENT GOOD_PACK ------ ---------- --------- 071382660 PRODUCTION $11,000 112847612 MIS $13,200 117593129 MIS $18,480 119265415 PRODUCTION $9,500 119329144 PRODUCTION $29,700 123764317 PRODUCTION -$999 126724188 PRODUCTION $21,120 219984371 MIS $18,480 326179357 MIS $21,780 451123478 PRODUCTION -$999 543729165 MIS $9,000 818692173 MIS $27,062