Rational Developer for System z
Enterprise COBOL for z/OS, Version 4.1, Programming Guide


Checking for incompatible data (numeric class test)

The compiler assumes that values you supply for a data item are valid for the PICTURE and USAGE clauses, and does not check their validity. Ensure that the contents of a data item conform to the PICTURE and USAGE clauses before using the item in additional processing.

It can happen that values are passed into your program and assigned to items that have incompatible data descriptions for those values. For example, nonnumeric data might be moved or passed into a field that is defined as numeric, or a signed number might be passed into a field that is defined as unsigned. In either case, the receiving fields contain invalid data. When you give an item a value that is incompatible with its data description, references to that item in the PROCEDURE DIVISION are undefined and your results are unpredictable.

You can use the numeric class test to perform data validation. For example:

Linkage Section.
01  Count-x   Pic 999.
. . .
Procedure Division Using Count-x.
    If Count-x is numeric then display "Data is good"

The numeric class test checks the contents of a data item against a set of values that are valid for the PICTURE and USAGE of the data item. For example, a packed-decimal item is checked for hexadecimal values X'0' through X'9' in the digit positions and for a valid sign value in the sign position (whether separate or nonseparate).

For zoned decimal and packed-decimal items, the numeric class test is affected by the NUMPROC compiler option and the NUMCLS option (which is set at installation time). To determine the NUMCLS setting used at your installation, consult your system programmer.

If NUMCLS(PRIM) is in effect at your installation, use the following table to find the values that the compiler considers valid for the sign.

Table 1. NUMCLS(PRIM) and valid signs
  NUMPROC(NOPFD) NUMPROC(PFD) NUMPROC(MIG)
Signed C, D, F C, D, +0 (positive zero)   C, D, F  
Unsigned F F F
Separate sign +, - +, -, +0 (positive zero)   +, -

If NUMCLS(ALT) is in effect at your installation, use the following table to find the values that the compiler considers valid for the sign.

Table 2. NUMCLS(ALT) and valid signs
  NUMPROC(NOPFD) NUMPROC(PFD) NUMPROC(MIG)
Signed A to F C, D, +0 (positive zero)   A to F  
Unsigned F F F
Separate sign +, - +, -, +0 (positive zero)   +, -

related references  
NUMPROC


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)