The copybook:
is an individual file
contains only DATA DIVISION or FILE SECTION structures
does not contain PROCEDURE DIVISION code
can be inserted into multiple programs
will merge into the program upon compiling
is used in 90% of bank systems
Types:
record layout (VSAM record structure)
file definition (FD + SELECT + record layout)
communication (CALL USING parameter structure)
constant/parameter (constants, arrays, codes)
DB2 (EXEC SQL INCLUDE..., DB2 table field definitions)
A copybook does not contain a whole program, only the lines which should be re-used and inserted in place of the COPYBOOK instruction line.
A copybook is usually a PDS where the members contain the code parts to be inserted. The last qualifier in the name of a copybook PDS:
COPY (widely used)
CPY
COPYBOOK (mostly in educational materials)
INC (DB2 copybook)
COPYLIB (if organized into a library)
A copybook is used by the JCL with which compiling of the code happens. The definition is written into DD statements, and the particular DD statement name defines the name with which the mathing COPY statement(s) in the source code work(s).
In case an array element definition would come from a copybook, in the copybook the record structure must be defined but without the head of the record. The reason is that the line with record head contains the OCCURS clause.
The level-88 definitions are valid as well.
EXAMPLE FOR DEFINITION AND INSERTING COPYBOOK:
In case inserting a copybook cause naming duplication, compiler error is raised.
It is possible to change in dynamic fashion:
field names
constants
structures
EXAMPLE FOR COPY REPLACING:
With this technique an original copybook is usable multiple times:
in different programs
in the same program
EXAMPLE FOR RE-USING COPYBOOK:
EXAMPLE FOR CUSTOMER MASTER DATA COPYBOOK (CUST-MASTER):
EXAMPLE FOR ACCOUNT DATA COPYBOOK (ACCOUNT-DETAIL):
EXAMPLE FOR TRANSACTION LOG COPYBOOK (TRAN-LOG):
EXAMPLE FOR CALLING SUBROUTINE WITH STRUCTURE FROM COPYBOOK:
EXAMPLE FOR FILE STRUCTURE FROM COPYBOOK: