In this section, we will explore the concept of temporary data sets in JCL. Temporary data sets are used for intermediate storage during the execution of a job and are deleted automatically when the job completes. They are particularly useful for passing data between steps within the same job.

Key Concepts

  1. Definition: Temporary data sets are data sets that exist only for the duration of the job and are deleted once the job completes.
  2. Naming Convention: Temporary data sets are identified by names that start with two ampersands (&&).
  3. Scope: They are accessible only within the job in which they are created.

Creating Temporary Data Sets

To define a temporary data set in JCL, you use the DD statement with a name that starts with &&. Here is the basic syntax:

//TEMPDS   DD  DSN=&&TEMP, DISP=(NEW,PASS), ...

Example

Let's look at a practical example where we create a temporary data set and use it in subsequent steps.

//JOB1     JOB  (ACCT),'TEMP DATA SET EXAMPLE',CLASS=A,MSGCLASS=X
//STEP1    EXEC PGM=PROG1
//TEMPDS   DD  DSN=&&TEMP,DISP=(NEW,PASS),UNIT=SYSDA,SPACE=(CYL,(1,1)),DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
//SYSOUT   DD  SYSOUT=*
//STEP2    EXEC PGM=PROG2
//INPUT    DD  DSN=&&TEMP,DISP=(OLD,DELETE)
//SYSOUT   DD  SYSOUT=*

Explanation

  1. STEP1:

    • TEMPDS: Defines a temporary data set named &&TEMP. The DISP=(NEW,PASS) parameter indicates that the data set is newly created and will be passed to the next step.
    • UNIT=SYSDA: Specifies the device type.
    • SPACE=(CYL,(1,1)): Allocates space for the data set.
    • DCB=(RECFM=FB,LRECL=80,BLKSIZE=800): Defines the data control block parameters.
  2. STEP2:

    • INPUT: References the temporary data set &&TEMP created in STEP1. The DISP=(OLD,DELETE) parameter indicates that the data set is to be used as an existing data set and will be deleted after this step.

Practical Exercises

Exercise 1: Creating and Using a Temporary Data Set

Task: Write a JCL job that creates a temporary data set in the first step and uses it in the second step.

//JOB2     JOB  (ACCT),'TEMP DATA SET EXERCISE',CLASS=A,MSGCLASS=X
//STEP1    EXEC PGM=PROG1
//TEMPDS   DD  DSN=&&TEMP,DISP=(NEW,PASS),UNIT=SYSDA,SPACE=(CYL,(1,1)),DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
//SYSOUT   DD  SYSOUT=*
//STEP2    EXEC PGM=PROG2
//INPUT    DD  DSN=&&TEMP,DISP=(OLD,DELETE)
//SYSOUT   DD  SYSOUT=*

Solution Explanation:

  • STEP1: Creates a temporary data set &&TEMP with the necessary parameters.
  • STEP2: Uses the temporary data set &&TEMP and deletes it after use.

Exercise 2: Modifying a Temporary Data Set

Task: Modify the previous job to add a third step that reads the temporary data set again.

//JOB3     JOB  (ACCT),'MODIFY TEMP DATA SET',CLASS=A,MSGCLASS=X
//STEP1    EXEC PGM=PROG1
//TEMPDS   DD  DSN=&&TEMP,DISP=(NEW,PASS),UNIT=SYSDA,SPACE=(CYL,(1,1)),DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
//SYSOUT   DD  SYSOUT=*
//STEP2    EXEC PGM=PROG2
//INPUT    DD  DSN=&&TEMP,DISP=(OLD,PASS)
//SYSOUT   DD  SYSOUT=*
//STEP3    EXEC PGM=PROG3
//INPUT    DD  DSN=&&TEMP,DISP=(OLD,DELETE)
//SYSOUT   DD  SYSOUT=*

Solution Explanation:

  • STEP1: Creates the temporary data set &&TEMP.
  • STEP2: Uses the temporary data set &&TEMP and passes it to the next step.
  • STEP3: Reads the temporary data set &&TEMP again and deletes it after use.

Common Mistakes and Tips

  • Incorrect DISP Parameter: Ensure that the DISP parameter is correctly set to PASS when passing the data set between steps.
  • Naming Convention: Always start the name of a temporary data set with &&.
  • Scope Limitation: Remember that temporary data sets are only accessible within the job they are created in.

Conclusion

Temporary data sets are a powerful feature in JCL for managing intermediate data within a job. By understanding how to create, use, and manage these data sets, you can write more efficient and organized JCL jobs. In the next section, we will delve into referencing data sets, which will further enhance your ability to manage data within your JCL jobs.

© Copyright 2024. All rights reserved