Page 1 of 3

Reading and updating the member of a pds using rexx

PostPosted: Tue Jan 24, 2017 7:23 pm
by arya_starc
Hi All,

I need to write rexx code for updating the member content (changing some string).
Below is the rexx code which i get from one of the post in this forum


PARSE ARG LIB MACRO
LIB = STRIP(LIB,B,"'")
ADDRESS ISPEXEC
"LMINIT DATAID(LIBDID) DATASET("LIB") ENQ(SHR)"
"LMOPEN DATAID("LIBDID") OPTION(INPUT)"
MEMBER = ''
"LMMLIST DATAID("LIBDID") OPTION(LIST) STATS(YES) MEMBER(MEMBER)"
/*------------------------------------------------------------------*/
/* */
/*------------------------------------------------------------------*/
DO WHILE ( RC = 0 )
 MEMBER = STRIP(MEMBER)
 "EDIT DATASET('"LIB"("MEMBER")') MACRO("MACRO")"
 "LMMLIST DATAID("LIBDID") OPTION(LIST) STATS(YES) MEMBER(MEMBER)"
END
/*------------------------------------------------------------------*/
/* FREE AND CLOSE LIB LIBRARY DIRECTORY */
/*------------------------------------------------------------------*/
"LMMLIST DATAID("LIBDID") OPTION(FREE)"
"LMCLOSE DATAID("LIBDID")"
"LMFREE DATAID("LIBDID")"
EXIT


Where MACRO contains:

/*REXX*/
ADDRESS ISREDIT
"MACRO PROCESS"
"CHANGE 'ABC' 'EFG' ALL"
"SAVE"
"END"
"MEND"
EXIT

 


How can i call the respective pds to this rexx ??
halp please...

Re: Reading and updating the member of a pds using rexx

PostPosted: Tue Jan 24, 2017 8:55 pm
by enrico-sorichetti
see here for a full working application ( TESTED )
http://ibmmainframes.com/viewtopic.php? ... ht=masschg

Re: Reading and updating the member of a pds using rexx

PostPosted: Tue Jan 24, 2017 9:12 pm
by willy jensen
I think that you need to be more specific about what you want to do and what kind of scenario you have in mind. The sample you posted will run the edit macro against all the members of a pds.

Re: Reading and updating the member of a pds using rexx

PostPosted: Tue Jan 24, 2017 9:56 pm
by enrico-sorichetti
The sample you posted will run the edit macro against all the members of a pds.


that' s what emerges from the question and the code snippet posted
( too bad that no error handling was implemented )

Re: Reading and updating the member of a pds using rexx

PostPosted: Tue Jan 24, 2017 10:28 pm
by willy jensen
The sample, yes, but the subject says 'updating the member of a pds' which to me means a single named member, hence my request for clarification. Let's see what the OP comes back with.

Re: Reading and updating the member of a pds using rexx

PostPosted: Wed Jan 25, 2017 3:02 pm
by arya_starc
I need to read the members of as pds then inside that member i need to change the string
I am tried with below code but it is not working:


/*REXX*/                                                        
TRACE I                                                        
SAY HI                                                          
ADDRESS TSO                                                    
LIBI = 'VM.LAT.D10A010.PF.JCLLIB.FB.SASH1'                      
LIBO = 'VM.LAT.D10A010.PF.JCLLIB.FB.SASH2'                      
"ALLOC F(INFILE) DSN('VM.LAT.D10A010.PF.SCHED3') SHR REU"      
"EXECIO * DISKR INFILE( FINIS STEM MYFILE."                    
"FREE F(INFILE)"                                                
"LISTDS'"LIBI"'MEMBER"                                          
/* PARSE ARG LIB MACRO  */                                      
IF SYSDSN("'"LIBI"'") = 'OK' THEN                              
   SAY YES                                                        
I = 1                                                          
DO WHILE I <= MYFILE.0                                        
   SAY I                                                        

   SAY ' LINE ' I ':' MYFILE.I                        
   MEMBER = STRIP(MYFILE.I)                          
   MEM = LIBI || "(" || MEMBER || ")"                
   SAY 'JOBNAME :' MEMBER                        
   "ALLOC FI(IN) DA('"MEM"') SHR REUSE"          
   "EXECIO * DISKR IN (STEM TAB. FINIS"          
   "FREE F(IN)"                                  
   DO J = 1 TO TAB.0                            
      DISPLAY TAB.J                                
      IF LENGTH(TAB.J) > 0 THEN
          CHANGESTR('SSIDCAMS','TAB.J','VIDCAMS')    
   END                                                  
