DocBag

Back Issue

Checking if a dataset exists

Sometimes, a dataset used in a job may or may not already exist. One way of dealing with this situation is to alter the behaviour of the job if the dataset doesn't exist. For example, //EXIST1 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSIN DD * LISTC ENT('SOME.DATASET.NAME') // IF RC = 0 THEN //* executes when dataset exists ……. more JCL here ………. // ELSE //* executes when dataset doesn't exist ……. more JCL here ………. // ENDIF If the dataset exists, then normally a zero return code is expected from the LISTC command. If the return code isn't zero, then different job steps are executed.

Another possible approach is to delete the dataset if it exists:

//EXIST2 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSIN DD * LISTC ENT('SOME.DATASET.NAME') IF LASTCC = 0 THEN - DELETE 'SOME.DATASET.NAME' ELSE SET MAXCC = 0 // ENDIF Then, the job will proceed as if the dataset doesn't exist. The return code from this step can be checked to see if there were problems deleting an existing dataset.

Feedback

Comments or suggestions can be sent to the author.

Last Month's Issue

Big Iron