Copybook (programming)
Encyclopedia
A copybook is a section of code written in a high-level programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 or assembly language
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

 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
Function prototype
A function prototype in C, Perl or C++ is a declaration of a function that omits the function body but does specify the function's return type, name, arity and argument types...

.

The term "copybook" may have originated from use of COBOL
COBOL
COBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....

 on IBM
IBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...

 mainframe
Mainframe computer
Mainframes are powerful computers used primarily by corporate and governmental organizations for critical applications, bulk data processing such as census, industry and consumer statistics, enterprise resource planning, and financial transaction processing.The term originally referred to the...

 operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

s: 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 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
Header file
Some programming languages use header files. These files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers...

, often using “include” as a keyword (e.g. Fortran
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...

, ALGOL
ALGOL
ALGOL is a family of imperative computer programming languages originally developed in the mid 1950s which greatly influenced many other languages and became the de facto way algorithms were described in textbooks and academic works for almost the next 30 years...

, PL/I
PL/I
PL/I is a procedural, imperative computer programming language designed for scientific, engineering, business and systems programming applications...

, C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

 and HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....

). The term “copybook” is mainly used in an IBM mainframe
IBM mainframe
IBM mainframes are large computer systems produced by IBM from 1952 to the present. During the 1960s and 1970s, the term mainframe computer was almost synonymous with IBM products due to their marketshare...

 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
    Header file
    Some programming languages use header files. These files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers...

     ...
    (C and C++),
  • include ... (MASM
    Microsoft Macro Assembler
    The Microsoft Macro Assembler is an x86 assembler that uses the Intel syntax for Microsoft Windows. there was a version of the Microsoft Macro Assembler for 16-bit and 32-bit assembly sources, MASM, and a different one, ML64, for 64-bit sources only...

    ),
  • <!--#include ... --> (HTML SSI
    Server Side Includes
    Server Side Includes is a simple interpreted server-side scripting language used almost exclusively for the Web.The most frequent use of SSI is to include the contents of one or more files into a web page on a web server...

    ),
  • <%@ include ... %> (JSP
    JavaServer Pages
    JavaServer Pages is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types...

    ). http://e-docs.bea.com/wlintegration/v2_1/gloss/glossary.htm.


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
Haskell (programming language)
Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...

 and Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

) tend to avoid copybooks or includes, preferring modules and import/export systems for namespace
Namespace (computer science)
A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols . An identifier defined in a namespace is associated only with that namespace. The same identifier can be independently defined in multiple namespaces...

control.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK