View previous topic :: View next topic
|
Author |
Message |
Satyajit
New User
Joined: 25 Jan 2006 Posts: 27
|
|
|
|
i have a copybook say
AA014TR3
which structure is
01 A014TR-MATCH-FIX-INFO.
05 A014TR-REG-OFF PIC X(2).
88 A014TR-TEST-R VALUE '96' '98' '99'.
88 A014TR-TEST-A VALUE '96'.
88 A014TR-REGIONAL-O VALUE SPACES.
05 A014TR-N-REG REDEFINES
A014TR-REGIONAL-OFFICE PIC 9(2).
...
...
...
i want to change all prefix; A014TR- by A014PR-
So i coded
Copy AA014TR3 replacing ==AA014TR-== by ==AA014PR-==
But its not working replace is not happening. can someone suggest how to do that |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Search this forum for all terms "copy replacing" and you could find on the first page a response I made in July on a thread titled "Doubt in Replacing in Copy book" (with emphasis added):
Quote: |
From the COBOL Language Reference manual (link at the top of the page), secdtion 8.1.4.3 on COPY REPLACING rules:
Quote:
The COPY statement with REPLACING phrase can be used to replace parts of words. By inserting a dummy operand delimited by colons into the program text, the compiler will replace the dummy operand with the desired text. Example 3 shows how this is used with the dummy operand :TAG:.
The colons serve as separators and make TAG a stand-alone operand.
It is a common misconception that COPY REPLACING can replace parts of COBOL variables. This is a misconception because COBOL only allows replacement of entire words -- unless a delimiting character such as a colon is used. And COBOL considers the delimiting characters to create a word.
So the answer to your question is the only other way is to change the copy book to include the appropriate tag character around the CTL -- which could adversely affect other programs using the copy book. If you cannot change the copy book, you cannot do what you want other than as Dick suggested.
|
|
|
Back to top |
|
|
Satyajit
New User
Joined: 25 Jan 2006 Posts: 27
|
|
|
|
Yes I had gone thru this Quote but i am not clear completly. Can i use the '-' hyphen in my variables as a delimiter and replace part of the variable? if not what is the work around? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
You can only use the hyphen as a delimiter if there is one in front of and behind the part of the variable to be replaced. The structure as you've listed it cannot be used in a REPLACING COPY in COBOL. You can solve this by:
1) Putting a hyphen in front of each A014TR so the REPLACING will be able to use the hyphens as word delimiters. This would require every COPY statement referencing the copy book have the REPLACING option -- if there are existing COPY statements in programs that do not have REPLACING, they would have to be changed. The hyphen could be any desired character (such as colon) that COBOL will recognize to delimit words.
2) Create another copy book that has the desired change and COPY it instead of the existing copy book. This may cause maintenance problems in the future as someone will have to ensure changes in one copy book are made in the other at the same time.
3) Change the characters outside of COBOL. For example, you could write a step to copy the copy book to a temporary file, write a step to use REXX to change the desired values in the temporary file, then use the temporary file as SYSLIB to the COBOL compile. |
|
Back to top |
|
|
Satyajit
New User
Joined: 25 Jan 2006 Posts: 27
|
|
|
|
Could you please explain me the point 1 as an example? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
I stand corrected. The hyphen won't work -- but colons will. The copy book looks like
Code: |
01 :A014TR:MATCH-FIX-INFO.
05 :A014TR:REG-OFF PIC X(2).
88 :A014TR:TEST-R VALUE '96' '98' '99'.
88 :A014TR:TEST-A VALUE '96'.
88 :A014TR:REGIONAL-O VALUE SPACES.
05 :A014TR:N-REG REDEFINES :A014TR:REG-OFF
PIC 9(2). |
will allow execution of
Code: |
Copy AA014TR3 replacing ==:AA014TR:== by ==AA014PR-== |
as shown in this compiler output:
Code: |
COPY AA014TR3
REPLACING ==:A014TR:==
BY ==A014PR-==.
01 A014PR-MATCH-FIX-INFO.
05 A014PR-REG-OFF PIC X(2).
88 A014PR-TEST-R VALUE '96' '98' '99'.
88 A014PR-TEST-A VALUE '96'.
88 A014PR-REGIONAL-O VALUE SPACES.
05 A014PR-N-REG REDEFINES A014PR-REG-OFF
PIC 9(2). |
|
|
Back to top |
|
|
|