Reading and updating the member of a pds using rexx



IBM's Command List programming language & Restructured Extended Executor

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

Postby NicC » Thu Jan 26, 2017 5:17 pm

Rexx on the mainframe is the original. Anything else is a derivative and many have new functions. One version has the ability to run scripts written for almost any derivative. However, you need the manual for the interpreter version that you are using and you need to skim through it at least once and then read, in depth, those parts that you are going to use now.

There are ways of changing data without using CHANGESTR. You could search the string (POS function) for the string that you want to replace, then split (SUBSTR) the string into before, after and not wanted parts and then reassemble with before, new, after.

You could also do it the way Enrico shows, using using ISPF facilities.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

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

Postby willy jensen » Thu Jan 26, 2017 5:48 pm

Parse (in my opinion sadly overlooked) can also be used, as in the sample I posted.

 cf='old-string'
 ct='new-string'
 parse value ' 'strip(data.di,'t')' ' with front (cf) back    
 if length(back)>0 then data.di=substr(front''ct''back,2)  
 
willy jensen
 
Posts: 455
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 69 times

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

Postby NicC » Thu Jan 26, 2017 6:08 pm

or, without losing leading and trailing blanks (which might be important):

 data.1 = "out with the old and in with the new stuff"
 say data.1
 cf='old'
 ct='new'
 parse value data.1 with front (cf) back    
 if length(back)>0 then data=front''ct''back
 say data.1
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

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

Postby enrico-sorichetti » Thu Jan 26, 2017 6:54 pm

there are many alternatives that You can Use ...
all depends on the layout of the data to be processed

chiefly on how many occurrences of the from string

for the simpler case something like
buf = " some data with some from string and the rest of the buffer"
f  = "from string"
t  = "to string"
say buf

l = length(f)
x = pos(f, buf)
if  x > 0 then ,
    buf = left(buf,x-1) || t || substr(buf,x+l)
say buf

buf = " some data with some from string and the rest of the buffer"
parse var buf head (f) tail

if length(tail) > 0 then ,
    buf = head || t || tail
say buf

buf = " there is nothing to be changed"
parse var buf head (f) tail

if length(tail) > 0 then ,
    buf = head || t || tail
say buf

 

might work
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

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

Postby enrico-sorichetti » Thu Jan 26, 2017 7:09 pm

Rexx on the mainframe is the original. Anything else is a derivative and many have new functions.


unfortunately I have to disagree on the second part
the rexx mainframe might be the original, but has not evolved :(
probably it is due to the process by which IBM implements product changes

see
http://www.rexxla.org/rexxlang/standards/j18pub.pdf
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

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

Postby arya_starc » Thu Jan 26, 2017 7:44 pm

Hi NicC,
I coded the below rexx and output is coming ok

/*REXX*/                                                    
 SAY HI                                                      
 ADDRESS TSO                                                
 FILEI = "VM.LAT.D10A010.PF.JCLLIB.FB.SASH1"                
    FILEO = "VM.LAT.D10A010.PF.JCLLIB.FB.SASH2"              
 A = '//STEPLIB  DD DSN=VPIDCAMS     '                      
 X = OUTTRAP(MEMBERS.)                                      
 "LISTDS" FILEI "MEMBERS"                                    
 X = OUTTRAP(OFF)                                            
 DO I=7 TO MEMBERS.0                                        
    X = STRIP(MEMBERS.I)                                    
    MEM = FILEI || "(" || X || ")"                          
    SAY MEM                                                  
    "ALLOC FI(IN) DA('"MEM"') SHR REUSE"                    
    "EXECIO * DISKR IN (STEM MEMB_LINES. FINIS"              
    "FREE F(IN)"                                            
    MEM1 = FILEO || "(" || X || ")"                          
    SAY MEM1                                                
 "ALLOC FI(OUT) DA('"MEM1"') SHR REUSE"                      
 STC -DSLISTC DSLISTC                                

SAY 'ALLOC OUT RC=' RC                                      
     DO J = 1 TO MEMB_LINES.0                                
        Y = STRIP(MEMB_LINES.J)                              
        IF POS('PGM=SSIDCAMS',Y) > 0 THEN DO                  
           SAY Y                                              
           B = SUBSTR(Y,1,9)                                  
           C = ' EXEC  PGM=VPIDCAMS,COND(0,NE),'              
           Y = B C                                            
           LINES_OUT.J = Y                                    
           SAY Y                                              
           SAY HEREREREE                                      
           DO L = J+1 TO J+2                                  
           D = STRIP(MEMB_LINES.L)                            
              IF POS('PARM=''',D) > 0 THEN DO                
              SAY TRUE                                        
                 D = SUBSTR(D,1,10)                          
                 E = 'PARM=''&JCLLIB $SETLIB&REGFS'''        
                 Y = D E                                      
                 SAY Y                                        

                J = J + 1                                              
                 LINES_OUT.J = Y                                        
              END                                                      
              ELSE IF POS('//      ',D) > 0 THEN DO                    
                   SAY TRUE                                            
                   F = '//*'                                            
                   Y = F                                                
                   SAY Y                                                
                   J = J + 1                                            
              END                                                      
              ELSE                                                      
                 NOP                                                    
           SAY D                                                        
           END                                                          
        END                                                            
        ELSE DO                                                        
        END                                                            
        LINES_OUT.J = Y                                                

       SAY LINES_OUT.J                                        
     END                                                        
     SAY HERE                                                  
    "EXECIO "MEMB_LINES.0" DISKW OUT(STEM LINES_OUT. FINIS)"    
    "FREE F(IN)"                                                
    "FREE FI(OUT)"                                              
 END                                                            
 EXIT                                                          

 


I am getting some warning message regarding freed of file
arya_starc
 
Posts: 136
Joined: Mon Sep 21, 2015 1:39 pm
Has thanked: 5 times
Been thanked: 0 time

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

Postby Akatsukami » Thu Jan 26, 2017 9:28 pm

That's too bad. If you had shown us a trace with the actual message, we might be able to do more than express sympathy.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

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

Postby NicC » Fri Jan 27, 2017 4:07 am

I guess it is because it cannot free 'in' at the end because you already freed it after reading it. Really, you need to spend more time analysing errors.

You appear to have accomplished the task - locking topic.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Previous

Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post