Friday, March 5, 2010

JCL to find if a dataset is empty

In your batch job, if there is a need to check for empty dataset, you can do it using IDCAMS.


//*-------------------------------------------------------------------*/
//* This JCL is to find if a file is empty or not. If there are no */
//* records, the return-code will be 4. */
//*-------------------------------------------------------------------*/
//STEP01 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//IN1 DD DISP=SHR,DSN=your.dataset.name
//SYSIN DD *
PRINT INFILE(IN1) COUNT(001)
/*


If you have ICETOOL at your site, you can use that as well.

//*-------------------------------------------------------------------*/
//* This JCL is to find if a file is empty or not using ICETOOL. */
//* If there are no records, the return-code will be 12 */
//*-------------------------------------------------------------------*/
//STEP01 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DISP=SHR,DSN=your.dataset.name
//TOOLIN DD *
COUNT FROM(IN) EMPTY
/*