COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
FIRST
specifies that only the first occurrence of compare-string is replaced.
compare-string
is the identifier of any type of elementary item with USAGE DISPLAY or nonnumeric
literal. It can be a figurative constant that does not include the keyword ALL, in which
case it represents one character.
replace-string
is an identifier of any type of elementary item with USAGE DISPLAY or a nonnumeric
literal. It can be a figurative constant that does not include the keyword ALL, in which
case it represents one character. When replace-string and compare-string
are used together, they must be the same size.
position
is as described earlier for absolute-replacement.
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 INSPECT TALLYING (page 345) Usage
Considerations: and INSPECT REPLACING (page 349) 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-strings, compare-strings, 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.
356 Procedure Division Verbs