END                                                  
EXIT                                                
 


On tracing it giving error: ROUTINE NOT FOUND

Edited by moderator to remove unnecessary DO/ENDs and to align code properly.
Note to OP:if that was how your code really looked then learn to code with proper indentation and unnecessary code blocks.

Re: Reading and updating the member of a pds using rexx

PostPosted: Wed Jan 25, 2017 4:06 pm
by NicC
Where does it say that - which line?
What is in routine DISPLAY?

Re: Reading and updating the member of a pds using rexx

PostPosted: Wed Jan 25, 2017 4:22 pm
by enrico-sorichetti
I do not see the I incremented

substitute
I = 1                                                          
DO WHILE I <= MYFILE.0        


with
do i = 1 to myfile.0

Re: Reading and updating the member of a pds using rexx

PostPosted: Wed Jan 25, 2017 4:25 pm
by arya_starc
NicC wrote:Where does it say that - which line?
What is in routine DISPLAY?



On tracing this...... it is saying routine not found.
I think refering to CHANGESTR

CHANGESTR('SSIDCAMS','TAB.J','VIDCAMS')
 


The error written in screen as ERROR RUNNING REIDCAMS; LINE 29:ROUTINE NOT FOUND

Re: Reading and updating the member of a pds using rexx

PostPosted: Wed Jan 25, 2017 4:33 pm
by willy jensen
The following sample will change a number of strings in all members of a pds using pure REXX. It will also set the ISPF statistics for changed members - note that values are reset as EXECIO willl destroy old info. But I will still very strongly advise using a proper utility, my personal favorite is PD86 from CBTTAPE.ORG, or it's commercial sibling STARTOOL from SERENA.

 ds='TEST.CF.PDS'  /* pds to update */                  
 xdd=''                                                            
 cf.1='TIME=1440'        /* change from */                          
 cf.2='SYS1.@'                                                      
 cf.0=2                                                            
 ct.1='TIME=NOLIMIT'     /* change to   */                          
 ct.2='SYSX'                                                        
 if sysdsn("'"ds"'")<>'OK' then call xit ds sysdsn("'"dsq"'")      
 zz=outtrap('mls.')                                                
 "listds '"ds"' members"                                            
 zz=outtrap('off')                                                  
 alp='rtddn(xdd)'                                                  
 do mln=7 to mls.0                                                  
   cn=0                                                            
   mbr=strip(mls.mln)                                              
   /* change data in member begin */                                
   cc=Bpxwdyn('alloc da('ds'('mbr')) shr' alp)                      
   if cc<>0 then call xit 'alloc' ds 'rc' cc                        
   alp='dd('xdd') reuse'                                            
   "execio * diskr" xdd "(stem data. finis)"                        
   if rc<>0 then call xit 'read' ds'('mbr')' 'rc' rc                
   do di=1 to data.0                                                
     do cfn=1 to cf.0                                              
       cf=cf.cfn                                                    
       ct=ct.cfn                                                    
       parse value ' 'strip(data.di,'t')' ' with front (cf) back    
       if length(back)=0 then iterate                              
       say mbr 'before:' data.di                                    
       data.di=substr(front''ct''back,2)                            
       say mbr 'after: ' data.di                                    
       cn=cn+1                                                      
     end                                                            
   end                                                              
   if cn=0 then iterate                                            
   "execio * diskw" xdd "(stem data. finis)"                        
   if rc<>0 then call xit 'write' ds'('mbr')' 'rc' rc              
   say 'Changes done in' mbr                                        
   /* ISPS stats */                                                
   address ispexec "lminit dataid(did) dataset('"ds"') enq(shr)"    
   if rc<>0 then call xit 'lminit rc' rc                            
   address ispexec "lmmstats dataid("did") member("mbr")"          
   if rc<>0 then call xit 'LMMStats rc' rc zerrlm                  
   address ispexec "lmfree dataid("did")"                          
   /* change data in member end   */                                
 end                                                                
 Call xit 'All done'                                                
XIT:                                                                
 if arg(1)<>'' then say arg(1)                                      
 if xdd<>'' then zz=Bpxwdyn('free dd('xdd')')                      
 exit word(arg(2) 0,1)