RPG/400 Help

CHEKR (Check Reverse)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| CHEKR   | Comparator    | Base            | Right-         |    _ ER FD    |
|         | string        | string:start    | position       |               |
*---------*---------------*-----------------*----------------*---------------*

The CHEKR operation verifies that each character in the base string (factor 2) is among the characters indicated in the comparator string (factor 1). Verifying begins at the rightmost character of factor 2 and continues character by character, from right to left. Each character of the base string is compared with the characters of factor 1. If a match for a character in factor 2 exists in factor 1, the next source character is verified. If a match is not found, an integer value is placed in the result field to indicate the position of the incorrect character. Although checking is done from the right, the position placed in the result field will be relative to the left.

You can specify a start position in factor 2, separating it from the base string by a colon. The start position is optional and defaults to the length of the string. The value in the result field is relative to the leftmost position in the source string, regardless of the start position.

If the result field is not an array, the operation stops checking when it finds the first incorrect character or when the end of the base string is encountered. If no incorrect characters are found, the result field is set to zero.

If the result field is an array, the operation continues checking after the first incorrect character is found for as many occurrences as there are elements in the array. If there are more array elements than incorrect characters, all of the remaining elements are set to zeros.

Factor 1 must be character, and can contain one of: a field name, array element, named constant, data structure name, data structure subfield, literal, or table name.

Factor 2 must contain either the base string or the base string, followed by a colon, followed by the start location. The base string portion of factor 2 must be character, and can contain: a field name, array element, named constant, data structure name, data structure subfield name, literal, or table name. The start location portion of factor 2 must be numeric with no decimal positions, and can be a named constant, array element, field name, literal, or table name. If no start location is specified, the length of the string is used.

The result field can be a numeric variable, numeric array element, numeric table name, or numeric array. Define the field or array specified with no decimal positions. The result field is an optional field; if you do not specify it, you must specify the found indicator in position 58-59.

Figurative constants cannot be used in the factor 1, factor 2, or result fields. No overlapping is allowed in a data structure for factor 1 and the result field, or for factor 2 and the result field.

Any valid indicator can be specified in positions 7 to 17.

The indicator in positions 56-57 is turned on if an error occurs. The indicator in positions 58-59 is turned on if any incorrect characters are found.

Figure "CHEKR Operation" shows examples of the CHEKR operation.

CHEKR Examples

Figure 19. CHEKR Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C* Because factor 1 is a blank character, CHEKR indicates the
C* position of the first nonblank character.  This use of CHEKR
C* allows you to determine the length of a string.  If STRING
C* contains 'ABCDEF   ', NUM will contain the value 6.
C*
C           ' '       CHEKRSTRING    NUM     20
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
I..............Namedconstant+++++++++C.........Fldnme......... ....
I*
I* After the following example, N=1 and the found indicator 90
I* is on. Because the start position is 5, the operation begins
I* with the rightmost 0 and the first nonnumeric found is the '$'.
I*
I              '0123456789'          C         DIGITS
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C                     MOVE '$2000.'  SALARY  6
C           DIGITS    CHEKRSALARY:5  N              90
E*
E* The following example checks that FIELD contains only the letters
E* A to J.  As a result, ARRAY=(876310) after the CHEKR operation.
E* Indicator 90 turns on.
E*
E....FromfileTofile++Name++N/rN/tbLenPDSArrnamLenPDSComments
E                    ARRAY       6  1 0
I..............Namedconstant+++++++++C.........Fldnme......... ....
I              'ABCDEFGHIJ'          C         LETTER
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C                     MOVE '1A=BC***'FIELD   8
C           LETTER    CHEKRFIELD     ARRAY          90


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