copybook n : a book containing models of good penmanship; used in teaching penmanship
A copybook is the section of code in a high-level computer programming language that is copied from a master copy and inserted in several different programs (or multiple places in a single program). It is most frequently used to define the physical layout of data (either in an input or output file (file schemas), or in a temporary area (working storage)), but can also be used for sections of procedural code.
The term may have originated from use of COBOL on IBM mainframe operating systems: COPY is the COBOL keyword for this, and the master item was stored as a "book" within a larger library of source code http://e-docs.bea.com/wlintegration/v2_1/gloss/glossary.htm.
Major reasons for using COPYBOOKs are to:
- ensure that everyone uses the identical version of a data layout definition or procedural code.
- make it easier to cross reference where components are used in a system.
- make it easier to change programs when needed (only one master copy to change).
- save programmer time by not needing to code long data layouts (minor, but useful).
Since COBOL defined the COPY statement in 1959, most other languages have included a similar feature. Fortran, ALGOL, and PL/I all have this; even recent languages like C or C++, HTML, and Java have this feature.
The term "copybook" is mainly used in a COBOL or IBM mainframe context. Other languages often refer to it as an "include", because that keyword is used in their syntax: include (Fortran), %include (PL/I),
- include (C and C++),
Many languages have a replacement feature in their copybook syntax. This allows a programmer to replace certain text in the copybook with other text when copying it into the program. This makes the copybook more versatile, since it can be re-used in the same program. For example, the same copybook can be used to describe the input and output files within the same program. (See the COBOL syntax below for an example of the replacing facility.
The copybook is invoked in COBOL by the COPY statement, which has two forms:
- COPY text-name.
- COPY text-name REPLACING item-1 BY item-2.
- "BEA WebLogic Integration Glossary", Version 2.1. unsigned. BEA Systems, Inc., October 2001. http://e-docs.bea.com/wlintegration/v2_1/gloss/glossary.htm, accessed: 2006/07/06.