COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

leftmost such occurrence is at the point where comparison began in the first comparison
cycle in which compare-string was eligible to participate.
If CHARACTERS appears, tally is incremented by one for each character matched
within source-string.
In the Example 106, INSPECT TALLYING checks for spaces in a data item. If spaces are present
(J-TALLY is greater than 0), the code reports an error.
Example 106 INSPECT TALLYING With One Compare-String
MOVE ZERO TO J-TALLY
INSPECT JOB-CLASS TALLYING J-TALLY FOR ALL SPACES
IF J-TALLY GREATER THAN 0
MOVE 0 TO J-TALLY
MOVE 3 TO MESSAGE-INDEX
PERFORM PRINT-ERROR
ELSE
MOVE 1 TO FLAG
END-IF
In Example 107, an INSPECT TALLYING statement uses multiple compare-strings. Some
characters look as if they qualify as matches, yet are not counted, because a character can be
counted only once, no matter how many comparisons it can satisfy.
Example 107 INSPECT TALLYING With Multiple Compare-Strings
WORKING-STORAGE SECTION.
01 INSPECT-COUNTERS.
03 COUNTER-1 PIC 99 VALUE 0.
03 COUNTER-2 PIC 99 VALUE 0.
03 COUNTER-3 PIC 99 VALUE 0.
03 COUNTER-4 PIC 99 VALUE 0.
03 COUNTER-5 PIC 99 VALUE 0.
77 ITEM-A PIC X(15) VALUE " 00001,003,200".
PROCEDURE DIVISION.
...
INSPECT ITEM-A TALLYING
COUNTER-1 FOR ALL "0",
COUNTER-2 FOR CHARACTERS BEFORE INITIAL ","
COUNTER-3 FOR LEADING " ",
COUNTER-4 FOR ALL "0" BEFORE INITIAL ",",
COUNTER-5 FOR ALL "0" AFTER INITIAL ","
After execution of the INSPECT statement in Example 107, the counters have these values:
ValueCounter
8COUNTER-1
3COUNTER-2
0COUNTER-3
0COUNTER-4
0COUNTER-5
INSPECT REPLACING
INSPECT REPLACING replaces occurrences of a sequence of one or more characters in a data
item with a specified value.
INSPECT 349