Copy Statement in COBOL
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Application Programming

#1: Copy Statement in COBOL Author: haqshaik PostPosted: Thu Jun 01, 2006 10:30 am
    —
Hi All.

I am using COPY statement with replacing option in the working storage.
While I complie, the replace statement is not working. if i simply say copy the copy book is getting expanded properly in the complialtion listing.

Here is my copy statement.

I have tried the following three variations
Variaition1: COPY FNLREQCP REPLACING "CPY" BY "INP"
Varaition2: COPY FNLREQCP REPLACING 'CPY' BY 'INP'
Third varaition is using the pseudo text.
Variation3:COPY FNLREQCP REPLACING ==CPY== BY ==INP==

I am pasting down the copy book for reference.

01 CPY-ADDRESS-REQ-DATA.

05 CPY-ADDRESS-REQ.
10 CPY-ADDRESS-LINE1 PIC X(30).
10 CPY-ADDRESS-LINE2 PIC X(30).
10 CPY-CITY-ST-LINE PIC X(17).
10 CPY-ZIP-CD PIC X(05).
10 CPY-ZIP-EXT PIC X(04).

I have searched throuh the forum and found good info about copy statement. But I could not resolve what the problem is.
Do we need to specify some compiler option for the replace to be effective?
Am I missing something here? Please guide me.

Thanks,
Salauddin

#2:  Author: kolusuLocation: San Jose PostPosted: Thu Jun 01, 2006 11:25 am
    —
haqshaik,

The COPY statement with REPLACING phrase can be used to replace parts of words only by inserting a dummy operand delimited by colons into the variable names.

if your copy book was follows

Code:

01 :CPY:-ADDRESS-REQ-DATA.             
   05 :CPY:-ADDRESS-REQ.               
      10 :CPY:-ADDRESS-LINE1 PIC X(30).
      10 :CPY:-ADDRESS-LINE2 PIC X(30).
      10 :CPY:-CITY-ST-LINE PIC X(17). 
      10 :CPY:-ZIP-CD      PIC X(05).   
      10 :CPY:-ZIP-EXT     PIC X(04).   


Then you can use
Code:

COPY cpybookname REPLACING ==:CPY:== BY ==INP==.

which will translate the copybook to

Code:

01  INP-ADDRESS-REQ-DATA.             
    05 INP-ADDRESS-REQ.                 
       10 INP-ADDRESS-LINE1 PIC X(30). 
       10 INP-ADDRESS-LINE2 PIC X(30). 
       10 INP-CITY-ST-LINE  PIC X(17).   
       10 INP-ZIP-CD        PIC X(05).   
       10 INP-ZIP-EXT       PIC X(04).   
                                       


Hope this helps...

Cheers

Kolusu

#3:  Author: haqshaik PostPosted: Thu Jun 01, 2006 1:06 pm
    —
Thanks Kolusu,
its working now. Thanks for your help.

Thanks,
Salauddin

#4:  Author: neilxt PostPosted: Tue Sep 19, 2006 3:54 pm
    —
kolusu wrote:
haqshaik,

The COPY statement with REPLACING phrase can be used to replace parts of words only by inserting a dummy operand delimited by colons into the variable names.


This works however the statement is not exactly true as stated. For clarity the COPY REPLACING statement only replaces words. In order to make it work as required you have to trick the compiler into seeing a word (or words) in the REPLACING field and have the BY field replace it in such a way as to remove the delimiter that broke the field name into two.

Surrounding the replaceable part with colons is a good way, but any special character at the end of the replaceable part will work.

e.g.
Code:
COPY MYREC REPLACING ==PREFIX@== BY ==ABC==


Code:

01 PREFIX@-MYFIELD PIC XXX.

Becomes

Code:

01 ABC-MYFIELD PIC XXX.


N.



MVSFORUMS.com -> Application Programming


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group