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Â ‘//’ 1ISREDIT (CROW,CPOS) = CURSORISREDIT (CSRDATA) = LINE &CROWSET 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 +DOWRITE IT CAN ONLY SCAN A JOBSET LINE_COUNT=0GOTO ENDCLISTEND/**********************************************************************/********* EXCLUDING THE LINES NOT NEEDED FOR SCANNING ****************/**********************************************************************ISREDIT X ALLISREDIT F ALL ‘//’ 1ISREDIT X ALL //*ISREDIT X ALL EXECSET RETURN_CODE=0SET CURRENT_ROW=0SET 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Â ENDENDIF &DSN_POS=&END_LOOP THEN +GOTOÂ ENDCLIST/**********************************************************************/*****Â ENDING THE CLISTÂ Â ********************************************/**********************************************************************ENDCLIST: +WRITE LINES PROCESSED &LINE_COUNTISREDIT 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.