COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-112
INSPECT TALLYING REPLACING
Usage Considerations:
•
Action of the INSPECT TALLYING REPLACING Statement
The INSPECT TALLYING REPLACING statement is a combination of the 
INSPECT TALLYING and the INSPECT REPLACING statements. See Usage 
Considerations: and Usage Considerations:.
•
Difference Between INSPECT TALLYING REPLACING and
INSPECT TALLYING Followed by INSPECT REPLACING
The only difference between an INSPECT TALLYING REPLACING statement and 
an INSPECT TALLYING statement followed immediately by an INSPECT 
REPLACING statement with the same source-string s, compare-string s, 
and delim-string is the side effects.
Each form of the INSPECT statement performs all operand identification at the 
beginning of execution. The INSPECT TALLYING REPLACING statement 
performs only one operand identification operation, but the INSPECT TALLYING 
statement followed by the INSPECT REPLACING statement performs operand 
identification before the INSPECT TALLYING statement and again before the 
INSPECT REPLACING statement. If subscripts or reference modifiers in any 
operands of the REPLACING clause use values that the TALLYING phrase 
changes, the INSPECT TALLYING REPLACING statement works differently than 
the INSPECT TALLYING statement followed immediately by an INSPECT 
REPLACING statement.
For example, suppose X has the value “AAABBBABAB” and C is an array 
containing the values 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
Executing the three statements
MOVE 1 TO Y
INSPECT X TALLYING Y FOR LEADING "A"
INSPECT X REPLACING LEADING "A" BY C (Y)
changes the value of X to “333BBBABAB,” because the subscript Y in the 
REPLACING clause has the value 4 when the INSPECT REPLACING statement 
begins execution; however, executing the two statements
MOVE 1 TO Y
INSPECT X TALLYING Y FOR LEADING "A"
 X REPLACING LEADING "A" BY C (Y)
changes the value of X to “000BBBABAB,” because the subscript Y in the 
REPLACING clause has the value 1 when the INSPECT TALLYING REPLACING 
statement begins executing.










