Copy Book Prefix


Is there a way I can add prefix to a record and it's correspondent items when I copy the copybook into the working storage section ?

Best Regards

  • Verified Answer

    You can use copy with the replacing phrase to specify a prefix to use but your copybook must already be setup with a generic prefix that can be replaced.

    There are two ways that you can do this depending on which dialect you are using in your compilation:

    Ansi 85 and MF Dialect:

    Source-file Code:

        copy Payroll
             replacing ==(TAG)== by ==Payroll==.

    Copy-file Code:

    01  (TAG).
        05 (TAG)-Week      pic s99.
        05 (TAG)-Gross-Pay pic s9(5)v99.
        05 (TAG)-Hours     pic s9(3)
                             occurs 1 to 52 times
                              depending on (TAG)-Week of (TAG).
    Is treated as if it were coded as:

    01  Payroll.
        05 Payroll-Week      pic s99.
        05 Payroll-Gross-Pay pic s9(5)v99.
        05 Payroll-Hours     pic s9(3)
                               occurs 1 to 52 times
                                 depending on Payroll-Week of Payroll.

    Example Using ISO 2002 and Micro Focus Dialects

    Both the ISO 2002 and the Micro Focus dialects support partial word replacement as specified in the ISO 2002 COBOL standard. As above, the modifiable sections must be pre-established, however, the use of special characters is not required and the copy members will compile cleanly even when no replacement is done to them.

    The above example could equivalently be coded as follows:

        copy Payroll
             replacing leading ==TAG== by ==Payroll==.

    Copy-file Code:

    01  TAG.
        05 TAG-Week      pic s99.
        05 TAG-Gross-Pay pic s9(5)v99.
        05 TAG-Hours     pic s9(3)
                             occurs 1 to 52 times
                              depending on TAG-Week of TAG.
    Is treated exactly as the code is treated in the ANSI'85 example.