IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Question related to COPY with REPLACING


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
cybertaurean

New User


Joined: 22 Dec 2008
Posts: 87
Location: US

PostPosted: Tue Jun 19, 2012 6:45 pm
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

Superior Member


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

PostPosted: Tue Jun 19, 2012 6:56 pm
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
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: 87
Location: US

PostPosted: Tue Jun 19, 2012 7:17 pm
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
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

Global Moderator


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

PostPosted: Tue Jun 19, 2012 7:28 pm
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: 87
Location: US

PostPosted: Tue Jun 19, 2012 7:33 pm
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jun 19, 2012 7:58 pm
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: 87
Location: US

PostPosted: Tue Jun 19, 2012 8:28 pm
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: 1353
Location: Israel

PostPosted: Tue Jun 19, 2012 8:35 pm
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
Reply with quote

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

Active Member


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

PostPosted: Wed Jun 20, 2012 12:22 am
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: 87
Location: US

PostPosted: Wed Jun 20, 2012 7:07 pm
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
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

Moderator Emeritus


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

PostPosted: Wed Jun 20, 2012 9:17 pm
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: 2455
Location: Hampshire, UK

PostPosted: Wed Jun 20, 2012 10:47 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts VB to VB copy - Full length reached SYNCSORT 8
No new posts Question for file manager IBM Tools 7
No new posts Need COBOL COPY Help in MVS Environment COBOL Programming 4
No new posts Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
No new posts DB2 Table - Image copy unload IBM Tools 2
Search our Forums:

Back to Top