JCL

EMPTY File condition check using JCL utilities

If you have a requirement to check Empty File before applying certain operations then it can be done using ICETOOL or FILEAID or IDCAMS or IEBPTPCH or ISRSUPC or SORT utilities.
The following requirements can be met using below mentioned JCL utilities:
1. Need to check if a data set is empty or not. If it’s empty I want to skip all other steps.
2. Need to skip certain steps in my job if the input is empty. This would be easiest if a utility would generate a non-zero RC if the input is empty.
3. I have several datasets that I need to sort together. How can I terminate if the total count of records in these data sets is greater than 5000?
4. I have a file that always has a header and trailer record and may or may not have data records OR I have an input file that always has a header and trailer and/or some data records but I want to empty this existing input file before the next set of operations.

Empty File check using – ICETOOL

You can use ICETOOL’s COUNT operator to set a return code of 12, 8, or 4 if a specified data set is EMPTY, NOTEMPTY, HIGHER(n), LOWER(n), EQUAL(n), or NOTEQUAL(n), where n is a specified number of records (for example, 5000). If RC4 operand is specified, ICETOOL sets RC=4. RC8 operand, ICETOOL sets RC=8. RC12 operand or don’t use the RC4 or RC8 operand, ICETOOL sets RC=12.

EMPTY Operation

