Monday, September 26, 2011

JCL: To check if a sequential file is empty


Below is an easy way to check if a sequential file is empty.

//STEP010   EXEC PGM=IDCAMS                
//SYSPRINT  DD  SYSOUT=*                  
//INFILE    DD DSN=xxxxxxx.xxxx,DISP=SHR  
//SYSIN     DD  *                          
 PRINT INFILE(INFILE) CHARACTER COUNT(1)  
/*                                        

This step sets RC as follows :

SETS RC=0000 IF DATASET HAS RECORDS  
SETS RC=0004 IF DATASET IS EMPTY      
SETS RC=0012 IF DATASET IS NOT CATALOGED



If the file is not cataloged you would get a JCL error if the IDCAMS is coded with a DD statement and the PRINT command referencing the INFILE as shown.

What you would need to avoid this would be to remove the DD statement and use INDATASET(xxxxxxx.xxxx) on the PRINT command. Then you can check if the file is cataloged:

//STEP010   EXEC PGM=IDCAMS                
//SYSPRINT  DD  SYSOUT=*                  
//SYSIN     DD  *                          
 PRINT INDATASET(xxxxxxx.xxxx) CHARACTER COUNT(1)  
/*        

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.