-
Notifications
You must be signed in to change notification settings - Fork 29
Copybook Expansion
Home -> User Guide -> General User 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.
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.
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.
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. The default behavior of cobol-check is not to expand copybooks.
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)
If the application under tests replaces full words in copybooks, the configuration settings above will suffice. If the application replaces pseudo-text, then you will need to tell cobol-check how to recognize the pseudo text:
copy.replacing.patterns = ==X==, ::X::
The sample values reflect this sort of code in the application under test (sample code borrowed from the IBM documentation).
Library code:
01 AA-DATA.
10 AA-ID PIC X(9).
10 AA-TYPE PIC X(1).
COPY statement:
COPY TEXTA REPLACING ==01 AA-DATA== BY ==05 EE-DATA==.
==AA-ID== BY ==EE-ID==.
==AA-TYPE== BY ==EE-TYPE==.
Result:
05 EE-DATA.
10 EE-ID PIC X(9).
10 EE-TYPE PIC X(1).
Reference: IBM: COPY REPLACING with pseudo-text