COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-100
INSPECT TALLYING
°
If CHARACTERS appears, tally is incremented by one for each character
matched within source-string.
In the Example 9-37, INSPECT TALLYING checks for spaces in a data item. If spaces
are present (J-TALLY is greater than 0), the code reports an error.
In Example 9-38, an INSPECT TALLYING statement uses multiple compare-string
s. 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 9-37. 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
Example 9-38. 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 ","