Skip to content

Copybook Expansion

Dave Nicolette edited this page Jan 30, 2021 · 18 revisions

Home -> Developer Guide -> Implementation Notes ->

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.

Cobol Check supports copybook expansion, including nested copybooks and the REPLACING option, as of January, 2021.

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 will actually occur, 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 compiler such as, for instance, GnuCOBOL, does not support this, and compilation of the test program will fail.

Current IBM documentation for enterprise Cobol states nested COPY REPLACING is not supported, but we have seen this in the field in older applications, so it may yet be a factor for supporting existing applications.

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 
application.copybook.directory = path-to-the-application's-copybooks

By default, cobol-check will assume:

copybook.expansion = false 

Pseudo-text replacement is supported

Reference: IBM: COPY REPLACING with pseudo-text

Clone this wiki locally