COBOL Manual for TNS and TNS/R Programs

Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs522555-006
9-107
INSPECT TALLYING REPLACING
INSPECT TALLYING REPLACING
INSPECT TALLYING REPLACING counts occurrences of a sequence of one or more
characters in a data item and replaces each occurrence with a specified value.
source-string
is the identifier of an elementary item or data structure with USAGE DISPLAY.
Inspection proceeds from left to right within source-string.
tallying-phrase
tally
is the identifier of an elementary numeric item where the number of
occurrences is to be stored. The INSPECT statement does not initialize tally
but adds to its current value. If you want tally to begin at a given number,
set it before the INSPECT statement executes.
Example 9-40. One INSPECT Statement, Several Replacements
WORKING-STORAGE SECTION.
77 ITEM-C PIC X(10) VALUE "009,999. ".
PROCEDURE DIVISION.
INSPECT ITEM-C REPLACING ALL " " BY "0",
LEADING "0" BY "$",
ALL "9" BY "X" AFTER INITIAL ","
INSPECT source-string tallying-phrase replacing-phrase
VST174.vsd
FORtallyTALLYING for-clause
VST165.vsd