The EMPTY operand of COUNT is used to stop STEP2 from being executed if the IN data set is empty. ICETOOL sets RC=8 (because the RC8 operand is specified) if the IN data set is empty, or RC=0 if the IN data set, is not empty. ICETOOL only reads one record to determine if the data set is empty or not empty, regardless of how many records there are in the data set.

 //EMPTYCHK EXEC PGM=ICETOOL
 //TOOLMSG DD SYSOUT=*
 //DFSMSG DD SYSOUT=*
 //IN DD DSN=…
 //TOOLIN DD *
 SET RC=8 IF THE 'IN' DATA SET IS EMPTY, OR
 SET RC=0 IF THE 'IN' DATA SET IS NOT EMPTY
 COUNT FROM(IN) EMPTY RC8
 /*
 // IF STEP1.RC = 0 THEN
 //* STEP2 WILL RUN IF 'IN' IS NOT EMPTY
 //* STEP2 WILL NOT RUN IF 'IN' IS EMPTY
 //STEP2 EXEC …
 …
 // ENDIF 

EMPTY Operation with OMIT: The EMPTY operand of COUNT is used to stop S2 from being executed if the INPUT data set doesn’t have any data records between the header and trailer. An OMIT statement is used with COUNT to delete the header and trailer record, leaving only the data records as a subset of the INPUT data set. ICETOOL sets RC=4 (because the RC4 operand is specified) if the subset of records is empty, or RC=0 if the subset of records is not empty.

 //EMPTYCHK EXEC PGM=ICETOOL
 //TOOLMSG DD SYSOUT=*
 //DFSMSG DD SYSOUT=*
 //INPUT DD DSN=…
 //TOOLIN DD *
 * SET RC=4 IF 'INPUT' ONLY HAS A HEADER AND TRAILER, OR
 * SET RC=0 IF 'INPUT' HAS DATA RECORDS.
   COUNT FROM(INPUT) EMPTY USING(HDTL) RC4
 /*
 //HDTLCNTL DD *
   OMIT COND=(1,6,CH,EQ,C'HEADER',OR,1,7,CH,EQ,C'TRAILER')
 /*
 // IF S1.RC = 0 THEN
 //* S2 WILL RUN IF 'IN' IS NOT EMPTY 
 //* S2 WILL NOT RUN IF 'IN' IS EMPTY
 //S2 EXEC …
 …
 // ENDIF 

HIGHER(n) Operation

Skip a SORT operation if the count of records in the data sets is greater than 5000.

 //EMPTYCHK EXEC PGM=ICETOOL
 //TOOLMSG DD SYSOUT=*
 //DFSMSG DD SYSOUT=*
 //CONCAT DD DSN=…
 // DD DSN=…
 // DD DSN=…
 //OUT DD DSN=…
 //TOOLIN DD *
 * SORT THE 'CONCAT' DATA SETS ONLY IF THEY
 * HAVE LE 5000 RECORDS
   MODE STOP
   COUNT FROM(CONCAT) HIGHER(5000)
   SORT FROM(CONCAT) TO(OUT) USING(CTL1)
 /*
 //CTL1CNTL DD *
   SORT FIELDS=(25,8,BI,A)
 /* 

Empty File check using – FILEAID

 //EMPTYCHK EXEC PGM=FILEAID 
 //INPUT    DD DSN=XXXXXXX.INFILE,DISP=SHR
 //OUTPUT   DD DSN=DUMMY,
 //         DISP=(NEW,CATLG,DELETE),
 //         UNIT=SYSDA
 //SYSOUT   DD *
 //SYSPRINT DD SYSOUT=*
 //SYSLIST  DD SYSOUT=*
 //SYSTOTAL DD SYSOUT=*
 //SYSIN    DD DUMMY

OR

//EMPTYCHK EXEC PGM=FILEAID,REGION=0M           
//SYSPRINT DD SYSOUT=*                         
//DD01     DD DSN=XXXXXXX.INFILE,
//            DISP=SHR   
//DD01O    DD SYSOUT=*                         
//SYSIN    DD *                                 
$$DD01 COPY                                     
//*

If the input file is empty, then this step will give RC = ’08’. If it is not empty, then this step will give RC = 0. Trapping the return code of this step one can say whether the input was empty.

Empty File check using – IEBPTPCH

//EMPTYCHK EXEC PGM=IEBPTPCH         
//SYSUT1   DD DSN=XXXXXXX.INFILE,
//            DISP=SHR               
//SYSUT2   DD DUMMY                   
//SYSPRINT DD SYSOUT=*               
//SYSIN    DD *                       
 PRINT                               
//* 

If the input file is empty, then this step will give RC = ’04’. If it is not empty, then this step will give RC = 0. Trapping the return code of this step one can say whether the input was empty.

Empty File check using – IDCAMS

//EMPTYCHK EXEC PGM=IDCAMS
//INPUT    DD DSN=XXXXXXX.INFILE,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSIN    DD *
   PRINT INFILE(INPUT) CHARACTER COUNT(1)
/*

If the input file is empty, then this step will give RC = 4. If it is not empty, then this step will give RC = 0. Trapping the return code of this step one can say whether the input was empty.

Empty File check using – ICETOOL

//EMPTYCHK EXEC PGM=ICETOOL         
//*                                   
//TOOLMSG  DD SYSOUT=*               
//DFSMSG   DD SYSOUT=*               
//IN       DD DSN=XXXXXXX.INFILE,
//            DISP=SHR
//TOOLIN DD *
  COUNT FROM(IN) EMPTY
//*

If the input file is empty, then this step will give RC = 12. If it is not empty, then this step will give RC = 0. Trapping the return code of this step one can say whether the input was empty.

Empty File check using – SORT

//EMPTYCHK EXEC  PGM=SORT,PARM='NULLOUT=RC4'   
//SYSOUT   DD SYSOUT=*                         
//SORTIN   DD DSN=XXXXXXX.INFILE,
//            DISP=SHR   
//SORTOUT  DD DUMMY                         
//SYSIN    DD *                                 
 SORT FIELDS=COPY                               
/*

If the input file is empty, then this step will give RC = 04. If it is not empty, then this step will give RC = 0. Trapping the return code of this step one can say whether the input was empty.

Empty File check using – ISRSUPC

//STEP0100 EXEC PGM=ISRSUPC                     
//SYSPRINT DD SYSOUT=*                 
//OUTDD    DD SYSOUT=*                 
//OLDDD    DD DUMMY
//NEWDD    DD DSN=YOUR FILE IN QUESTION,
//            DISP=SHR                             
//SYSIN    DD DUMMY

If the input file is empty, then this step will give RC = 28. If it is not empty, then this step will give RC = 01. Trapping the return code of this step one can say whether the input was empty.

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)
//*

Empty Existing File

Below mentioned JCLs will remove the content of an existing file without deleting it.

  1. You can do it in multiple ways e.g. Using a COBOL program that reads the file. Open the file as input and read until end-of-file. When AT END is reached, close the file. NOW – open the file as output and close the file. In the DD statement, specify DISP=OLD. You can do it via JCL using the below code
 //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 the attribute same as the file which we want to empty. The key is to specify DISP=OLD as this is an existing file. This step will empty the content of the existing file without deleting it.

2. You can use IDCAMS the same operation will be done using IDCAMS. This step will empty the content of the existing file without deleting it.

//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 to achieve the above results but I would recommend using IBM utilities like IDCAMS or IEBGRNER.

//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                                   
/*   

Read JCL blogs : Click Here SYNCSORT Manual : Click Here

Admin

Share
Published by
Admin

Recent Posts

Increase Transparency and Collaboration Product Backlog

A well-maintained product backlog is crucial for successful product development. It serves as a single…

2 months ago

Product Backlog – Incremental value to the customer

Incremental value to the customer refers to the gradual delivery of small, functional parts of…

2 months ago

Product Market, Customer’s Desire, Need, and Challenges

A Product Market refers to the group of potential customers who might be interested in…

2 months ago

PAL-EBM Professional Agile Leadership – EBM Certification

The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…

5 months ago

PAL I Professional Agile Leadership Certification

The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…

5 months ago

Scrum Master Certification: CSM, PSM, SSM

Choosing the right Scrum Master Certification depends on your current experience and career goals. If…

7 months ago