The REPLACE statement is used to replace source program text.
A REPLACE statement can occur anywhere in the source program where a character-string can occur. It must be preceded by a separator period except when it is the first statement in a separately compiled program. It must be terminated by a separator period.
The REPLACE statement provides a means of applying a change to an entire COBOL source program, or part of a source program, without manually having to find and modify all places that need to be changed. It is an easy method of doing simple string substitutions. It is similar in action to the REPLACING phrase of the COPY statement, except that it acts on the entire source program, not just on the text in COPY libraries.
If the word REPLACE appears in a comment-entry or in the place where a comment-entry can appear, it is considered part of the comment-entry.
___ Format 1 ___________________________________________________________ | | | <__________________________________________ | | >>__REPLACE____==pseudo-text-1==__BY__==pseudo-text-2==_|__.________>< | | | |________________________________________________________________________|Each matched occurrence of pseudo-text-1 in the source program is replaced by the corresponding pseudo-text-2.
___ Format 2 ___________________________________________________________ | | | >>__REPLACE OFF.____________________________________________________>< | | | |________________________________________________________________________|Any text replacement currently in effect is discontinued with the format 2 form of REPLACE. If format 2 is not specified, a given occurrence of the REPLACE statement is in effect from the point at which it is specified until the next occurrence of the statement or the end of the separately compiled program, respectively.
Note: Characters outside the standard COBOL character set should not appear in pseudo-text, other than as part of nonnumeric literals, comment lines, or comment-entries.
The compiler processes REPLACE statements in a source program after the processing of any COPY statements. COPY must be processed first, to assemble a complete source program. Then REPLACE can be used to modify that program, performing simple string substitution. REPLACE statements can themselves contain COPY statements.
The text produced as a result of the processing of a REPLACE statement must not contain a REPLACE statement.
Subtopics:
Adobe, the Adobe logo, Acrobat, the Acrobat logo, and Acrobat Reader are registered trademarks of Adobe Systems incorporated.