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

Replacing function in cobol


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

New User


Joined: 25 Jan 2006
Posts: 27

PostPosted: Thu Oct 08, 2009 6:33 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Oct 08, 2009 6:47 pm
Reply with quote

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
View user's profile Send private message
Satyajit

New User


Joined: 25 Jan 2006
Posts: 27

PostPosted: Thu Oct 08, 2009 7:03 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Oct 08, 2009 7:17 pm
Reply with quote

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
View user's profile Send private message
Satyajit

New User


Joined: 25 Jan 2006
Posts: 27

PostPosted: Thu Oct 08, 2009 8:22 pm
Reply with quote

Could you please explain me the point 1 as an example?
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: Thu Oct 08, 2009 8:37 pm
Reply with quote

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
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 Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top