Using Rexx to find members in a PDS matching a given string

1.7k Views Asked by At

I am looking for help with my REXX script. Which should open an existing Member and search for a specific string.

Here is my script:

 /* REXX */ 
"ALLOC FILE(input) DA('.....(MEMBER)') SHR REUSE"
"EXECIO * DISKR "input" (STEM input. FINIS"                    
"FREE FILE(input)"                                             
/* Parmlib werden ausgelesen */                                
do i =1 to input.0                                             
   if POS('met,', input.i) > 0 Then                            
      /* Code if string is found */                            
      say Zeile gefunden                                       
   else                                                        
     /*  Code if string is not found */                        
     say Zeile nicht gefunden                                  
end                                                            

3

There are 3 best solutions below

0
apo On BEST ANSWER

Under ISPF, edit macros seem like a good fit. You can set up an ISPF stack if you're not running one already, works in batch too.

If I'm reading your requirement correctly, maybe something like this might work:

/* REXX-ISPF V/E macro */

Address ISREDIT                                    
"MACRO (needle,dest)"                              
                                                   
"CURSOR = 1 0"                                     
lastHit = 0                                        
i = 0                                              
                                                
"SEEK "needle                                      
Do While RC=0                                      
  "(l#) = CURSOR"                                  
  /* Conditional for multiple hits on same line */ 
  If l# > lastHit Then Do   /* do */               
    "(this) = LINE "l#                             
    i=i+1; out.i = this                            
    lastHit = l#                                   
  End                                              
  "SEEK "needle                                    
End                                                
out.0=i                                            
                                                   
Address TSO                                        
"ALLOCATE F(OUT) DA("dest"') OLD"                  
"EXECIO "out.0" DISKW OUT (FINIS STEM out."        
                                                   
Exit 0                                             

You can do this with much fewer lines with more ISPF services in a Macro (X ALL -> F ALL needle -> DEL ALL X -> CREATE dest). Or through intermittent use of ISPF E clipboard. That has some risks, so not going into that.

Good thing about ISPF E/V Macros is that thy use almost the same command you'd normally use in ISPF E/V. Find is quick. It needs to fit the whole dataset in the Region which might be an issue sometimes.

0
Marv Knight On

As cschneid stated this looks like something you would just use SuperC for. ISPF Option 3.14 or 3.15 will search for a string and show results. Also you can issue SRCHFOR from a member list and have only the found members then filtered in the member list. Additionally ISPF LM services can be used to go thru members of a PDS and then run an Edit macro to do the find. EXEXIO could be used to write the results to an output file. Note that SuperC will already do this using 3.15

0
rphi On

You could also call ISRSUPC from Rexx. There was a nifty Rexx exec published in MVS Update long ago. It searches for a string across all members of a PDS and presents the "hit list" on an ISPF panel, so you can edit or view the members.

I still use it (a descendant of it anyway) on my systems. I found the MVS Update article, here it is :

https://manualzz.com/doc/10913425/mvs0207