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-30
Including Text From a COPY Library
Topics:
Simple Copying
Copying With Replacement
Replacing Substrings
Copying Into Debugging Lines
Using Multiple COPY Libraries
Using COPY Libraries Efficiently
Simple Copying
Simple copying means copying text from a COPY library into a source program. This
example uses simple copying to copy the occurrence number in an OCCURS clause
into more than one data description entry, as if it were a constant.
Suppose that the present number of sales offices is 24, but you expect it to change.
Put this text into a COPY library:
?SECTION OFFICES
24
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 ).