Check whether a data set exists
With ZOAU, you can check whether the data set ${prefix}.MY.JCL
exists with any of the following ways:
-
Issuing a shell command:
If the data set exists, the return code is zero. If the data set does not exist, the return code is non-zero.
- Option 1:
dls "${prefix}.MY.JCL" 2>/dev/null >/dev/null
- Option 2:
mvscmdauth --pgm=IDCAMS --sysprint=dummy --sysin=stdin <<zz LISTCAT ENTRIES('${prefix}.MY.JCL') zz
-
Calling an API in Python programs:
datasets.exists("%s.MY.JCL" % HLQ)
To achieve the same purpose without ZOAU, you could write the following JCL:
//*
//* Check if dataset @@HLQ@@.ZOASAMP.MY.JCL exists
//* If it does, return code from step will be 0.
//* Otherwise it will be non-zero.
//*
//DSEXIST EXEC PGM=IDCAMS
//SYSPRINT DD DUMMY
//SYSIN DD *
LISTCAT ENTRIES('@@HLQ@@.ZOASAMP.MY.JCL')
/*