Library View Topics Framed Contents Revised Topics Previous Topic Next Topic Search Search ResultsPrevious Topic MatchNext Topic Match Notes List Notes Print Download No PDF Handheld DisconnectedHandheld ConnectedHelp

8.1.10 REPLACE Statement



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.

pseudo-text-1
Must contain one or more text words. Character-strings can be continued.


X As an IBM extension, pseudo-text-1 can consist entirely of a separator
X comma or a separator semicolon.

pseudo-text-2
Can contain zero, one, or more text words. Character strings can be continued.

Any individual character-string within pseudo-text can be up to 322 characters long.

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.


X The REPLACE statement can be used with DBCS literals and DBCS or EUC
X names.


X Pseudo-text can contain DBCS or EUC character-strings, but the characters
X cannot be continued across lines.

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:



Previous Topic Next Topic © Copyright IBM Corp. 1991, 1998

IBM Library Server Copyright 1989, 2005 IBM Corporation. All rights reserved.





Return to library:   z/OS | z/OS.e | TPF | z/VSE | z/VM | IBM Hardware | IBM System z Redbooks
Glossary:   IBM terminology
Publications:   How to order publications
Readers:   Download IBM Library Reader | Download IBM Softcopy Reader | Download Adobe® Acrobat® Reader®
Library management:   Download IBM Softcopy Librarian
Contacts:   Contact z/OS


Adobe, the Adobe logo, Acrobat, the Acrobat logo, and Acrobat Reader are registered trademarks of Adobe Systems incorporated.