July 30, 2018
How to check whether a sequential file (PS) or VSAM file is empty or not?
Sometimes we may face a requirement to check the file is empty or not, if it is empty stop the process other wise proceed with further steps using JCL. Here are some of the commonly used methods to check whether a Physical Sequential (PS) or VSAM File is empty or not.
1.
By Using IDCAMS utility we can check whether the file is empty or not. If the return code is 4 (RC=4), then it is considered as empty.
Here is the JCL for this purpose
//MG9908EM JOB 0000,'TEST',CLASS=6,MSGCLASS=X,NOTIFY=&SYSUID //M010 EXEC PGM=IDCAMS //INFIL01 DD DSN=MG9908.TEST.EMPTY.F001,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSIN DD DATA PRINT INFILE(INFIL01) COUNT(1) /*
2.
By using IDCAMS repro also empty check can be done.
If the return code is 4 (RC=4), then the file is empty.
//M030 EXEC PGM=IDCAMS //INFIL01 DD DSN= MG9908.TEST.EMPTY.F001,DISP=SHR //OUTFL01 DD DSN= MG9908.TEST.EMPTY.F002,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSIN DD * REPRO INFILE(INFIL01) OUTFILE(OUTFL01) COUNT(1) /*
3.
By using ICETOOL
//M020 EXEC PGM=ICETOOL //INFILE02 DD DSN= MG9908.TEST.EMPTY.F001,DISP=SHR //TOOLMSG DD SYSOUT=* //DFSMSG DD SYSOUT=* //TOOLIN DD DATA COUNT FROM(INFILE02) EMPTY /*
If the return code is Zero (RC=0) then file is not empty otherwise it is empty and return code would be 12 if it is empty .