Allocate New File
Below mentioned JCLs using IEBGENER or IEFBR14 will generate the required file with the DCB parameters requested.
//EMPTYFL EXEC PGM=IEBGENER
//SYSUT1 DD DUMMY,
// DCB=(LRECL=80,BLKSIZE=0,RECFM=FB,DSORG=PS)
//SYSUT2 DD DSN=XXXXX.YYYYY,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL(20,20),RLSE),
// DCB=(LRECL=80,BLKSIZE=0,RECFM=FB,DSORG=PS)
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD DUMMY
//EMPTYFL EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSDUMP DD SYSOUT=*
//DD01 DD DSN=XXXXX.YYYYY,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(CYL(20,20),RLSE),UNIT=SYSDA,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=0)
//*
Best Practices
- Always use COUNT(1) or PRINT CHARACTER COUNT(1) to limit processing to one record.
- Standardize on one utility per shop (e.g., IDCAMS or ICETOOL) for consistency.
- Ensure DISP=SHR on input DD to avoid allocation errors.
- Test return codes thoroughly in your environment, as some sites map RC 12 to empty files with ICETOOL.
- Document the utility and RC mapping in your JCL standards.
By incorporating these utilities into your JCL, you can reliably detect empty datasets and orchestrate downstream processing with clear, maintainable steps.
Empty Existing File
Below mentioned JCLs will remove the content of an existing file without deleting it.
1. One way is to use a COBOL program that opens the file in input mode and reads until end-of-file, then reopens it in output mode and closes it—effectively emptying the file.
Alternatively, use JCL with IEBGENER as shown below:
//EMPTYFL EXEC PGM=IEBGENER
//SYSUT1 DD DUMMY,
// DCB=(LRECL=80,BLKSIZE=0,RECFM=FB,DSORG=PS)
//SYSUT2 DD DSN=XXXXX.YYYYY,
// DISP=OLD
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD DUMMY
Here we have used a DUMMY file with attributes identical to the file we want to empty. The key is specifying DISP=OLD, which tells the system to keep the file and just overwrite its content (with nothing).
2. You can also use IDCAMS to achieve the same effect:
//EMPTYFL EXEC PGM=IDCAMS
//DDDMMY DD DUMMY
//DDOUT DD DSN=XXXXX.YYYYY,
// DISP=OLD
//SYSIN DD *
REPRO IFILE(DDDMMY) OFILE(DDOUT)
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
3. You can use SORT as well, though utilities like IDCAMS and IEBGENER are preferred for clarity and control.
//EMPTYFL EXEC PGM=SORT
//SORTIN DD DSN=XXXXX.YYYYY,DISP=SHR
//SORTOUT DD DSN=XXXXX.YYYYY,DISP=OLD
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OMIT COND=ALL
/*
Summary
Detecting and emptying files in JCL is essential for building robust, efficient, and error-free batch jobs. Whether you’re using IDCAMS, IEBGENER, or DFSORT, the key is knowing when and how to use them correctly. By doing so, you improve your mainframe job flows and prevent downstream errors caused by unexpected data conditions.