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
 

 

Find ane replace string in all the members of a pds
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Fri Jun 18, 2010 2:09 pm    Post subject: Find ane replace string in all the members of a pds
Reply with quote

Hi,

I got a requirement as below

I need to change(comment the line with comp-3 and add a line with comp-5) all the strings 'PIC S9(3) COMP-3' with 'PIC S9(4) COMP-5'

but this may not present in the same column.The value may present in different columns as below.

01 J PIC S9(3) COMP-3 VALUE ZEROS.
01 C PIC S9(3)COMP-3 VALUE ZEROS.
01 I-GR PIC S9(3) COMP-3 VALUE ZEROS.
01 I-HJ PIC S9(3) COMP-3 VALUE ZEROS.
01 X-T2 PIC S9(3) COMP-3 VALUE ZEROS.
01 kk PIC S9(6) COMP-3 VALUE ZEROS.


How to acheive this in an easiest way?
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Fri Jun 18, 2010 2:23 pm    Post subject:
Reply with quote

I think that I would probably start with a search of the forum as this has been asked and answered quite a few times.

Quote:
How to acheive this in an easiest way?
That is all relative as I would go for a REXX/ISPF solution where someone else might consider a COBOL solution the easiest.

As you have posted in the REXX forum, what is your experience of REXX, are you a novice or accomplished, or expert.
Back to top
View user's profile Send private message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Fri Jun 18, 2010 2:35 pm    Post subject:
Reply with quote

Hi,

I have developed few REXX tools. Could you please provide me the link in the forum where it's already discussed. So that I can get an idea to develop this tool.
Back to top
View user's profile Send private message
superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Fri Jun 18, 2010 2:56 pm    Post subject: Reply to: Find ane replace string in all the members of a pd
Reply with quote

Here's a few:

http://www.ibmmainframes.com/viewtopic.php?=46562
http://www.ibmmainframes.com/viewtopic.php?t=32315
http://www.ibmmainframes.com/viewtopic.php?t=32107
http://www.ibmmainframes.com/viewtopic.php?t=31958
http://www.ibmmainframes.com/viewtopic.php?t=31907
http://www.ibmmainframes.com/viewtopic.php?=13695
http://www.ibmmainframes.com/viewtopic.php?=13275
http://www.ibmmainframes.com/viewtopic.php?t=43241
Back to top
View user's profile Send private message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Fri Jun 18, 2010 6:47 pm    Post subject:
Reply with quote

Hi Kevin,

Please find below the source code i have developed in rexx for thie requirement.

Code:
/* REXX */                                                       
                                                                 
SAY 'ENTER THE PDS NAME : '                                     
PULL SRCPDS                                                     
                                                                 
SRCPDS = STRIP(SRCPDS)                                           
TRGTPDS = SRCPDS                                                 
                                                                 
SAY 'ENTER THE ORIGINAL STRING: '                               
PULL SRCSTRNG                                                   
SAY 'ENTER THE REPLACEMENT STRING: '                             
PULL TRGSTRNG                                                   
                                                                 
IF SYSDSN("'"SRCPDS"'") /= "OK" THEN                             
DO                                                               
  SAY "UNABLE TO FIND DATASET '"SRCPDS"'. PLEASE VERIFY."       
  EXIT                                                           
END                                                             
X = OUTTRAP("MEMLST.")                     
"LISTDS '"SRCPDS"' MEMBERS"               
X = OUTTRAP("OFF")                         
SHOWLIST = 0                               
DO I = 1 TO MEMLST.0                       
  IF MEMLST.I = "--MEMBERS--" THEN         
  DO                                       
    I = I + 1                             
    LEAVE                                 
  END                                     
END                                       
                                           
CHANGED = 0                               
SKIPED = 0                                 
DO INDX = I TO MEMLST.0                   
  MEMBER = STRIP(MEMLST.INDX)             
  INPUTDAT = SRCPDS"("MEMBER")"           
  INP. = ""                               
  OUT. = ""                               
"ALLOC DA('"INPUTDAT"') F(INPF) SHR REU"                       
"EXECIO * DISKR INPF (STEM INP. FINIS"                         
"FREE F(INPF)"                                                 
                                                               
