Search code examples
mainframejcl

Pass JCL symbol to in-stream data sets


I'm trying to create and delete a dataset with a JCL symbol in the dataset name this way:

//    SET DATE=20110809
//* DELETE DATASET
//DEL01 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN    DD *
           DELETE DATASET.TEMP.&DATE                PURGE
           SET MAXCC = 0
//* CREATE DATASET
//STEP01   EXEC PGM=IEFBR14
//DELDD    DD DSN=DATASET.TEMP.&DATE,
//            DISP=(NEW,CATLG,DELETE)

The problem is that I can not use a JCL symbol within a instream (SYSIN DD *). I can't be sure if the dataset already exists so I can not just use DISP=(MOD,DELETE,DELETE). Is there another way to delete the data set?


Solution

  • JCL does not support symbol substitution within inline data as you have found out...

    The following should work for you:

    //DEL01   EXEC PGM=IEFBR14          
    //DELDD    DD DSN=DATASET.TEMP.&DATE, 
    //         DISP=(MOD,DELETE,DELETE), 
    //         SPACE=(TRK,0)             
    

    Add a SPACE parameter. If the dataset doesn't exist it will be created because of the MOD disposition. Then it will be DELETED upon step completion. Net result is that after this step, the named dataset will not exist.

    The only real problem that I see is with:

    //    SET DATE=20110809
    

    The date you are giving is 8 characters long (maximum qualifier length) but does not begin with an alphabetic or national character (it begins with a numeric). This will result in an invalid dataset name. The dataset DATE qualifer will become too long if you just add an alpha prefix to it. The common approach to this problem is to use Julian dates as in: 2011221. Prefix the Julian Date with either an alpah or national character as in: D2011221. So your SET directive would become something like:

    //    SET DATE=D2011221
    

    And all should work out.