HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy statement in Cobol

 
Cobol Copy
Occasional Visitor

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

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.

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
Occasional Visitor

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.




Wim Van den Wyngaert
Honored Contributor

Re: Copy statement in Cobol

He's correct. All IDENTIFIERS are replaced. Not all STRINGS.

If you can't change the rapclodt copymember you will not be able to solve this case.
And if you do change it, you will need to add "replacing ==(X)== by ==RAPCLODT==" where there is no replacing clause.

Wim
Wim
Phil.Howell
Honored Contributor

Re: Copy statement in Cobol

MVS is another country
they do thing differently there

The compiler will tell you about any ambiguity in variable names

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

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

MOVE RAPCLODT-ACCT-KEY TO .
will be flagged by the compiler as an error

MOVE RAPCLODT-ACCT-KEY OF RAP-IN
TO RAPCLODT-ACCT-KEY OF RAP-OUT.
will work

Phil

Cobol Copy
Occasional Visitor

Re: Copy statement in Cobol

thanks phil.. ur reply was useful.

karthikeyan