Delete datasets catalogued in JCL:

Delete data sets cataloged in a JCL

This one I developed I guess around 5 yrs back, there were lot of JCL’s in the system, poorly written not to have a delete Step at the top for deleting the datasets cataloged in the JCL. Each time I had to run the job I had to delete all the datasets manually.

One or two dataset to delete was Ok, but was frustrating when there were more than 10.  So friends if you face the similar situation then the following piece of CLIST and ISREDIT macro will rescue you.

How to Use this? – Copy the code to a pds allocated to SYSPROC and then Just give command line command “ACDEL” on the JCL you wish to operate this CLIST on.

/********************************************************************** /* TITLE      : ACDEL /*——————————————————————- /* FUNCTION   : DELETE ALL CATALOGED DATASETS IN A JOB /*——————————————————————- /* AUTHOR     : VIKAS SAXENA (mainframewizard.com) /*——————————————————————- /* DESCRIPTION: THIS CLIST SCANS THE JOB AND DELETES ALL DATASETS THAT /*            : ARE CREATED IN THE JOB. IT SAVES THE EFFORT OF WRITING /*            : A DELETE STEP AT THE TOP. /*——————————————————————- /* HOW TO RUN : COPY THIS MEMBER TO THE PDS ALLOCATED TO SYSPROC. OPEN /*            : THE JOB WHICH YOU WISH TO SCAN AND TYPE ‘ACDEL’ AT THE /*            : COMMAND LINE AND PRESS ENTER. /*——————————————————————- /* COMMENTS   : IT WILL ONLY DELETE DATASETS CATALOGED BY THE USER /********************************************************************** ISREDIT MACRO /*CONTROL MSG CONLIST SYMLIST NOFLUSH /********************************************************************** /* SAVING THE LAST LINE NUMBER AS LAST_ROW IN THE JOB ***************** /********************************************************************** ISREDIT FIND LAST  ‘//’ 1 ISREDIT (CROW,CPOS) = CURSOR ISREDIT (CSRDATA) = LINE &CROW SET LAST_ROW=&CROW /********************************************************************** /********* MOVING THE CURSOR AT THE START OF THE JOB    **************** /********************************************************************** ISREDIT FIND FIRST ‘//’ 1 /********************************************************************** /********* VALIDATING THAT IT IS A JCL BEFORE SCANNING  **************** /********************************************************************** IF &LASTCC^=0 THEN + DO WRITE IT CAN ONLY SCAN A JOB SET LINE_COUNT=0 GOTO ENDCLIST END /********************************************************************** /********* EXCLUDING THE LINES NOT NEEDED FOR SCANNING **************** /********************************************************************** ISREDIT X ALL ISREDIT F ALL ‘//’ 1 ISREDIT X ALL //* ISREDIT X ALL EXEC SET RETURN_CODE=0 SET CURRENT_ROW=0 SET LINE_COUNT=0 /********************************************************************** /********* PERFORMING TILL FIND FOR ‘DSN’ IS SUCCESSFUL  *************** /********************************************************************** DO WHILE &RETURN_CODE=0  ISREDIT FIND DSN  SET RETURN_CODE=&LASTCC  IF &RETURN_CODE^=0 THEN +    GOTO ENDCLIST  ISREDIT (CROW,CPOS) = CURSOR  ISREDIT (CSRDATA) = LINE &CROW  SET DDLINE = &CROW  SET DSNCOL=&SYSINDEX(&STR(DSN=),&STR(&CSRDATA),1)  SET CATLG_POS=0  SET DSN_POS=0  SET CURRENT_ROW=&CROW /********************************************************************** /*******PERFORMING TILL NEXT SEARCH FOR ‘DSN’ IS UNSUCCESSFUL  ******** /**********************************************************************   DO WHILE &DSN_POS=0    SET LINE_COUNT=&LINE_COUNT +1    SET CATLG_POS=&SYSINDEX(CATLG,&STR(&CSRDATA),1)    IF &CURRENT_ROW < &LAST_ROW THEN +     SET CURRENT_ROW=&EVAL(&CURRENT_ROW + 1)    ELSE +     GOTO ENDCLIST    ISREDIT (CSRDATA) = LINE &CURRENT_ROW    SET DSN_POS=&SYSINDEX(DD,&STR(&CSRDATA),1) /********************************************************************** /*****  IF ‘CATLG’ IS FOUND DELETE THE DATASET ONLY IF THE  *********** /*****  DATASET EXISTS AND THE USER HAS ACCESS TO DELETE IT *********** /**********************************************************************    IF &CATLG_POS^=0 THEN +     DO      ISREDIT (CSRDATA) = LINE &DDLINE      SET STARTPOS= &SYSINDEX(&STR(DSN=),&STR(&CSRDATA),1)      SET STARTPOS=&STARTPOS+4      SET ENDPOS= &SYSINDEX(&STR(,),&STR(&CSRDATA),&STARTPOS)       IF &ENDPOS= 0 THEN +        SET ENDPOS= &SYSINDEX(&STR( ),&STR(&CSRDATA),&STARTPOS)        SET ENDPOS = &ENDPOS-1        SET DATASET=&SUBSTR(&STARTPOS:&ENDPOS,&STR(&CSRDATA))        SET USER_DS=&SYSINDEX(&STR(&SYSUID),&STR(&DATASET),1)        IF &USER_DS^=0 THEN +          DO           SET DSN_STATUS=&STR(&SYSDSN(‘&DATASET’))         IF &DSN_STATUS=OK THEN +           DO           DELETE ‘&DATASET’           END           END         ELSE +           DO           IF &USER_DS=0 THEN +           WRITE CANNOT DELETE &DATASET           IF &DSN_STATUS^=OK THEN +           WRITE DATASET NOT FOUND           END      SET DSN_POS=&LAST_ROW + 1      SET END_LOOP=&LAST_ROW + 1     END   END END IF &DSN_POS=&END_LOOP THEN + GOTO  ENDCLIST /********************************************************************** /*****  ENDING THE CLIST   ******************************************** /********************************************************************** ENDCLIST: + WRITE LINES PROCESSED &LINE_COUNT ISREDIT RESET

END

 

Please provide your feedback/suggestions regarding this tutorial on contact form. Tutorials related to COBOL, JCL, DB2 etc are also present on the Website for mainframe developers. Mainframe jobs can be posted on our mainframe jobs forum.