Contents


Overview

Skill Level: Intermediate

The recipe gives a way to verify if a data set does not have data and do not cause the job to abend when coding mainframe JCLs.

Ingredients

Understanding of JCLs with DD/EXEC/IF statements. Basic knowledge of DFSORT utilities.

Step-by-step

  1. Introduction

    In Mainframe, applications are constructed based on jobs. Jobs are coded in JCL(Job Control Language). We code some job steps in order to complete some business logic. Sometimes we need to determine if a dataset is empty – without any data in it. There are different ways of doing it, such as Utility IDCAMS etc. However if we have restrictions: 1 the dataset name can be generic with variables; 2 whether the dataset is empty or not does not cause the job to abend. Things are different.

  2. Sample codes

    Here I use sort utility ICETOOL to complete the task. The below is the sample codes:

    //*—————————————————————-
    //* STEP010: CHECK IF INPUT DATASET &QLFR1..&QLFR2..DATA IS EMPTY
    //* SET RC=04 IF THE ‘IN’ DATA SET IS EMPTY, OR
    //* SET RC=0 IF THE ‘IN’ DATA SET IS NOT EMPTY
    //*—————————————————————-
    //STEP010 EXEC PGM=ICETOOL
    //TOOLMSG DD SYSOUT=*
    //DFSMSG DD SYSOUT=*
    //IN DD DSN=&QLFR1..&QLFR2..DATA,
    // DISP=SHR
    //TOOLIN DD *
    COUNT FROM(IN) RC4 EMPTY
    /*
    //*
    // IF (STEP010.RC = 04) THEN
    //* Here add the process when the dataset is empty
    // ELSE
    //* Here add the process when the dataset is NOT empty
    // ENDIF

    in the sample codes, what you need to change is to fill your own dataset name in the DD statement where ‘IN’ is specified. You do not need to change anything for two DD statements SYSOUT. In ‘COUNT FROM(IN) RC4 EMPTY’, RC4 means return code=4. Here you can specify other two return codes in fact in addition to RC4: RC8 and RC12. But as you know, RC8 and RC12 will break JCL run. So when you want to deliberately fail a job run if the dataset is empty, you can use RC8 or RC12.

Join The Discussion