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-31
Including Text From a COPY Library
Copying With Replacement
Copying with replacement means copying text from a COPY library, modifying it, and
then writing it into a source program. Copying with replacement is achieved with the
REPLACING phrase.
Using the preceding example, suppose that the number of sales offices increases from
24 through 27. You have two choices:
In the COPY library, change 24 to 27:
?SECTION OFFICES
27
In the HP COBOL source program, add REPLACING phrases to the appropriate
COPY statements:
01 RENT RATE PICTURE 9(6) OCCURS COPY OFFICES
REPLACING 24 BY 27. TIMES.
01 EMPLOYEES OCCURS COPY OFFICES
REPLACING 24 BY 27. TIMES.
...03 MANAGEMENT PICTURE 9(3).
...03 ADMINISTRATIVE PICTURE 9(3).
...03 SALES PICTURE 9(3).
...03 SUPPORT PICTURE 9(3).
...03 OTHER PICTURE 9(3).
The resulting source code is:
01 RENT RATE PICTURE 9(6) OCCURS 27 TIMES.
01 EMPLOYEES OCCURS 27 TIMES.
...03 MANAGEMENT PICTURE 9(3).
...03 ADMINISTRATIVE PICTURE 9(3).
...03 SALES PICTURE 9(3).
...03 SUPPORT PICTURE 9(3).
...03 OTHER PICTURE 9(3).
(This COPY library itself does not change.)
Copying with replacement is not the only way to replace text-words in source code; the
REPLACE statement is another way. See Replacing Text-Words in an HP COBOL
Source Program.