- Copybook (programming)
-
A copybook is a section of code written in a high-level programming language or assembly language that can be copied (from a master) and inserted into several different programs (or multiple places in a single program). It is often used to define the physical layout of program data, pieces of procedural code and prototypes.
The term "copybook" 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.[1]Major reasons for using COPYBOOKs in assembly language or COBOL are to:
- ensure that everyone uses the same 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 extensive data layouts (minor, but useful).
RPG IV supports the COPYBOOK concept exactly as in COBOL; here COPYBOOKs are most commonly used to define PROTOTYPEs of RPG IV procedures.
Influence
Since COBOL defined the COPY statement in 1959, many other languages have included a similar feature, often using “include” as a keyword (e.g. Fortran, ALGOL, PL/I, C, C++ and HTML). The term “copybook” is mainly used in an IBM mainframe context; other languages have different names and syntaxes:
COPY text-name.
(COBOL),/COPY QCPYLESRC,QBC
(RPG IV – first argument is the filename, second argument is the copybook),include ...
(Fortran),%include ...
(PL/I),#include ...
(C and C++),include ...
(MASM),<!--#include ... -->
(HTML SSI),<%@ include ... %>
(JSP). [2].
Several 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.
Replacements in COBOL are invoked using the second form of the
COPY
statement:COPY text-name REPLACING item-1 BY item-2.
Modern languages (e.g. Haskell and Java) tend to avoid copybooks or includes, preferring modules and import/export systems for namespace control.
References
- "BEA WebLogic Integration Glossary", Version 2.1. unsigned. BEA Systems, Inc., October 2001. [3], accessed: 2006/07/06.
- RPGLE Copybooks
Categories:
Wikimedia Foundation. 2010.