Check File is Empty
To check if a sequential File is empty is a usual step added in a job on practical scenario. The general use cases for doing the same are :
- To skip the further processing of the job if the file is empty
- To check if the file has arrived from an external source and if it contains data
- To check if the allocated file does not contain any junk data
This can be achieved with different JCL utilities such as ICETOOL, FILEAID, IDCAMS etc
A.Using ICETOOL
- Using EMPTY operand
EMPTY operand with COUNT can be used to find if the file is empty. By default, return 12 will be returned if the file is empty.
//EXEC PGM=ICETOOL |
Since return code above 4 is not considered ideal in a system and it may even fail in a scheduler unless specified, hence it is advised to override the return using RC command
//EXEC PGM=ICETOOL |
- Using HIGHER operand
HIGHER operand with COUNT can also be used to find if the file is empty. By default, return 12 will be returned if the file is empty. This return code can be overridden as above.
//EXEC PGM=ICETOOL |
The above two methods can be used along with MODE STOP to stop further processing of control cards in ICETOOL if the file is empty or continue the processing if records are present as shown below. Control Card 1 in the below step will not be processed if the file is empty and the return code will be RC4.
//EXEC PGM=ICETOOL |
B.Using IDCAMS
In IDCAMS, the PRINT operand and REPRO operand can be used to check the file.
If the file is empty, this step will give RC 04, else the return code will be 00.
//EXEC PGM=IDCAMS |
//EXEC PGM=IDCAMS |