CHKPCK: Validating a Packed Field

How to:

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:

  1. Ensure that the Master File (USAGE and ACTUAL attributes) or the MODIFY FIXFORM command defines the field as alphanumeric, not packed. This does not change the field data, which remains packed, but it enables the request to read the data without a data exception.
  2. Call CHKPCK to examine the field. The function returns the output to a field defined as packed. If the value it examines is a valid packed number, the function returns the value; if the value is not packed, the function returns an error code.

Top of page

x
Syntax: How to Validate a Packed Field
CHKPCK(length, in_value, error, output)

where:

length

Numeric

Is the length of the packed field. It can be between 1 and 16 bytes.

infield

Alphanumeric

Is the name of the packed field or the value to be verified as packed decimal. Is the. The value must be described as alphanumeric, not packed.

error

Numeric

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.

output

Packed-decimal

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.



Example: Validating Packed Data
  1. Prepare a data source that includes invalid packed data. The following example creates TESTPACK, which contains the PACK_SAL field. PACK_SAL is defined as alphanumeric but actually contains packed data. The invalid packed data is stored as AAA.
    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
    [EBCDIC|ALPHANUMERIC]  RECORD NAMED  TESTPACK 
    FIELDNAME                         ALIAS         FORMAT        LENGTH
    EMP_ID                            EID           A9               9 
    DEPARTMENT                        DPT           A10             10 
    PACK_SAL                                        A8               8 
    TOTAL                                                           27 
    [DCB USED WITH FILE TESTPACK IS DCB=(RECFM=FB,LRECL=00027,BLKSIZE=00540)] SAVED... >
  2. Create a Master File for the TESTPACK data source. Define the PACK_SAL field as alphanumeric in the USAGE and ACTUAL attributes.
    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 ,$
  3. Create a request that uses CHKPCK to validate the values in the PACK_SAL field, and store the result in the GOOD_PACK field. Values not in packed format return the error code -999. Values in packed format appear accurately.
    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

Information Builders