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 a copy of our white paper and contact our team to learn more.

Download the White Paper

Please allow the essential cookies to have access to this form.

Let's Talk

Get in touch with our experts and find out how Astadia's range of tools and experience can support your team.

contact us now