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
/*

7 comments:

IBM Mainframe Training said...

Really good work, commendable.
It is a nice place to share the information and knowledge with others.
The data should be updated from time to time so that we get new and useful information.

Thanks allot!

Kumaresh T said...

Thanks for your encouraging words and suggestions !!

SWATHY KRISHNAN said...

Hi Aji
But your code wont work if the dataset doesn't exist....

Kumaresh T said...

Thanks for your comments Swathi Krishnan.

If the data set doesn't exist, the JCL will go down with a JCL ERROR.

HTH !!

Anonymous said...

Thanks for the tip!!! It was helpful!!

Siva said...

Hi AJ,

Can I check if a particular line is empty
?

Here my requirement is to check whether a report is empty or not. But the report always contains header.

Kumaresh T said...

Siva,

If you are sure about having the header always in your file, you can split the file into two, with the first file with just the header and the 2nd file with rest of the data rows. After splitting the file, you can check if the 2nd file has any rows (check for empty file), just as decribed in this blog post.

HTH !!