COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

==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.
For restrictions on the use of the REPLACE statement and a detailed explanation of the comparison
operation that it uses, see REPLACE Statement (page 508).
Topics:
Replacing Substrings
Replacing Text-Words From COPY Libraries
Replacing Text-Words From SOURCE Libraries
Replacing Substrings
The REPLACE statement can only replace entire text-words (DAILY-TOTAL but not just TOTAL, for
example); however, parenthesized words within pseudo-text are recognized as text-words, allowing
you to write statements such as:
REPLACE ==(PREFIX)== BY ==DAILY==.
Suppose that you want to declare several identifiers that begin with the same prefix (such as
DAILY-TOTAL, DAILY-MINIMUM, and DAILY-MAXIMUM), several identifiers that end with the same
suffix (such as DAILY-TOTAL, WEEKLY-TOTAL, and MONTHLY-TOTAL), and several identifiers that
contain the same strings (such as AVG-DAILY-COST, AVG-MONTHLY-COST, and
AVG-ANNUAL-COST).
The two sets of source code in Example 238 are equivalent.
Example 238 Replacing Substrings in an HP COBOL Source Program
REPLACE ==(PREFIX)== BY ==DAILY==.
==(SUFFIX)== BY ==TOTAL==.
==(PRE)== BY ==AVG==
==(SUF)== BY ==COST==.
77 (PREFIX)-TOTAL PIC S9(8).99.
77 (PREFIX)-MINIMUM PIC S9(8).99.
77 (PREFIX)-MAXIMUM PIC S9(8).99.
77 DAILY-(SUFFIX) PIC S9(8).99.
77 WEEKLY-(SUFFIX) PIC S9(8).99.
77 MONTHLY-(SUFFIX) PIC S9(8).99.
77 (PRE)-DAILY-(SUF) PIC S9(8).99.
77 (PRE)-MONTHLY-(SUF) PIC S9(8).99.
77 (PRE)-ANNUAL-(SUF) PIC S9(8).99.
77 DAILY-TOTAL PIC S9(8).99.
77 DAILY-MINIMUM PIC S9(8).99.
77 DAILY-MAXIMUM PIC S9(8).99.
77 DAILY-TOTAL PIC S9(8).99.
77 WEEKLY-TOTAL PIC S9(8).99.
77 MONTHLY-TOTAL PIC S9(8).99.
77 AVG-DAILY-COST PIC S9(8).99.
Replacing Text-Words in an HP COBOL Source Program 767