Operating System - OpenVMS
1753428 Members
4801 Online
108793 Solutions
New Discussion юеВ

Re: Copy statement in Cobol

 
Cobol Copy
New Member

Copy statement in Cobol

Hi,
I am coding a program where I have to use the same copybook for both input and output layout.
to avoid ambiguity in variable names I have used the replacing statement .

like
COPY RAPCLODT REPLACING ==RAPCLODT== BY ==RAP-IN==.

The original copybook looks like:
01 RAPCLODT.
05 RAPCLODT-DB-AREA PIC S9(04) COMP.
05 RAPCLODT-DB-RAP PIC X(06).
05 RAPCLODT-ACCT-KEY.
.
.
.


But the replace stament is replacing only the first occurence of the literal.

it looks like

01 RAP-IN.
05 RAPCLODT-DB-AREA PIC S9(04) COMP.
05 RAPCLODT-DB-RAP PIC X(06).
05 RAPCLODT-ACCT-KEY.
.
.
.


Kindly tell me how do i solve this issue.
Reply ASAP.

Thanks in advance,
Karthikeyan.
12 REPLIES 12
Phil.Howell
Honored Contributor

Re: Copy statement in Cobol

you can now reference each like
move rapclodt-acct-key of rap-in to rapctodt-acct-key of rap-out.
or use move corresponding
Wim Van den Wyngaert
Honored Contributor

Re: Copy statement in Cobol

If there is a REPLACING phrase, the compiler changes the source text as it copies it. The compiler replaces each successfully matched occurrence of a text-matching argument in the source text by the corresponding replacement item.

The comparison operation starts with the leftmost source text text-word and the first text-matching argument. The compiler compares the entire text-matching argument to an equivalent number of consecutive source text text-words.
***
Thus it only replaces words, not strings.

Wim manual reader
Wim
Phil.Howell
Honored Contributor

Re: Copy statement in Cobol

You could also put RAPCLODOT in brackets in both the copycode and the copy statement.
COPY RAPCLODT REPLACING ==(RAPCLODT)== BY ==(RAP-IN)==.

Wim Van den Wyngaert
Honored Contributor

Re: Copy statement in Cobol

Phil,

You will have the () in your source then. You can try replacing ==(X)== by ==Y== instead.

I vaguely remember that HP3000 cobol reacted differently and that strings were replaced instead of words. But I can be wrong.

Wim without compiler.
Wim
Wim Van den Wyngaert
Honored Contributor

Re: Copy statement in Cobol

http://h71000.www7.hp.com/wizard/wiz_5132.html

The ==(X)== by ==RAP-IN== should work.

Wim
Wim
Richard Anthony
Advisor

Re: Copy statement in Cobol

The REPLACING statement is available for Structured ANS COBOL, but it is compiler-dependent and the recommendation is to avoid its use. The example you give shows you are trying to change all occurrences of a string-value in your copy-member, as the compiler places it into your program, with another string-value -- as if you expect the compiler to recognize it just as an editor (such as SPF) would. The compiler does not. Instead, it has correctly replaced the specified data-item (RAPCLODT) with the replacing data-item (RAP-IN).

I suggest you make an extra copy in your library, give it a different name, open it and use your editor's features to make a global change to the item-name; then your program will contain two COPY statements (as it does now) but both will be more straight-forward and will make future trouble-shooting and maintenance easier due to reduced confusion opportunity.

Dennis Handly
Acclaimed Contributor

Re: Copy statement in Cobol

>Wim: You can try replacing ==(X)== by ==Y== instead.

Yes, "()" is the trick you have to use. We had to ask the ANSI Committee about it decades ago.
Note: Using () would mean that copylib member can't be used without REPLACING.

>I vaguely remember that HP3000 COBOL reacted differently and that strings were replaced instead of words. But I can be wrong.

I worked on that compiler for 14 years. Our COBOLII required () since a "-" didn't separate text-words.
http://docs.hp.com/cgi-bin/doc3k/B3150090013.11820/1

>Richard: The REPLACING statement is available for Structured ANS COBOL, but it is compiler-dependent and the recommendation is to avoid its use.

REPLACE or REPLACING?
REPLACE is COBOL 85 Standard.
But REPLACE won't help in this case, the rules for COPY and REPLACE are the same.
Wim Van den Wyngaert
Honored Contributor

Re: Copy statement in Cobol

So I was wrong. Still have a 1998 MPE tape but no machine to load the tape.

Karthikeyan : pls confirm that it works.

Wim
Wim
Cobol Copy
New Member

Re: Copy statement in Cobol

yes,
looking at all the replies, i would like to have a say.
these are some of the limitations:
1. I cannot create a copy of the copybook and avoid using the replacing statement.
2. I dont have the authority to change the production copybook either from RAPCLODT to (RAPCLODT) or even ::rapclodt:: (some people suggest the second one too).

If the people who replies have a valid MVS login, try reading a QW on copy.
there are few examples there.
just giving a sample:

actual copybook: copybook1

01 A.
05 B PIC 9(1).
05 C OCCURS 1 TO 9 TIMES DEPENDING ON B PIC X(5). (SAY SOMETHING LIKE THIS).

when a copy statement was issued like:

copy copybook1 replacing a by employee
b by emp-id
c by emp-seat.

it replaces all the a's, b's and c's(note - b is there twice in the cpybook).

but in my example the replacing statement replaced only first occurence.

i do accept all your answers, but can anyone justify the qw in mvs?

or tell the author that he is wrong?

thanks,
karthikeyan.