COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
4. If the compiler compares all the occurrences of pseudo-text-1 without finding a match,
it considers the next text-word of the source program as the leftmost source program
text-word and starts the comparison cycle again with the first occurrence of
pseudo-text-1.
5. Whenever a match occurs between pseudo-text-1 and the source program text, the
compiler replaces the matched text in the source program with the corresponding
pseudo-text-2. The compiler then considers the source program text-word immediately
following the rightmost text-word that participated in the match to be the leftmost source
program text-word, and starts the comparison cycle again with the first occurrence of
pseudo-text-1.
6. The compiler continues its comparison operation until either the rightmost text-word in the
source program text (within the scope of the REPLACE statement) has participated in a
match or has been considered as a leftmost text-word and participated in a complete
comparison cycle.
• Comment Lines and Blank Lines in Replacement Text
The matching operation ignores any comment lines or blank lines occurring in the source
program text. The compiler determines the sequence of text-words in the source program text
and in pseudo-text-1 by the rules for reference format.
The replacement operation copies comment lines or blank lines in pseudo-text-2 into the
source program text without change whenever it copies pseudo-text-2 into the source
program.
The compiler does replace a comment line or blank line in source program text if that comment
line or blank line appears within the sequence of text-words that match pseudo-text-1.
• Debugging Lines
You can put debugging lines in pseudo-text-1 or in pseudo-text-2. text-words within
a debugging line participate in the comparison cycle as though the indicator area did not
contain a D or d.
If a portion of the apparent source text is replaced, any text-words of the replacement text
specified on debugging lines appear on debugging lines in the final source text.
If a portion of the apparent source text that begins on a debugging line is replaced, all
text-words of the replacement text appear on debugging lines in the final source text.
If the REPLACE statement itself begins on a debugging line, all replacement text, except
comment and compiler directive lines, appears on debugging lines.
Because debugging lines and continuation lines are mutually exclusive, the compiler cannot
introduce a continued text-word into the source text when the preceding rules require it to
appear on debugging lines.
• Sensitivity to Reference Format
Because, when a REPLACE statement is in force, the compiler analyzes pseudo-text (and source
text) without the benefit of any contextual information, you must observe the COBOL reference
format rules carefully. In particular, the compiler does not identify a comma, semicolon, or
period character as a separator unless it is followed by at least one space character.
Similarly, the compiler interprets the character sequence X/9 as one text-word (presumably
a PICTURE character-string) rather than as three text-words; however, the compiler always
considers a left parenthesis, right parenthesis, or colon character to be a separator unless it
appears within a nonnumeric literal.
The REPLACE statement in Example 146 enables you to declare a name for a constant in your
program, then use that name in various places in a program. While OFFICES could have
been declared as a data-item for this purpose, SQ-FT-SIZE could not have.
510 Source Text Manipulation










