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-32
Including Text From a COPY Library
Replacing Substrings
The REPLACING phrase 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:
COPY SUM-IT REPLACING ==(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).
Example 22-6. Replacing Substrings
Lines in COPY library:
?SECTION PREFIX
77 (PREFIX)-TOTAL PIC S9(8).99.
77 (PREFIX)-MINIMUM PIC S9(8).99.
77 (PREFIX)-MAXIMUM PIC S9(8).99.
?SECTION SUFFIX
77 DAILY-(SUFFIX) PIC S9(8).99.
77 WEEKLY-(SUFFIX) PIC S9(8).99.
77 MONTHLY-(SUFFIX) PIC S9(8).99.
?SECTION PRESUF
77 (PRE)-DAILY-(SUF) PIC S9(8).99.
77 (PRE)-MONTHLY-(SUF) PIC S9(8).99.
77 (PRE)-ANNUAL-(SUF) PIC S9(8).99.
Lines in HP COBOL source program:
COPY PREFIX REPLACING ==(PREFIX)== BY ==DAILY==.
COPY SUFFIX REPLACING ==(SUFFIX)== BY ==TOTAL==.
COPY PRESUF REPLACING ==(PRE)== BY ==AVG==
==(SUF)== BY ==COST==.
HP COBOL source program effectively contains these lines:
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.