COBOL Manual for TNS and TNS/R Programs

Creating and Compiling HP COBOL Source
Programs
HP COBOL Manual for TNS and TNS/R Programs522555-006
22-36
Replacing Text-Words in an HP COBOL Source
Program
Replacing Text-Words in an HP COBOL Source
Program
You can replace text-words with other text-words in a HP COBOL source file with a
REPLACE statement. A REPLACE statement is active from the time the compiler
encounters it until the compiler encounters either another, overriding REPLACE
statement or the end of a separately compiled program.
The two Data Divisions in Example 22-9 are equivalent.
For restrictions on the use of the REPLACE statement and a detailed explanation of
the comparison operation that it uses, see REPLACE Statement.
Topics:
Replacing Substrings
Replacing Text-Words From COPY Libraries
Replacing Text-Words From SOURCE Libraries
Example 22-9. Replacing Text-Words in an HP COBOL Source Program
DATA DIVISION.
REPLACE ==OFFICES== BY ==10==
==SQ-FT-SIZE== BY ==5==
01 OFFS.
03 OFFICE-INFO OCCURS OFFICES TIMES.
05 DISTRICT PICTURE 99.
05 SQUARE-FEET PICTURE S9(SQ-FT-SIZE)
PROCEDURE DIVISION.
PERFORM REPORT-OFFICE OFFICE TIMES.
REPLACE OFF.
DATA DIVISION.
01 OFFS.
03 OFFICE-INFO OCCURS 10 TIMES.
05 DISTRICT PICTURE 99.
05 SQUARE-FEET PICTURE S9(5)
PROCEDURE DIVISION.
PERFORM REPORT-OFFICE 10 TIMES.