View previous topic :: View next topic |
Author |
Message |
haqshaik Beginner
Joined: 11 May 2005 Posts: 49 Topics: 19
|
Posted: Thu Jun 01, 2006 10:30 am Post subject: Copy Statement in COBOL |
|
|
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 |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Thu Jun 01, 2006 11:25 am Post subject: |
|
|
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 _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
haqshaik Beginner
Joined: 11 May 2005 Posts: 49 Topics: 19
|
Posted: Thu Jun 01, 2006 1:06 pm Post subject: |
|
|
Thanks Kolusu,
its working now. Thanks for your help.
Thanks,
Salauddin |
|
Back to top |
|
 |
neilxt Beginner
Joined: 01 Mar 2004 Posts: 23 Topics: 1
|
Posted: Tue Sep 19, 2006 3:54 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
|
|