check for an empty file in jcl

File empty condition in JCL can be identified with the help of following two Utilities

1) IDCAMS utility
2) IEBPTPCH --> IBM Print puch utility

Check for an empty file using IDCAMS utility

Lets start with understanding how IDCAMS does file empty check condition. Following is the JCL code to identify whether the file is empty or not using IDCAMS utility.

//CHKEMPTY JOB (X,XX,XXX),'CHK EMPT', MSGCLASS=T,CLASS=S,REGION=M
//STEP010 EXEC PGM=IDCAMS
//IFILE DD DSN=file_name_here,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
PRINT INFILE(INFILE) CHARACTER COUNT(1)
/*
//******************* END OF JOB ********************************************

Above step will sets the return codes (RC) as follows:

a) If the dataset has atleast one record then above step SETS RC=0000
b) If the dataset is empty then above step SETS RC=0004
c) If the dataset set is not cataloged then SETS RC=0012

Based on the return codes returned by IDCAMS utility we can control the execution of subsequent steps by using COND parameter in the subsequent steps




IDCAMS utility would give JCL error if the file is coded with DD statement and the PRINT command referencing the DD name of file.

To avoid the JCL error, remove the DD statement and code the file name directly along with PRINT command as shown in the below JCL example.

//CHKEMPTY JOB (X,XX,XXX),'CHK EMPT', MSGCLASS=T,CLASS=S,REGION=M
//STEP010 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
PRINT INFILE(file_name_here) CHARACTER COUNT(1)
/*
//*************** END OF JOB **************************


Check for an empty file using IEBPTPCH utility

IEBPTPCH is an IBM' print punch utility. Following is the code

//CHKEMPTY JOB (X,XX,XXX),'MAIL ATT'MSGCLASS=F,CLASS=D,REGION=M
//PS010 EXEC PGM=IEBPTPCH *CHECK FOR EMPTY FILE *
//*********************************************************************
//SYSUT1 DD DSN=Your_File_Name_Here,DISP=SHR
//SYSUT2 DD DUMMY
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
PRINT TYPORG=PS
/*
//**************** END OF JOB *************************************

Above step will sets the return codes (RC) as follows:

a) If the dataset has atleast one records then above step (IEBPTPCH) SETS RC=0000
b) If the dataset is empty then above step (IEBPTPCH) SETS RC=0004


More by this Author


Comments

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working