Page 1 of 1

Replacing multiple strings in a single COPY statement

PostPosted: Wed Feb 15, 2012 4:58 pm
by kerembenli76
Hi,

is it possible to convert 2 different strings within a single COPY statement?
For example, the following is not working.. Is there any other way you know?

COPY MYSAMPLECOPY REPLACING
==X== BY ==Y==
==W== BY ==Z==.

.

Re: Replacing multiple strings in a single COPY statement

PostPosted: Wed Feb 15, 2012 5:18 pm
by BillyBoyo
Can you show the actual COPY statement and the source copybook? What you have shown should generally work, although your copybook name is long. Are you using a Mainframe? What library system is it using?

Re: Replacing multiple strings in a single COPY statement

PostPosted: Wed Feb 15, 2012 6:09 pm
by Robert Sample
If you check the Enterprise COBOL Language Reference manual, the syntax diagram for the COPY statement indicates multiple REPLACING phrases are allowed. So it is possible to use the statement you provided. However, telling us that something is not working is useless. Do you mean:

1. The COPY statement did not include the library code?
2. The COPY statement included the library code but did not do the first replacement?
3. The COPY statement included the library code but did not do the second replacement?
4. The COPY statement included the library code but neither replacement was done?
5. Something else you didn't bother to explain?

Be aware, too, that COPY statements do NOT work like most new COBOL programmers think. In your COPY statement, X and W must be variable names or otherwise be delimited by spaces; your COPY statement will not -- EVER -- change WS-XVARIABLE to WS-YVARIABLE since COBOL COPY statements do not work on strings. You could put in your copybook WS-:X:VARIABLE and your COPY statement could change :X: to Y but without the delimiters around it, X will not be changed inside a variable name.

Re: Replacing multiple strings in a single COPY statement

PostPosted: Wed Feb 15, 2012 6:54 pm
by kerembenli76
Thanks for quick replies..

Robert Sample wrote:Be aware, too, that COPY statements do NOT work like most new COBOL programmers think. In your COPY statement, X and W must be variable names or otherwise be delimited by spaces; your COPY statement will not -- EVER -- change WS-XVARIABLE to WS-YVARIABLE since COBOL COPY statements do not work on strings. You could put in your copybook WS-:X:VARIABLE and your COPY statement could change :X: to Y but without the delimiters around it, X will not be changed inside a variable name.


Yes this is the point i missed... The problem is not related with the syntax of COPY command.

I didn't mention in my example, but both X and W are a part of the variables in the copybook.
When i wrote the full variable name, it worked.

Thanks again for your great help.

Re: Replacing multiple strings in a single COPY statement

PostPosted: Wed Feb 15, 2012 7:02 pm
by Robert Sample
Glad to hear its resolved.