Skip to content

Copybook Expansion

Dave Nicolette edited this page Dec 14, 2020 · 18 revisions

Home -> Development Guide -> General Development Guide

Copybook expansion is a task for compilers. The proof of concept performs no copybook expansion. Experience with the proof of concept project suggests there are two practical reasons to enable copybook expansion in cobol-check.

Mock support

Production Cobol code typically contains many COPY statements. Programmers use copybooks to describe data layouts in the Data Division and to achieve a degree of source-level code reuse in the Procedure Division. Cobol-check operates on the source code before it is compiled, when COPY statements have not yet been expanded.

Cobol-check implements mocks by commenting out selected source code lines and optionally replacing them with Cobol statements to implement mock behavior. In some cases, cobol-check may need to comment-out statements that are not visible prior to compilation, as they reside in copybooks.

Nested COPY REPLACING

In standard Cobol, nested COPY statements with the REPLACING option are not supported because there is a possibility of infinite recursion, depending on exactly what values end up in the final version of the copied code. IBM supports nested COPY REPLACING statements, because they have implemented an algorithm to determine whether infinite recursion actually occurred, or to err on the side of caution when the algorithm cannot make that determination definitively.

This functionality does not exist in compilers for other platforms. As cobol-check is meant to enable Cobol development on other platforms, targeting the zOS platform, we have to support nested COPY REPLACING statements. A compile such as, for instance, GnuCOBOL, does not support this, and compilation of the test program will fail.

Optional copybook expansion

In many cases, the code under test will not use nested COPY REPLACING statements or contain COPY code that affects cobol-check mocks. Therefore, we don't want to expand copybooks all the time.

When copybook expansion is needed, users can specify the following configuration settings:

copybook.expansion = true 
copybook.library = full-path-to-the-application's-copybooks

By default, cobol-check will assume:

copybook.expansion = false 
copybook.library = (not used)
Clone this wiki locally