View previous topic :: View next topic
|
Author |
Message |
cybertaurean
New User
Joined: 22 Dec 2008 Posts: 87 Location: US
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Cut/paste the C1 in C2 after replacing (pre) with value-of-your-choice?
PS. Only if I understood correctly. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
cybertaurean
New User
Joined: 22 Dec 2008 Posts: 87 Location: US
|
|
|
|
@ 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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
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 |
|
|
cybertaurean
New User
Joined: 22 Dec 2008 Posts: 87 Location: US
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
without seeing the copybooks, it is difficult to provide you with an answer |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
cybertaurean
New User
Joined: 22 Dec 2008 Posts: 87 Location: US
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
thx Marso, |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
FWIW, I prefer to use the REPLACE statement rather than COPY...REPLACING. It seems to work more intuitively for me. |
|
Back to top |
|
|
cybertaurean
New User
Joined: 22 Dec 2008 Posts: 87 Location: US
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
Or even just READ the example posted by Marso. |
|
Back to top |
|
|
|