TRACE ?IR                                                     
STRFLAG = 0                                                   
DO I = 1 TO INP.0                                             
                                                               
  SRCPOS = 1                                                   
  DO WHILE SRCPOS > 0                                         
    SRCPOS = POS(SRCSTRNG,INP.I,SRCPOS)                       
    IF SRCPOS > 0 THEN                                         
    DO                                                         
      SAY "INP.I:" INP.I                                       
      INP.I = DELSTR(INP.I, SRCPOS, LENGTH(SRCSTRNG))         
      INP.I = INSERT(TRGSTRNG, INP.I, SRCPOS-1)               
      STRFLAG = 1                                             
      SRCPOS = SRCPOS + LENGTH(TRGSTRNG)                       
    END                                                       
    END                                                     
  END                                                       
                                                           
  IF STRFLAG = 1 THEN                                       
  DO                                                       
    OUTPUTDAT = TRGTPDS"("MEMBER")"                         
    "ALLOC DA('"OUTPUTDAT"') F(OUTF) SHR REU"               
    "EXECIO * DISKW OUTF (STEM INP. FINIS"                 
    "FREE F(OUTF)"                                         
    SAY "CHANGED " INPUTDAT                                 
    CHANGED = CHANGED + 1                                   
  END                                                       
  ELSE                                                     
  DO                                                       
    SKIPED = SKIPED + 1                                     
  END                                                       
END                                                         
SAY ' TOTAL NO. OF MEMBERS CHANGED : ' CHANGED             
SAY ' TOTAL NO. OF MEMBERS SKIPED : ' SKIPED


The strings which I want to change is perfectly changed. But If the string which I'm searching is found then I need to write it in the file as commented line(* in column 7) and the next line with the changed string.

So the record where the searched string is found have to written twice. One with old string and commented. Second with changed string without commented.


Please let me know how to proceed on this?

Thanks in advance.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 18, 2010 7:00 pm    Post subject:
Reply with quote

instead of 'reading' the member,
i would invoke an EDIT session with an EDIT MACRO for the member.

usage of ISPF EDIT Macro Commands would easily enable the insert of additional lines,
whereas dealing with a stem, as in your current logic, is more cumbersome.
Back to top
View user's profile Send private message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Fri Jun 18, 2010 7:12 pm    Post subject:
Reply with quote

Hi,

Could you please explain me in detail or posting the sample code for acheiving this requirement using ISPF EDIT Macro Commands
Back to top
View user's profile Send private message
Pedro

Senior Member


Joined: 01 Sep 2006
Posts: 2019
Location: Silicon Valley

PostPosted: Fri Jun 18, 2010 7:32 pm    Post subject: Reply to: Find ane replace string in all the members of a pd
Reply with quote

Read the ISPF Edit manual and study the FIND, LINE, and LINE_AFTER macro instructions.
Back to top
View user's profile Send private message
Pedro

Senior Member


Joined: 01 Sep 2006
Posts: 2019
Location: Silicon Valley

PostPosted: Fri Jun 18, 2010 7:37 pm    Post subject: Reply to: Find ane replace string in all the members of a pd
Reply with quote

In the rexx program that you have already done, I would:

1. make a subroutine to process the reading, stem processing, inserting lines.

2. Call that subroutine from the loop that does the member names

3. In the subroutine, make a new stem... check each line at a time and if string is no is not found, copy from input stem to output stem. If it is found, do your comment / change logic for that line.
Back to top
View user's profile Send private message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Fri Jun 18, 2010 8:20 pm    Post subject:
Reply with quote

Hi,

I have include one more stem and tryed to write the record in the file as bleo.But only the changed record is written in to the file and the other one is not writing.

IF SRCPOS > 0 THEN
DO
SAY "INP.I:" INP.I
INTER.I = INP.I
OUTPUTINT = TRGTPDS"("MEMBER")"
"ALLOC DA('"OUTPUTINT"') F(OUTE) SHR REU"
"EXECIO * DISKW OUTE (STEM INTER. FINIS"
"FREE F(OUTE)"
INP.I = DELSTR(INP.I, SRCPOS, LENGTH(SRCSTRNG))
INP.I = INSERT(TRGSTRNG, INP.I, SRCPOS-1)
STRFLAG = 1
SRCPOS = SRCPOS + LENGTH(TRGSTRNG)
OUTPUTDAT = TRGTPDS"("MEMBER")"
"ALLOC DA('"OUTPUTDAT"') F(OUTF) SHR REU"
"EXECIO * DISKW OUTF (STEM INP. FINIS"
"FREE F(OUTF)"
END
Back to top
View user's profile Send private message
Pedro

