COBOL COPY Statements

If you’ve ever used COBOL, chances are high you are familiar with the COPY statement. It allows developers to write chunks of reusable code in a separate file, called a copybook. Such a copybook typically contains common data structures (a data copybook) or shared code for e.g. error handling (a code copybook), but in theory it can contain nearly anything you wish to reuse in multiple COBOL programs.

To include such a copybook in your main program, you use the COPY statement. This statement will simply place the prewritten source code in the compilation unit at compile time. The ‘compile time’ phrase is an important detail here as it means the COPY statement is a preprocessing statement altering the original source file by replacing the entire COPY statement with the contents of the copybook, so that the compiled program no longer contains the reference to the copybook, but instead contains the entire contents from that copybook.

In addition, a REPLACING clause can be specified with the COPY statement. This clause can be used to replace all occurrences of a specified text by the new associated text.

White Paper Overview
  • Comparison With OO Languages
  • Compile Time vs Runtime Expansion
  • Tokenization vs String Manipulation
  • Multiple Replacing Clauses
  • The CodeTurn Solution: Simplicity, Flexibility and Maintainability
Get the full white paper using the form below.
Request White Paper

Please fill in this form to request a PDF download for this White Paper.

Thank you! Your request has been received!
Oops! Something went wrong while submitting the form.