HP OpenVMS Systemsask the wizard |
The Question is: The question : Is there any way to replace a portion of text in COBOL when using the Copy Replace By statement? Background : I am trying to use the COBOL COPY "R.LIB" REPLACING ==WS== BY ==WS-HOLD== statement in VMS COBOL Version 5 6.60. R.LIB 01 WS-TOP-LEVEL. 03 WS-FIELD1 PIC X(01) 03 WS-FIELD2 PIC X(10). ..................... 03 WS-FIELD200 PIC X(5). The replacing statement does not replace the WS with WS-HOLD. After consulting the manual it says a full text word is required. I have seen COBOL allow this on many other platforms so presume that there is a small syntactical error. The Answer is :
Without some explanation of what is going wrong, it's a bit difficult
for the OpenVMS Wizard to know what to say about this. However, there
are a number of potential problems with the posted code.
First, the file specification in the COPY statement should be enclosed
in double quotes. Next, there is a missing period at the end of the
statement.
Inside the COPY file, there is no PIC clause or period on the 03 item.
All the above are likely to cause errors in the compilation.
So, if the statement is replaced with:
COPY "R.LIB" REPLACING ==WS== BY ==WS-HOLD==.
and R.LIB with:
01 WS-TOP-LEVEL.
03 WS-FIELD1 PIC X.
(also note that the OpenVMS Wizard is assuming the formatting in terms
of area A and B is consistent with your choice of source format).
Alternatively, you could simply leave out the ".LIB" part of the file
specification:
COPY R REPLACING ==WS== BY ==WS-HOLD==.
There is no period to confuse COBOL and the compiler will assume a file
type extension of .LIB for the COPY file.
This will now give a clean compile, but the OpenVMS Wizard suspects that
it won't do what you might expect. The REPLACING clause implies that you
want to replace the substring "WS" with the substring "WS-HOLD" in each
of the items in R.LIB. As it stands, this will not occur. This is because
the COPY REPLACING is token-based, rather than string-based. In R.LIB,
the only tokens eligible for replacement are "WS-TOP-LEVEL" and
"WS-FIELD1". Since neither matches the REPLACING token "WS", there will
be no substitution.
You can resolve this by changing both the REPLACING clause and the COPY
file source so that the string you want to replace is a token. The easiest
way is using parentheses. For example, change the COPY statement to:
COPY "R.LIB" REPLACING ==(WS)== BY ==WS-HOLD==.
and R.LIB to:
01 (WS)-TOP-LEVEL.
03 (WS)-FIELD1 PIC X.
The resulting source code will be:
01 WS-HOLD-TOP-LEVEL.
03 WS-HOLD-FIELD1 PIC X.
|