Highlighted
Absent Member.
Absent Member.
1562 views

nested copy/replace issue (runtime 9)

[Migrated content. Thread originally posted on 23 August 2011]

From the ACUCOBOL-GT Reference Manual 2.4.1

1.COPY statements may be nested in other COPY libraries. Any one of the COPY statements in this structure can include the REPLACING phrase.

Depending on the scope of each statement, the REPLACING phrases might affect subsidiary COPY statements. For example, if "program-a.cbl" contains a copy/replace as follows:

COPY "program-b.cpy"
REPLACING ==genericitems== BY ==myitems==.

and "program-b.cpy" contains a nested copy/replace statement:

COPY "program-c.cpy"
REPLACING ==variabledata== BY == specificdata==.

The replace performed in "program-b.cpy" by the copy/replace statement in "program-a.cbl" will affect "program-c.cpy." If you do not want the copy/replace statement in "program-a.cbl" to cascade to "program-c.cpy", you must add the following statement to "program-b.cpy", so that the copy/replace performed in "program-b.cpy" will not be performed in "program-c.cpy."

COPY "program-c.cpy"
REPLACING ==genericitems== BY ==genericitems==.


However i can't get the following copy/replace to work

GRID.DEF

01  !PRFX!grid.
           05 !PRFX!handle          usage handle of grid.
           05 !PRFX!def             pic x(2048) value spaces.
           05 !PRFX!descr.
              08 !PRFX!x            pic 9(02)   value zeros. 
              08 !PRFX!y            pic 9(09)   value zeros. 
              08 !PRFX!x-ord        pic 9(02)   value zeros. 
              08 !PRFX!verso-ord    pic 9(01)   value zeros. 
              08 !PRFX!col-num      pic 9(02)   value zeros. 
              08 !PRFX!rec-width    pic 9(09)   value zeros. 
              08 !PRFX!row-head-num pic 9(02)   value zeros. 
              08 !PRFX!col-head-num pic 9(02)   value zeros. 
           copy "array.def" replacing leading ==05 == by ==08 ==
                                      leading ==01 == by ==05 ==.


then


PROGRAM.CBL
copy "grid.def"  replacing ==!PRFX!== by ==w-gd-==.


the content of array.def is


01  !PRFX!array.
           05 !PRFX!array-ptr   usage pointer value 0.             
           05 !PRFX!array-el-sz pic 9(04)  usage is comp-4 value 0.
           05 !PRFX!array-len   pic 9(09)  usage is comp-4 value 0.
           05 !PRFX!array-cap   pic 9(09)  usage is comp-4 value 0.


the result from running the compiler with the -Lp option is as follows:


01 W-GD-GRID.
       05 W-GD-HANDLE USAGE HANDLE OF GRID.
       05 W-GD-DEF PIC X(2048) VALUE SPACES.
       05 W-GD-DESCR.
            08 W-GD-X PIC 9(02) VALUE ZEROS.
            08 W-GD-Y PIC 9(09) VALUE ZEROS.
            08 W-GD-X-ORD PIC 9(02) VALUE ZEROS.
            08 W-GD-VERSO-ORD PIC 9(01) VALUE ZEROS.
            08 W-GD-COL-NUM PIC 9(02) VALUE ZEROS.
            08 W-GD-REC-WIDTH PIC 9(09) VALUE ZEROS.
            08 W-GD-ROW-HEAD-NUM PIC 9(02) VALUE ZEROS.
            08 W-GD-COL-HEAD-NUM PIC 9(02) VALUE ZEROS.
       05 ! PRFX ! ARRAY.
            08 ! PRFX ! ARRAY-PTR USAGE POINTER VALUE 0.
            08 ! PRFX ! ARRAY-EL-SZ PIC 9(04) USAGE IS COMP-4 VALUE 0.
            08 ! PRFX ! ARRAY-LEN PIC 9(09) USAGE IS COMP-4 VALUE 0.
            08 ! PRFX ! ARRAY-CAP PIC 9(09) USAGE IS COMP-4 VALUE 0.


from the documentation i would expect that also the nested !PRFX! would have to be replaced by "w-gd-".
If i only copy "array.def" without replacing 05 and 08 level, it correctly replace also the nested !PRFX!.

Do i am doing something wrong?
0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: nested copy/replace issue (runtime 9)

This appears to be a bug, please contact customer care.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: nested copy/replace issue (runtime 9)

Sadly, using various versions of Extend 8.xx the copy statement never worked for me (only a specific method using "leading").
Interesting, that this (only?) option in COBOL to introduce some flexibility is so poorly supported in Extend and thus probably hardly used. In a previous job involving IBM enterprise COBOL we used the copy-replacing all the time for data and code.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: nested copy/replace issue (runtime 9)

This issue - a copy \ replacing in a copy file of a copy file was (is) a documentation error. Copy relacing is supported and support copy \ replacing in a copybook, but copy \ replacing is not supported in a copy file of a copy file. Neither the Acu compiler nor the Micro Focus compiler (checker) support copy \ replacing in a copy file of a copy file.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.