COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-106
INSPECT REPLACING
Usage Considerations:
•
Rules for Replacement
°
CHARACTERS causes each character in source-string to be replaced by
replace-string.
°
ALL causes each occurrence of compare-string in source-string to be
replaced by replace-string.
°
LEADING causes each contiguous occurrence of compare-string in
source-string to be replaced by replace-string, provided that the
leftmost occurrence is at the point where comparison began in the first
comparison cycle in which compare-string was eligible to participate.
°
FIRST causes the leftmost occurrence of compare-string in source-
string to be replaced by replace-string.
ALL, LEADING, and FIRST apply to each succeeding BY phrase until the next
ALL, LEADING, or FIRST appears.
•
See these usage considerations in INSPECT TALLYING:
°
How Parameter Categories Affect INSPECT
°
Comparison Operation
°
BEFORE and AFTER Phrases
•
Leading Zeros
HP COBOL does not treat leading spaces in a numeric data item as if they were
leading zeros, as some implementations of COBOL do. To convert leading spaces
to zeros, use the INSPECT statement as Example 9-39 does.
In Example 9-40, several replacements occur during the execution of one
INSPECT statement. When the INSPECT statement finishes executing, ITEM-C
equals “$$9,XXX.00.”
Example 9-39. INSPECT Statement Converting Leading Spaces to Zeros
WORKING-STORAGE SECTION.
03 A-VALUE PICTURE X(10) VALUE " 23".
03 N-VALUE PICTURE 9(10) REDEFINES A-VALUE.
...
INSPECT A-VALUE REPLACING LEADING " " BY "0".