[Migrated content. Thread originally posted on 23 August 2011]
From the ACUCOBOL-GT Reference Manual 2.4.11.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?
