Copybook

From Wikipedia, the free encyclopedia

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 [1].

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++), < !--#include (HTML SSI), <jsp:include> (JSP), import (Java). [2].

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.

[edit] COBOL Syntax

The copybook is invoked in COBOL by the COPY statement, which has two forms:

  1. COPY text-name.
  2. COPY text-name REPLACING item-1 BY item-2.

[edit] References

  • "BEA WebLogic Integration Glossary", Version 2.1. unsigned. BEA Systems, Inc., October 2001. [3], accessed: 2006/07/06.