Replacing multiple strings in a single COPY statement



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Replacing multiple strings in a single COPY statement

Postby kerembenli76 » Wed Feb 15, 2012 4:58 pm

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==.

.
kerembenli76
 
Posts: 5
Joined: Mon Jan 30, 2012 9:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Replacing multiple strings in a single COPY statement

Postby BillyBoyo » Wed Feb 15, 2012 5:18 pm

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?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Replacing multiple strings in a single COPY statement

Postby Robert Sample » Wed Feb 15, 2012 6:09 pm

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Replacing multiple strings in a single COPY statement

Postby kerembenli76 » Wed Feb 15, 2012 6:54 pm

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.
kerembenli76
 
Posts: 5
Joined: Mon Jan 30, 2012 9:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Replacing multiple strings in a single COPY statement

Postby Robert Sample » Wed Feb 15, 2012 7:02 pm

Glad to hear its resolved.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post