Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Question related to COPY with REPLACING

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
cybertaurean

New User


Joined: 22 Dec 2008
Posts: 85
Location: US

PostPosted: Tue Jun 19, 2012 6:45 pm    Post subject: Question related to COPY with REPLACING
Reply with quote

Hi,

I have a copybook C1 with (pre)- tags. need to include it within another copybook C2 by replacing the -(pre) tag -

Code:
C2
   copy C1 replacing -(pre)- with some arbitrary value


however, copy doesn't allow this. what can be done in this case?

Regards,
CT
Back to top
View user's profile Send private message

Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Tue Jun 19, 2012 6:56 pm    Post subject:
Reply with quote

Cut/paste the C1 in C2 after replacing (pre) with value-of-your-choice?

PS. Only if I understood correctly.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jun 19, 2012 7:07 pm    Post subject:
Reply with quote

Quote:
however, copy doesn't allow this. what can be done in this case?


would you be so kind as to post the errors that you received during compilation?
Back to top
View user's profile Send private message
cybertaurean

New User


Joined: 22 Dec 2008
Posts: 85
Location: US

PostPosted: Tue Jun 19, 2012 7:17 pm    Post subject: Re: Question related to COPY with REPLACING
Reply with quote

@ Anuj Dhawan

I am supposed to use that copybook as such instead of copypasting.

@dbzTHEdinosauer

The usage of REPLACING WITH inside a copybook gives the below error

A "COPY" statement with "REPLACING" phrase was found within a nested "COPY".The "COPY" statement was discarded
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jun 19, 2012 7:26 pm    Post subject:
Reply with quote

cybertaurean,

sorry, you are correct.

what is the construct of C1 and C2?

can not the C2 be COPYied outside of C1?

if not, you have a design generated by someone unfamiliar with COBOL
or at least forgetful (as I was) of the fact that you can not nest with replacing.
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1529
Location: Andromeda Galaxy

PostPosted: Tue Jun 19, 2012 7:28 pm    Post subject:
Reply with quote

If I understand your requirement corrently why not try this


Code:
01 MAIN-LEVEL.
COPY C1   REPLACING ==(PRE)== BY ==ARBITARY VALUE==.
COPY C2   REPLACING ==(PRE)== BY ==ARBITARY VALUE==.
Back to top
View user's profile Send private message
cybertaurean

New User


Joined: 22 Dec 2008
Posts: 85
Location: US

PostPosted: Tue Jun 19, 2012 7:33 pm    Post subject:
Reply with quote

C1 is actually a common layout that has to be used between a couple of programs...

in one of the program the layout has an occurance of 2500 times

C2 copybook has other variables plus the common layout (occurance 2500 times)

is there any way to solve this either using redefines or any such commands other than copypasting the layout and changing (PRE)
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jun 19, 2012 7:52 pm    Post subject:
Reply with quote

without seeing the copybooks, it is difficult to provide you with an answer
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Tue Jun 19, 2012 7:58 pm    Post subject:
Reply with quote

What you want to do cannot be done, period. The Enterprise COBOL Programming Guide manual:
Quote:
APPENDIX1.5.4.1 Processing of LIBEXIT with nested COPY statements

Any record from the active copybook can contain a COPY statement. (However, nested COPY statements cannot contain the REPLACING phrase, and a COPY statement with the REPLACING phrase cannot contain nested COPY statements.)

Copy sstatements can be nested arbitrarily as per the same document:
Quote:
8.2.1 Eliminating repetitive coding

Use the COPY statement in any program division and at any code sequence level to include stored source statements in a program. You can nest COPY statements to any depth.
but not if you are using REPLACING.
Back to top
View user's profile Send private message
cybertaurean

New User


Joined: 22 Dec 2008
Posts: 85
Location: US

PostPosted: Tue Jun 19, 2012 8:28 pm    Post subject:
Reply with quote

Thank you for all your help

have modified the design using level variables

Code:

01 MAIN-LEVEL.
COPY C1   REPLACING ==(PRE)== BY ==ARBITARY VALUE==.
05 MAIN-LEVEL2     occurs 2500 times
COPY C2   REPLACING ==(PRE)== BY ==ARBITARY VALUE==.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Tue Jun 19, 2012 8:35 pm    Post subject: Reply to: Question related to COPY with REPLACING
Reply with quote

