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) 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 number of bytes in the packed field. It can be between 1 and 16 bytes.

infield

Alphanumeric

Is the value to be verified as packed decimal. 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



Example: Validating Packed Data

CHKPCK validates the values in PACK_SAL, and store the result in a column with the format P8CM. Values not in packed format return the error code -999. Values in packed format appear accurately.

CHKPCK(8, PACK_SAL, -999, 'P8CM')

iWay Software