Sequences of code (such as file and data descriptions, error and exception routines, etc.) that are common to a number of programs can be saved in a library, and then used in conjunction with the COPY statement. If naming conventions are established for such common code, then the REPLACING phrase need not be specified. If the names will change from one program to another, then the REPLACING phrase can be used to supply meaningful names for this program.
01 A.
02 B PIC S99.
02 C PIC S9(5)V99.
02 D PIC S9999 OCCURS 1 TO 52 TIMES
DEPENDING ON B OF A.
COPY PAYLIB.
The library text will be copied unchanged into the COBOL program, immediately after the COPY statement.
COPY PAYLIB REPLACING A BY PAYROLL
B BY PAY-CODE
C BY GROSS-PAY
D BY HOURS.
01 PAYROLL.
02 PAY-CODE PIC S99.
02 GROSS-PAY PIC S9(5)V99.
02 HOURS PIC S9999 OCCURS 1 TO 52 TIMES
DEPENDING ON PAY-CODE OF PAYROLL.
The changes shown are made only for this program. The text, as it appears in the library, remains unchanged.
01 (PRFX)-RECORD.
03 (PRFX)-NAME PIC X(24).
03 (PRFX)-PHONE PIC X(10).
03 (PRFX)-EXTN PIC X(4).
COPY CONTACT REPLACING ==(PRFX)== BY ==CUST==.
01 CUST-RECORD.
03 CUST-NAME PIC X(24).
03 CUST-PHONE PIC X(10).
03 CUST-EXTN PIC X(4).