Tuesday, April 27, 2010

Using File-AID Batch to update multiple PDS members

Today at work I found I had multiple members of a partitioned data set that I wanted to update from a batch job. I had previously written an RPF to do this, but post-Sarbanes/Oxley fallout has caused us to change our dataset permissions and procedures somewhat, so I needed to update with JCL this time.

I was trying to fool around with using TSO edit commands to update the files using IKJEFT01 to invoke a TSO shell, and my boss saw what I was doing and suggested File-AID instead. File-AID is very flexible and fast, but the documentation is a little daunting, and I've never taken a class on it or found any tutorials that I could tolerate. However, with some trial and error I was able to get it to update my dataset members without any problems, and my final JCL read pretty well, unlike some of the more unintelligible arcana I've submitted to the mainframe in the past.



To illustrate my approach without giving out any company secrets, I created a sample PDS, curtis.s.pds, and members test1 through test3. They each have a word on three lines that I want to replace with another word:
> APPLID(MYROSCOE)   USER(CID,CURTIS)                                          
> DSN()               SCRL CSR  COLS 00001 00073                   LINE 000001  
> CURTIS.S.PDS(TEST1)                                                          
>      <...+....1....+....2....+....3....+....4....+....5....+....6....+....7...
        =============================== T O P ================================= 
000001 He was caught between a brick and a hard place.                          
000002 This concert is brickin'!                                                
000003 I am a brick, I am an island.                                            
        ============================ B O T T O M ============================== 

> APPLID(MYROSCOE)   USER(CID,CURTIS)                                          
> DSN()               SCRL CSR  COLS 00001 00073                   LINE 000001  
> CURTIS.S.PDS(TEST2)                                                          
>      <...+....1....+....2....+....3....+....4....+....5....+....6....+....7...
        =============================== T O P ================================= 
000001 What is six times nine?                                                  
000002 The number nine is considered lucky.                                     
000003 One of the few single-digit primes is nine.                              
        ============================ B O T T O M ============================== 

> APPLID(MYROSCOE)   USER(CID,CURTIS)                                          
> DSN()               SCRL CSR  COLS 00001 00073                   LINE 000001  
> CURTIS.S.PDS(TEST3)                                                          
>      <...+....1....+....2....+....3....+....4....+....5....+....6....+....7...
        =============================== T O P ================================= 
000001 Two wrongs don't make a left.                                            
000002 Most computer geeks are left-handed.                                     
000003 The book is left over there.                                             
        ============================ B O T T O M ============================== 
In test1, I want to replace "brick" with "rock". In test2, "nine" with "seven". In test3, "left" with "right". In the JCL dataset declaration, I'm allowed to feed File-AID datasets DD01 through DD99, and refer to them by $$DD01 through $$DD99 in the SYSIN script, and in fact my first iteration addressed the members individually this way and it worked.