I tried a few things, this is the only one that worked for me (Using IBM Enterprise COBOL for z/OS 3.4.1)

This is COPY XXXTEMP1:
Code:
           03  :YY:TEMP1-1           PIC X(28).           
           03  :YY:TEMP1-2           PIC X(5).           
           03  :YY:TEMP1-3           PIC X(10).           
           03  :YY:TEMP1-4           PIC S9(4)    COMP-3.


This is COPY XXXTEMP2:
Code:
       01  :XX:TEMP2-DATA.                               
           03  :XX:TEMP2-1           PIC X(15).           
           03  :XX:TEMP2-3           PIC X(2).         
           COPY XXXTEMP1.                               
           03  :XX:TEMP2-4           PIC S9(8)    COMP-3.


And this is the COBOL program:
Code:
           REPLACE ==:XX:== BY ==T2-== 
                   ==:YY:== BY ==T1-==.
                                       
           COPY XXXTEMP2. 
             
           REPLACE OFF.


Compilation went smoothly:
Code:
000028                    REPLACE ==:XX:== BY ==T2-==                   
000029                            ==:YY:== BY ==T1-==.                   
000030                                                                   
000031                    COPY XXXTEMP2.                                 
000032C               01  T2-TEMP2-DATA.                                 
000033C                   03  T2-TEMP2-1           PIC X(15).           
000034C                   03  T2-TEMP2-3           PIC X(2).             
000035C                   COPY XXXTEMP1.                                 
000036C                   03  T1-TEMP1-1           PIC X(28).           
000037C                   03  T1-TEMP1-2           PIC X(5).             
000038C                   03  T1-TEMP1-3           PIC X(10).           
000039C                   03  T1-TEMP1-4           PIC S9(4)    COMP-3. 
000040C                   03  T2-TEMP2-4           PIC S9(8)    COMP-3. 
000041                               
000042                    REPLACE OFF.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jun 19, 2012 8:40 pm    Post subject:
Reply with quote

thx Marso,
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 641
Location: Whitby, ON, Canada

PostPosted: Wed Jun 20, 2012 12:22 am    Post subject:
Reply with quote

FWIW, I prefer to use the REPLACE statement rather than COPY...REPLACING. It seems to work more intuitively for me.
Back to top
View user's profile Send private message
cybertaurean

New User


Joined: 22 Dec 2008
Posts: 85
Location: US

PostPosted: Wed Jun 20, 2012 7:07 pm    Post subject:
Reply with quote

Tried REPLACE also but still giving compilation error
The "REPLACE" statement was invalid.
The "COPY" statement was invalid. Expected "REPLACING", but found "REPLACE". The statement was discarded.

I am using IBM Enterprise COBOL for z/OS 4.2.0
maybe REPLACE with COPY is not allowed in this version.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 20, 2012 7:39 pm    Post subject:
Reply with quote

you are wasting the time of everyone.

you were provided with a scenario of REPLACE .. and REPLACE OFF
which works with every COBOL on the planet.

cut and paste your code and compiler messages,
we will provide the corrective code to your garbage.

actually, you should think about another career that does not involve accuracy, precision, attention to detail, etc....
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Jun 20, 2012 9:17 pm    Post subject:
Reply with quote

Hello,

Quote:
Tried REPLACE also but still giving compilation error
The "REPLACE" statement was invalid.
The "COPY" statement was invalid. Expected "REPLACING", but found "REPLACE". The statement was discarded.
When you use REPLACE, it is Not part of the COPY statement.

Suggest you look in the COBOL Language manual available via the "IBM Manuals" link at the top of the page
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1715
Location: UK

PostPosted: Wed Jun 20, 2012 10:47 pm    Post subject:
Reply with quote

Or even just READ the example posted by Marso.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts syncsort: copy lines after the keyword shreya19 SYNCSORT 7 Fri Dec 02, 2016 9:47 am
No new posts Single COPY CICS TS datasets and when... Kyle Carroll CICS 2 Tue Oct 11, 2016 9:47 pm
No new posts Fault Analyzer - listings question. egrove IBM Tools 4 Thu Aug 11, 2016 5:31 pm
No new posts dataset copy question - REPRO or some... atulxp TSO/ISPF 2 Wed Aug 03, 2016 10:56 pm
No new posts How to copy Tape dataset to unix main... chaky All Other Mainframe Topics 4 Fri Jul 08, 2016 2:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us