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
 

 

Replacing function in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Replacing function in cobol
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: 7929
Location: Bellevue, IA

PostPosted: Thu Oct 08, 2009 6:47 pm    Post subject:
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    Post subject:
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: 7929
Location: Bellevue, IA

PostPosted: Thu Oct 08, 2009 7:17 pm    Post subject:
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    Post subject:
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: 7929
Location: Bellevue, IA

PostPosted: Thu Oct 08, 2009 8:37 pm    Post subject:
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    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 Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am


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