RPG/400 Help

TESTN (Test Numeric)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| TESTN   |               |                 | Character      |    NU BN BL   |
|         |               |                 | field          |               |
*---------*---------------*-----------------*----------------*---------------*

The TESTN operation tests a character result field for the presence of zoned decimal digits and blanks. The result field must be a character field. To be considered numeric, each character in the field, except the low-order character, must contain a hexadecimal F zone and a digit (0 through 9). The low-order character is numeric if it contains a hexadecimal C, hexadecimal D, or hexadecimal F zone, and a digit (0 through 9). Note that the alphabetic characters J through R, should they appear in the low-order position of a field, are treated as negative numbers by TESTN. As a result of the test, resulting indicators are set on as follows:

The same indicator can be used for more than one condition. If any of the conditions exist, the indicator is set on.

To prevent undesirable results or an abnormal end of a program, the TESTN operation validates data in fields before arithmetic or editing operations are processed on the fields. Following validation, the field must be moved to a numeric field to process the arithmetic and editing operations.

Figure "TESTN Operation" illustrates uses of the TESTN operation.

TESTN Examples

Figure 59. TESTN Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C*  The field values are FLDA = 123, FLDB = 1X4, FLDC = 004,
C*  FLDD = bbb, FLDE = b1b3, and FLDF = b12.
C*
C*  Indicator 21 is set on because FLDA contains all numeric
C*  characters.
C                     TESTN          FLDA       21
C*  Indicator 22 is set on because FLDA contains all numeric
C*  characters.  Indicators 23 and 24 remain off.
C                     TESTN          FLDA       222324
C*  All indicators are off because FLDB does not contain valid
C*  numeric data.
C                     TESTN          FLDB       252627
C*  Indicator 28 is set on because FLDC contains valid numeric data.
C*  Indicators 29 and 30 remain off.
C                     TESTN          FLDC       282930
C*  Indicator 33 is set on because FLDD contains all blanks.
C*  Indicators 31 and 32 remain off.
C                     TESTN          FLDD       313233
C*  Indicators 34, 35, and 36 remain off.  Indicator 35 remains off
C*  off because FLDE contains a blank after a digit.
C                     TESTN          FLDE       343536
C*  Indicator 38 is set on because FLDF contains leading blanks and
C*  low order digits.  Indicators 37 and 39 remain off.
C                     TESTN          FLDF       373839


[ Top of Page | Previous Page | Next Page | Table of Contents ]