However, I found you could get by with just declaring the PDS as DD01, and each command in the script could reference an individual member using "MEMBER=" before the final command.
> APPLID(MYROSCOE)   USER(CID,CURTIS)                                          
> AWS(CID.FATEST)     SCRL CSR  COLS 00001 00072                   A<ROS1>      
>       <...+....1....+....2....+....3....+....4....+....5....+....6....+....7..
 ...... ================================ T O P =================================
 000001 //CURTISF JOB (59000),'FILEAIDTEST',CLASS=F,                           
 000002 //      MSGCLASS=H                                                      
 000003 //********************************************************************  
 000004 //FILEAID1  EXEC PGM=FILEAID,REGION=6M                                  
 000005 //STEPLIB  DD  DSN=SYS3.FILEAID.LOAD,DISP=SHR                           
 000006 //SYSPRINT DD SYSOUT=*                                                  
 000007 //SYSLIST  DD SYSOUT=*                                                  
 000008 //DD01     DD DSN=CURTIS.S.PDS,DISP=OLD                                
 000010 //SYSIN    DD *                                                         
 000011 $$DD01 UPDATE MEMBER=TEST1,EDIT=(1,0,C'brick',C'rock')                  
 000012 $$DD01 UPDATE MEMBER=TEST2,EDIT=(1,0,C'nine',C'seven')                  
 000013 $$DD01 UPDATE MEMBER=TEST3,EDIT=(1,0,C'left',C'right')                  
 000014 /*                                                                      
 000015 //                                                                      
 ...... ============================= B O T T O M ==============================
I submitted the above job and got a good return code. In the job output, the SYSPRINT had this to say about what it did:
> APPLID(MYROSCOE)   USER(CID,CURTIS)                                          
> JOB(CURTISF,14062) SCRL CSR  COLS 00001 00073                   F 04 P 0001  
>      <...+....1....+....2....+....3....+....4....+....5....+....6....+....7...
000004      PROGRAM AND ALL MATERIAL COPYRIGHT 1980,2008 BY COMPUWARE CORPORATIO
000005 1...5...10...15...20...25...30...35...40...45...50...55...60...65...70...
000006                                                                          
000007 DD01     DSN=CURTIS.S.PDS OPENED AS PO,                                 
000008              RECFM=FB,LRECL=80,BLKSIZE=27920,VOL=TSO053                  
000009 $$DD01 UPDATE MEMBER=TEST1,EDIT=(1,0,C'brick',C'rock')                   
000010 ABOVE FUNCTION ENDED ON MEMBER END                                       
000011   MEMBERS-READ=1,UPDATED=1,RECORDS-READ=3,UPDATED=3                      
000012                                                                          
000013 - - - - - - - - - - - - - - - - ACTIONS TAKEN MAP - - - - - - - - - - - -
000014    EDT#1---------3                                                       
000015                                                                          
000016 $$DD01 UPDATE MEMBER=TEST2,EDIT=(1,0,C'nine',C'seven')                   
000017 ABOVE FUNCTION ENDED ON MEMBER END                                       
000018   MEMBERS-READ=1,UPDATED=1,RECORDS-READ=3,UPDATED=3                      
000019                                                                          
000020 - - - - - - - - - - - - - - - - ACTIONS TAKEN MAP - - - - - - - - - - - -
000021    EDT#1---------3                                                       
000022                                                                          
000023 $$DD01 UPDATE MEMBER=TEST3,EDIT=(1,0,C'left',C'right')                   
000024 ABOVE FUNCTION ENDED ON MEMBER END                                       
000025   MEMBERS-READ=1,UPDATED=1,RECORDS-READ=3,UPDATED=3                      
000026                                                                          
000027 - - - - - - - - - - - - - - - - ACTIONS TAKEN MAP - - - - - - - - - - - -
000028    EDT#1---------3                                                       
000029                                                                          
        ============================ B O T T O M ============================== 
Looks good so far - each edit command found three records to update. Now here is what the changed members look like:
> APPLID(MYROSCOE)   USER(CID,CURTIS)                                          
> DSN()               SCRL CSR  COLS 00001 00073                   LINE 000001  
> CURTIS.S.PDS(TEST1)                                                          
>      <...+....1....+....2....+....3....+....4....+....5....+....6....+....7...
        =============================== T O P ================================= 
000001 He was caught between a rock  and a hard place.                          
000002 This concert is rockin'!                                                 
000003 I am a rock,  I am an island.                                            
        ============================ B O T T O M ============================== 

> APPLID(MYROSCOE)   USER(CID,CURTIS)                                          
> DSN()               SCRL CSR  COLS 00001 00073                   LINE 000001  
> CURTIS.S.PDS(TEST2)                                                          
>      <...+....1....+....2....+....3....+....4....+....5....+....6....+....7...
        =============================== T O P ================================= 
000001 What is six times seven?                                                 
000002 The number seven is considered lucky.                                    
000003 One of the few single-digit primes is seven.                             
        ============================ B O T T O M ============================== 

> APPLID(MYROSCOE)   USER(CID,CURTIS)                                          
> DSN()               SCRL CSR  COLS 00001 00073                   LINE 000001  
> CURTIS.S.PDS(TEST3)                                                          
>      <...+....1....+....2....+....3....+....4....+....5....+....6....+....7...
        =============================== T O P ================================= 
000001 Two wrongs don't make a right.                                           
000002 Most computer geeks are right-handed.                                    
000003 The book is right over there.                                            
        ============================ B O T T O M ============================== 
Everything looks correct, except for lines 1 and 3 of test1. "rock" is shorter than "brick", and File-AID looks for excuses not to re-write entire records wherever possible. Since this is a tool meant to manipulate reports where column positions are significant, this is expected behavior, albeit annoying if you want it to work like a text editor's replace function.

Is there a way to keep that from happening? Sure, download the file with FTP, open it in Notepad...

No comments:

Post a Comment