Senior Member


Joined: 01 Sep 2006
Posts: 2019
Location: Silicon Valley

PostPosted: Sat Jun 19, 2010 2:43 am    Post subject: Reply to: Find ane replace string in all the members of a pd
Reply with quote

You do not show the value of I, but likely you are not incrementing it.

Get a trace and analyze it. If you cannot figure it out, post the trace here.
Back to top
View user's profile Send private message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Wed Jun 23, 2010 5:21 pm    Post subject:
Reply with quote

Hi,

I have modified my code as below ,but now i am hitting the below error .Please let me know what's wrong with the code.

24 +++ SRCPOS = POS(SRCSTRNG,INP.I,SRCPOS)
Error running SRCHBKP1, line 24: Incorrect call to routine


***
source code:


SRCPOS = 0
DO I = 1 TO INP.0
"EXECIO * DISKW OUTF (STEM INP. "
SAY 'SRCSTRNG:'SRCSTRNG
SAY 'INP.I:'INP.I
SAY 'SRCPOS:' SRCPOS
SRCPOS = POS(SRCSTRNG,INP.I,SRCPOS)
IF SRCPOS > 0 THEN
DO
INP.I = DELSTR(INP.I, SRCPOS, LENGTH(SRCSTRNG))
INP.I = INSERT(TRGSTRNG, INP.I, SRCPOS-1)
SRCPOS = SRCPOS + LENGTH(TRGSTRNG)
OUT.J =INP.I
SAY 'OUT.J' OUT.J
"EXECIO * DISKW OUTF (STEM OUT. "
J = J + 1
END
END
"FREE F(OUTF)"
. . . . . . . . . . . . . . . . . . . . .
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Wed Jun 23, 2010 5:31 pm    Post subject:
Reply with quote

Huh ....................... how can you specify a starting position of zero
No wonder you get an error. This is a true position not an offset.
Back to top
View user's profile Send private message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Wed Jun 23, 2010 5:34 pm    Post subject:
Reply with quote

Hi,

I solved the problem.The offset(srcpos) must be a positive whole number. A syntax error will be raised if the offset is 0
Back to top
View user's profile Send private message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Wed Jun 23, 2010 5:44 pm    Post subject:
Reply with quote

SOURCE CODE:
Code:

/* REXX */                                       
SRCPDS    = 'Z000089.GPI.OPT(OPT1)'             
TRGTPDS   = 'Z000089.GPI.OPT(OP2)'               
SRCSTRNG  = 'COMP-4'                             
TRGSTRNG  = 'COMP-3'                             
INPUTDAT  = SRCPDS                               
OUTPUTDAT = TRGTPDS                             
INP.      = ""                                   
OUT.      = ""                                   
J         = 1                                   
                                                 
  "ALLOC DA('"INPUTDAT"') F(INPF) SHR REU"       
  "EXECIO * DISKR INPF (STEM INP. FINIS"         
  "FREE F(INPF)"                                 
                                                 
  "ALLOC DA('"OUTPUTDAT"') F(OUTF) SHR REU"     
    TRACE ?IR                                   
    SRCPOS = 1                                   
DO I = 1 TO INP.0                                       
    "EXECIO * DISKW OUTF (STEM INP.  "                 
    SAY 'SRCSTRNG:'SRCSTRNG                             
    SAY 'INP.I:'INP.I                                   
    SAY 'SRCPOS:' SRCPOS                               
    SRCPOS = POS(SRCSTRNG,INP.I,SRCPOS)                 
    IF SRCPOS > 0 THEN                                 
    DO                                                 
      INP.I = DELSTR(INP.I, SRCPOS, LENGTH(SRCSTRNG))   
      INP.I = INSERT(TRGSTRNG, INP.I, SRCPOS-1)         
      SRCPOS = SRCPOS + LENGTH(TRGSTRNG)               
      OUT.J =INP.I                                     
      SAY 'OUT.J' OUT.J                                 
     "EXECIO * DISKW OUTF (STEM OUT.  "                 
      J = J + 1                                         
    END                                                 
