COBOL Manual for TNS and TNS/R Programs
Source Text Manipulation
HP COBOL Manual for TNS and TNS/R Programs—522555-006
10-9
REPLACING Phrase
Usage Considerations:
•
Effect of REPLACE on Literals
The REPLACE statement does not affect literals; for example,
REPLACING ==Year== BY ==Month==
does not change the original text-word
"End of Year"
to the new text-word
"End of Month"
•
Matching Text in a COPY Library
The compiler searches for portions of text in the order you specify in the
REPLACING phrase. If you want to replace a sequence of text-words with
something and a particular text-word with something else, specify the sequence
first. For example, if you want to replace all occurrences of “XXX” with “BALANCE”
and all occurrences of “XXX OF YYY” with “BALANCE OF BUDGET-REC,” the
REPLACING phrases must be in this order:
REPLACING "XXX OF YYY" BY "BALANCE OF BUDGET-REC"
"XXX" BY "BALANCE"
If you specify “XXX” first, the compiler first changes the “XXX” to “BALANCE,”
producing “BALANCE OF YYY;” therefore, it can never find the sequence “XXX OF
YYY.”
For purposes of matching, the compiler handles identifier-1, word-1, and
literal-1 as pseudo-text containing only identifier-1, literal-1, or
word-1, respectively.
•
Comparison Operation
The compiler determines which characters of source text to replace by comparing
pseudo-text-1, identifier-1, literal-l to text-words in the COPY
library. This is how the comparison operation works:
1. The compiler copies any separator comma, semicolon, and space that
precedes the leftmost library text-word into the source program.
2. Starting with the leftmost library text-word, the compiler compares all the text-
words in the first pseudo-text-1, identifier-1, literal-1, or word-1
to an equal number of contiguous text-words in the library. During the
comparison, the compiler handles each occurrence of a separator comma or
semicolon and each sequence of one or more space separators as a single
space. The compiler ignores any comment or directive line in the library text or
in pseudo-text-1. The REPLACING phrase operand matches the library
text if the two sequences of text-words are equal, character for character.