Monday, December 12, 2011

File-aid: Insert a record after a particular condition is met

Lets say we have a JCL library and it has several jobs as members and we want to insert a new load library right after the existing load library in each JCL. The below job achieves this.

//STEP10 EXEC PGM=FILEAID
//DD01   DD DISP=SHR,DSN=TEST.JCL.LIB
//NEWJCL DD DISP=SHR,DSN=TEST.JCL.LIB
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
$$DD01 USER FORM=JCL,WRITE=NEWJCL,
 IF=(1,0,C'EXISTING.LOAD.LIB'),
 IF=(1,NE,C'//*'),
 MOVE=(1,80C' '),
 MOVE=(1,C'// DISP=SHR,DSN=NEW.LOAD.LIB'),
 WRITE=NEWJCL
//*

Explanation of the control card

The USER parameter is used to insert new records in a dataset.  FORM=JCL instructs the file-aid that the input dataset has the JCLs and logically process the JCL statements. Assume the below case.

//JOBLIB DD DSN=EXISTING.LOAD.LIB,
//          DISP=SHR

In this case, File-aid, properly inserts the "// DISP=SHR,DSN=NEW.LOAD.LIB" statement right after the DISP=SHR statment, instead of inserting the new statement inbetween the DSN and DISP statements.

We can interpret rest of the control card as below.

1. Write the input record in the output dataset. In this case, same dataset
2. If "EXISTING.LOAD.LIB" is found anywhere between column 1 and till end of the record and first three poisitions are not equal to "//*" (check for commented line)
3.Intialize the output record
4.Populate "// DISP=SHR,DSN=NEW.LOAD.LIB" to the output record
5.Write the output record in the output dataset.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.