END                                                     
    "FREE F(OUTF)"                 

INPUT:

Z000089.GPI.OPT(OPT1)
----+----1----+----2----+-
**************************
RAJAN BOSE COMP-4
AISHWARYA COMP-4

Expected Output:

Z000089.GPI.OPT(OP2)
----+----1----+----2---
***********************
RAJAN BOSE COMP-4
RAJAN BOSE COMP-3
AISHWARYA COMP-4
AISHWARYA COMP-3

Current Output:
----+----1----+----2----+----
*****************************
RAJAN BOSE COMP-4
AISHWARYA COMP-4
RAJAN BOSE COMP-3
RAJAN BOSE COMP-3
AISHWARYA COMP-4


But Hitting RC=12 in trace as below

35 *-* END
19 *-* DO I = 1 TO INP.0
36 *-* "FREE F(OUTF)"
>L> "FREE F(OUTF)"
FILE OUTF NOT FREED, DATA SET IS OPEN
+++ RC(12) +++

Please help me out to overcome this issue.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Wed Jun 23, 2010 5:47 pm    Post subject:
Reply with quote

"EXECIO * DISKW OUTF (STEM INP. "

Would be better coded as ......................

"EXECIO * DISKW OUTF (STEM INP. FINIS"
Back to top
View user's profile Send private message
Pedro

Senior Member


Joined: 01 Sep 2006
Posts: 2019
Location: Silicon Valley

PostPosted: Wed Jun 23, 2010 7:29 pm    Post subject: Reply to: Find ane replace string in all the members of a pd
Reply with quote

You need to close the file before freeing it. Look at the syntax for the EXECIO command.
Back to top
View user's profile Send private message
Pedro

Senior Member


Joined: 01 Sep 2006
Posts: 2019
Location: Silicon Valley

PostPosted: Wed Jun 23, 2010 10:45 pm    Post subject: Reply to: Find ane replace string in all the members of a pd
Reply with quote

I had the same thought as Expat, but a quick look at the program showed that you were doing EXECIO in a loop.

I believe you have a logic problem in your program. It appears you are writing the output file for each line of the input file, which I do not think you want to do.
Back to top
View user's profile Send private message
superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Thu Jun 24, 2010 1:17 am    Post subject: Reply to: Find ane replace string in all the members of a pd
Reply with quote

I thought you wanted to do an update-in-place, finding the string, commenting it out, and then adding the changed string. If that's still what you want, here's something a bit simplified:

Code:

/* REXX */                                             
THEPDS    = 'Z000089.GPI.OPT(OPT1)'                   
SRCSTRNG  = 'COMP-4'                                   
TRGSTRNG  = 'COMP-3'                                   
"ALLOC DA('"THEPDS"') F(IO) SHR REU"                   
"EXECIO * DISKR IO (STEM INP. FINIS"                   
J = 0                                                 
DO I = 1 TO INP.0                                     
  PARSE VAR INP.I LFT (SRCSTRNG) RGT                   
  IF LENGTH(RGT) = 0 THEN                             
    DO                                                 
      J = J + 1                                       
      OUT.J = INP.I                                   
      OUT.0 = J                                       
    END                                               
  ELSE                                                 
    DO                                                 
      J = J + 1                                       
      OUT.J = INP.I                                   
      OUT.J = OVERLAY('*',OUT.J,7,1)                   
      J = J + 1                                       
      OUT.J = LFT||TRGSTRNG||RGT                       
      OUT.0 = J                                       
    END                                               
END                                                                   
"EXECIO * DISKW IO (STEM OUT. FINIS"                   
"FREE F(IO)"                                           
EXIT 0       
Back to top
View user's profile Send private message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Sun Jun 27, 2010 4:56 am    Post subject:
Reply with quote

Hi Superk,

Thanks a Lot.It worked fine for me.If anyone want me to post the source code please let me know.

Again Thanks Superk icon_smile.gif
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 -> CLIST & REXX All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
No new posts Replace repeated JCL with looping REXX prino CLIST & REXX 3 Thu Oct 13, 2016 5:30 am
No new posts Find out a active PGM jpsager JCL & VSAM 10 Fri Oct 07, 2016 4:32 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts How to find a CICS resource used in C... Arunkumar Chandrasekaran CICS 8 Thu Sep 29, 2016 1:45 pm


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