JCL Realtime (Scenario based) Interview Questions (31 - 40)

31. How do you create a dataset in a JCL with the same file organization as that of another existing dataset?

  • Method1: - The LIKE parameter copies the DCB attributes (RECFM, LRECL, BLKSIZE) from an existing dataset.
    //STEP1 EXEC PGM=IEFBR14
    //NEWDS  DD DSN=NEW.DATASET,DISP=(NEW,CATLG,DELETE),
    //            LIKE=EXISTING.DATASET
  • Method2: - Use IEBGENER, passing the existing file in SYSUT1 and the new file in SYSUT2. Specify DCB=*.SYSUT1 to inherit the same DCB as that of the SYSUT1 dataset.
    //STEP2 EXEC PGM=IEFBR14
    //NEWDS  DD DSN=NEW.DATASET,DISP=(NEW,CATLG,DELETE),
    //            DCB=*.STEP1.OLDDS

32. How do you access an uncataloged dataset in a JCL?

To access an uncataloged dataset, you must specify the volume and unit information explicitly in the DD statement.

//STEP1 EXEC PGM=MYPROG
//DD1   DD DSN=UNCAT.DATASET,DISP=SHR,
//           VOL=SER=VOL001,UNIT=SYSDA

33. A JCL has 2 steps. How to code the JCL such that if step1 abends, then step2 runs. Else, job terminates with step1?

To run STEP2 only if STEP1 abends, use the COND=ONLY parameter in STEP2.

//JOBNAME JOB ...
//STEP1  EXEC PGM=MYPROG
//STEP2  EXEC PGM=RECOVERY,COND=ONLY

34. How to do automated RESTART when a job abends?

To enable automatic restart of a job after an abend, use one of the following methods:

  • Using a JOB Scheduler - Tools like Control-M, CA-7, Tivoli Workload Scheduler can automatically restart abended jobs based on predefined rules.
  • Using the RD=R Parameter in JOB Statement - This allows the job to automatically restart after an abend.
  • Checkpoint Restart - If the program supports checkpointing, the job can restart from the last checkpoint.

35. A JCL has 10 steps. How to run step3 and step7 (only) without using COND parameter or IF-THEN-ELSE?

Using IEBEDIT in a JCL, you can execute specific steps from another JCL. In the JCL mentioned above, the input JCL containing 10 steps is located in MY.JCL.LIBRARY(MYJOB). The steps specified in SYSIN for IEBEDIT are STEP3 and STEP7, which means that only those two steps will be executed.

//EXTRACT  JOB ...
//STEP1    EXEC PGM=IEBEDIT
//SYSUT1   DD DSN=MY.JCL.LIBRARY(MYJOB),DISP=SHR  
//SYSUT2   DD SYSOUT=(*,INTRDR)  
//SYSIN    DD *
   EDIT TYPE=INCLUDE,MEMBER=(STEP3,STEP7)
/*

36. When does a dataset go uncataloged?

  • DISP=UNCATLG Used - If DISP=UNCATLG is specified, the dataset is removed from the catalog but remains on disk.
  • When a dataset is defined with DISP = (NEW, KEEP) at creation, the handling of generations in a GDG depends on how the GDG base is defined. If the GDG base is defined with the NOEMPTY parameter and the limit is reached, the least recent generation will be uncataloged. However, if the EMPTY option is specified, all generations will be uncataloged once the limit is reached.

37. How can a GDG base be created in a JCL. What is the difference between EMPTY and SCRATCH parameter while defining/altering GDG base?

A GDG (Generation Data Group) base is created using the IDCAMS DEFINE GDG command.

//STEP1 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN    DD *
  DEFINE GDG (NAME(MY.GDG.BASE) -
              LIMIT(5) -
              NOEMPTY -
              SCRATCH)
/*
  • EMPTY - Deletes all generations when the LIMIT is exceeded.
  • SCRATCH - Automatically deletes expired generations when they are uncataloged.

38. A dataset contains 2500 records. How can the last 1500 records copied to an output file?

You can use DFSORT or SYNCSORT to extract the last 1500 records from a 2500-record dataset.

//STEP1  EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=INPUT.DATASET,DISP=SHR
//SORTOUT DD DSN=OUTPUT.DATASET,
//           DISP=(NEW,CATLG,DELETE),
//           SPACE=(CYL,5),
//           DCB=(RECFM=FB,LRECL=80)
//SYSIN  DD *
  OPTION COPY
  OUTFIL FNAMES=SORTOUT,STARTREC=1001
/*

39. How can a file of 3000 records be split into 3 files each containing 100 records?

You can use DFSORT or SYNCSORT to split a file into three equal parts.

//STEP1  EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=INPUT.DATASET,DISP=SHR
//OUT1   DD DSN=OUTPUT.FILE1,DISP=(NEW,CATLG,DELETE),
//            SPACE=(CYL,5),DCB=(RECFM=FB,LRECL=80)
//OUT2   DD DSN=OUTPUT.FILE2,DISP=(NEW,CATLG,DELETE),
//            SPACE=(CYL,5),DCB=(RECFM=FB,LRECL=80)
//OUT3   DD DSN=OUTPUT.FILE3,DISP=(NEW,CATLG,DELETE),
//            SPACE=(CYL,5),DCB=(RECFM=FB,LRECL=80)
//SYSIN  DD *
  OPTION COPY
  OUTFIL FNAMES=OUT1,ENDREC=1000
  OUTFIL FNAMES=OUT2,STARTREC=1001,ENDREC=2000
  OUTFIL FNAMES=OUT3,STARTREC=2001,ENDREC=3000
/*

40. When can a job time-out occur? How to overcome that?

A job time-out (S322 abend) occurs when a job or step exceeds the CPU time limit specified in the TIME parameter.

Possible Causes of Time-Out:

  • Infinite Loops in the program.
  • Exceeding TIME Parameter Limit in JOB or EXEC statement.
  • Excessive Resource Usage, causing slow execution.
  • System-Level Timeout Limits set by JES or job scheduler.

How to Overcome Job Time-Out Issues:

  • Increase the TIME Parameter Limit: Set a higher CPU time limit or remove the limit (if permitted).
    //JOBNAME JOB ...,TIME=1440
  • Optimize the Program Logic: Fix infinite loops and optimize CPU-heavy operations.
  • Split Long-Running Jobs Into Multiple Steps: Break large jobs into smaller, restartable steps.