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

In every table whose length must be the same as the number of sales offices, use a COPY statement;
for example:
01 RENT RATE PICTURE 9(6) OCCURS COPY OFFICES. TIMES.
01 EMPLOYEES OCCURS COPY OFFICES. 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).
Each COPY statement ends with a period. The COPY statement and its period are replaced by the
library text:
01 RENT RATE PICTURE 9(6) OCCURS 24 TIMES.
01 EMPLOYEES OCCURS 24 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).
If the section OFFICES had been empty, the COPY statements would have been replaced with
spaces. If there had been no section named OFFICES, the compiler would have reported an error
72 (Expected section-name ).
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.
Including Text From a COPY Library 763