MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Count no:of occurrences of a string within a PDS

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF
View previous topic :: View next topic  
Author Message
sheelu
Beginner


Joined: 07 Apr 2014
Posts: 26
Topics: 6

PostPosted: Tue May 06, 2014 10:00 am    Post subject: Count no:of occurrences of a string within a PDS Reply with quote

Hi
I have written the following code to calculate the no:of occurrences of a string within A PDS.
Code:

SAY 'ENTER STRING'
PULL STR
INPUT=XXXXXX.XXXXX.PDS  (PDS NAME)
COUNT=0
X=OUTTRAP(BUF.)
ADDRESS TSO "LISTDS('"INPUT"') MEMBERS"
X=OUTTRAP("OFF")
DO I=7 TO BUF.0
     BUF.I=STRIP(BUF.I)
     ADDRESS TSO "ALLOC F(XX) DSN('"INPUT"("BUF.I")') SHR REU"
     "EXECIO * DISKR XX (FINIS STEM NEWVAR.")
DO I=1 TO NEWVAR.0
IF POS(STR,NEWVAR.I) <> 0
      THEN COUNT = COUNT +1
ELSE
      NOP
END
END
END
SAY COUNT
EXIT


On executing the code,the count value is printed but it is equal to the no:of occurrences of the string in the first member of the PDS and thereafter the error message "invalid data set name XXXX(PDS name)" is printed..

Can you please tell me how to achieve the count value equal to the total value of all occurrences of the string in the PDS??
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue May 06, 2014 12:13 pm    Post subject: Reply with quote

sheelu,

Code:

/* REXX                                                 */           
SAY 'ENTER STRING TO SEARCH '                                         
PULL STR                                                             
MAC  = 'PDSRCH'                                                       
PDS  = "'Your.pds.to.be.searched'"
TOT_COUNT = 0                                                         
ADDRESS ISPEXEC "VPUT (STR) SHARED"                                   
SAY 'SEARCHING THE PDS : ' PDS                                       
SAY 'STRING TO BE SEARCHED : ' STR                                   
X = OUTTRAP("LIBMEM.")                                               
 ADDRESS TSO "LISTDS "PDS" M"                                         
X = OUTTRAP("OFF")                                                   
                                                                     
PDS = STRIP(PDS,"B","'")                                             
                                                                     
DO I = 7 TO LIBMEM.0                                                 
  LIBMEM.I = STRIP(LIBMEM.I)                                         
  ADDRESS ISPEXEC "VIEW DATASET ('"PDS"("LIBMEM.I")') MACRO ("MAC")" 
  ADDRESS ISPEXEC "VGET (ZISPFRC) SHARED"                             
  TOT_COUNT = TOT_COUNT + ZISPFRC                                     
END                                                                   
  SAY 'TOTAL COUNT IS : ' TOT_COUNT                                   
EXIT                                                                 


The macro PDSRCH used to search
Code:

/* REXX                                                 */
ADDRESS ISPEXEC "VGET (STR) SHARED"                       
ADDRESS ISREDIT "MACRO PROCESS"                           
ADDRESS ISREDIT "SEEK ALL '" || STR || "'"                 
ADDRESS ISREDIT "(ZISPFRC) = SEEK_COUNTS"                 
ADDRESS ISPEXEC "VPUT (ZISPFRC)"                           
ADDRESS ISREDIT "END"                                     
EXIT                                                       

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sheelu
Beginner


Joined: 07 Apr 2014
Posts: 26
Topics: 6

PostPosted: Wed May 07, 2014 12:56 am    Post subject: Reply with quote

Thanks Kolusu

I tried the code but on execution of the code,I am getting the error-
"command PDSRCH" not found!!
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed May 07, 2014 11:23 am    Post subject: Reply with quote

sheelu wrote:
Thanks Kolusu

I tried the code but on execution of the code,I am getting the error-
"command PDSRCH" not found!!


Sheelu,

Did you save the second macro as PDSRCH ?

Follow these steps.

1. Save the 1st REXX exec as "STRSRCH"
2. Save the 2nd REXX exec as "PDSRCH"
3. Issue the command TSO STRSRCH which will give you the desired results.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group