COBOL Manual for TNS and TNS/R Programs
Creating and Compiling HP COBOL Source
Programs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
22-37
Replacing Substrings
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 22-10 are equivalent.
Compare the preceding example to the example in Replacing Substrings.
Example 22-10. 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.
77 AVG-MONTHLY-COST PIC S9(8).99.
77 AVG-ANNUAL-COST PIC S9(8).99.