MainframeMaster

JCL Tutorial

Data Set Specification

Understanding how to specify and manage datasets in JCL

Progress0 of 0 lessons

Introduction to Data Set Specification

One of the primary purposes of JCL is to manage and connect datasets to your programs. The DD statement (Data Definition) provides the link between the logical files your program uses and the physical datasets on the system. Understanding data set specification is crucial for effective JCL programming.

This tutorial covers the essential parameters for specifying datasets in JCL, with a focus on the DSN and DISP parameters, which are among the most important and frequently used parameters in JCL.

DSN Parameter

The DSN (Data Set Name) parameter identifies the name of the dataset to be used in a job step. It specifies which dataset will be allocated to the DD statement.

Basic Syntax:

jcl
1
//ddname DD DSN=dataset.name,other-parameters

Key points about data set names:

  • A dataset name can have up to 44 characters
  • It can contain letters (A-Z), numbers (0-9), and special characters (@, #, $)
  • Segments of the name are separated by periods
  • Each segment (qualifier) can be 1-8 characters long
  • A dataset name must start with a letter or one of the special characters (@, #, $)
  • The first character of each qualifier must also be a letter or special character

High-Level Qualifiers:

The first segment of a dataset name is called the high-level qualifier. In many organizations, high-level qualifiers are standardized and often indicate who owns the dataset (e.g., a department or user ID).

Examples of valid data set names:

jcl
1
2
3
//DD1 DD DSN=SYS1.LINKLIB,DISP=SHR //DD2 DD DSN=PAYROLL.MASTER.FILE,DISP=OLD //DD3 DD DSN=USERX.TEST.DATA,DISP=SHR

Temporary Dataset Names

You can create temporary datasets that exist only for the duration of your job by using special naming conventions:

  • &&tempname - A temporary dataset that exists only for the duration of the job
  • DSN=&SYSUID..tempname - Using system symbols to create unique dataset names
jcl
1
2
3
//TEMPDD DD DSN=&&TEMP,DISP=(NEW,PASS), // SPACE=(TRK,(10,5)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)

Generation Data Groups (GDG)

Generation Data Groups allow you to manage multiple versions of a dataset. Each new version is a "generation" and is referenced by a relative number:

jcl
1
2
3
//GDGDD DD DSN=PAYROLL.MONTHLY(0),DISP=SHR // Current generation //GDGDD DD DSN=PAYROLL.MONTHLY(-1),DISP=SHR // Previous generation //GDGDD DD DSN=PAYROLL.MONTHLY(+1),DISP=(NEW,CATLG) // New generation

DISP Parameter

The DISP (Disposition) parameter is one of the most critical parameters in JCL. It serves three main purposes:

  1. Indicates the current status of the dataset (NEW, OLD, SHR, MOD)
  2. Specifies what to do with the dataset when the step ends normally (KEEP, CATLG, DELETE, PASS)
  3. Specifies what to do with the dataset if the step abnormally terminates (KEEP, CATLG, DELETE)

Basic Syntax:

jcl
1
//ddname DD DSN=dataset.name,DISP=(status,normal-disp,abnormal-disp)

Dataset Status

The first subparameter of DISP indicates the current status of the dataset:

  • NEW - Create a new dataset
  • OLD - The dataset exists and you need exclusive access (no sharing)
  • SHR - The dataset exists and can be shared with other jobs (for reading)
  • MOD - The dataset exists and you want to add records to the end; if it doesn't exist, it will be created

Data Set Access Conflicts:

Using DISP=OLD requests exclusive access to a dataset. If another job is already using the dataset with DISP=OLD or DISP=MOD, your job will wait or fail depending on system settings.

Normal Termination Disposition

The second subparameter indicates what to do with the dataset if the job step ends normally:

  • KEEP - Keep the dataset (retain it on the volume)
  • CATLG - Catalog the dataset (make it available for future jobs)
  • DELETE - Delete the dataset (remove it from the system)
  • PASS - Pass the dataset to subsequent job steps in the same job

Abnormal Termination Disposition

The third subparameter indicates what to do with the dataset if the job step abnormally terminates:

  • KEEP - Keep the dataset even if the step fails
  • CATLG - Catalog the dataset even if the step fails
  • DELETE - Delete the dataset if the step fails

Note:

PASS is not valid as an abnormal termination disposition.

Creation of New Datasets (NEW)

When you create a new dataset with DISP=NEW, you must also specify additional parameters such as SPACE for allocation and often DCB for dataset characteristics.

The typical pattern for creating a new dataset is:

jcl
1
2
3
4
//NEWDD DD DSN=USER.NEW.DATASET, // DISP=(NEW,CATLG,DELETE), // SPACE=(allocation parameters), // DCB=(dataset characteristics)

Example of creating a new sequential dataset:

jcl
1
2
3
4
//SEQDD DD DSN=USER.SEQUENTIAL.DATA, // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(10,5)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)

Example of creating a new partitioned dataset (PDS):

jcl
1
2
3
4
//PDSDD DD DSN=USER.PARTITIONED.DATA, // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(10,5,5)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)

Note:

The third value in the SPACE parameter for a PDS (5 in the example) specifies the number of directory blocks. This is required for partitioned datasets to store member information.

Using Existing Datasets (OLD, SHR)

When you need to use an existing dataset, you specify either DISP=OLD (for exclusive access) or DISP=SHR (to allow sharing with other jobs).

Exclusive Access (OLD)

Use DISP=OLD when you need to update a dataset and no other job should access it concurrently:

jcl
1
2
//UPDATE DD DSN=PAYROLL.MASTER,DISP=(OLD,KEEP) //UPDATE DD DSN=PAYROLL.MASTER,DISP=(OLD,CATLG,KEEP)

Shared Access (SHR)

Use DISP=SHR when you only need to read a dataset or when multiple jobs can safely access it simultaneously:

jcl
1
2
3
//READDD DD DSN=PAYROLL.MASTER,DISP=SHR //READDD DD DSN=PAYROLL.MASTER,DISP=(SHR,KEEP) //READDD DD DSN=PAYROLL.MASTER,DISP=(SHR,KEEP,KEEP)

Important:

Even with DISP=SHR, if one job is updating a dataset, other jobs attempting to update the same dataset may face conflicts. SHR is primarily intended for multiple readers or a mixture of readers and a single writer.

Dataset Disposition (KEEP, CATLG, DELETE)

Properly managing dataset disposition is crucial for efficient job flow and to prevent unintended data loss.

KEEP

The KEEP disposition maintains a dataset on the volume but does not catalog it:

jcl
1
2
//DD1 DD DSN=USER.TEMP.DATA,DISP=(NEW,KEEP) //DD2 DD DSN=USER.TEMP.DATA,DISP=(OLD,KEEP)

A dataset with KEEP disposition can only be accessed in subsequent jobs by specifying both its name and volume:

jcl
1
//DD3 DD DSN=USER.TEMP.DATA,DISP=OLD,VOL=SER=VOLID1

CATLG

The CATLG disposition catalogs a dataset, which makes it easily accessible in subsequent jobs:

jcl
1
2
//DD1 DD DSN=USER.IMPORTANT.DATA,DISP=(NEW,CATLG) //DD2 DD DSN=USER.IMPORTANT.DATA,DISP=(MOD,CATLG)

Once cataloged, datasets can be accessed without specifying the volume:

jcl
1
//DD3 DD DSN=USER.IMPORTANT.DATA,DISP=SHR

DELETE

The DELETE disposition removes a dataset from the system:

jcl
1
2
//DD1 DD DSN=USER.ONETIME.DATA,DISP=(NEW,DELETE) //DD2 DD DSN=USER.OBSOLETE.DATA,DISP=(OLD,DELETE)

DELETE is particularly useful for temporary datasets that are no longer needed after the job completes.

Warning:

Be careful with DELETE disposition, especially with existing datasets. Always ensure you have proper backups before deleting important data. In production environments, dataset deletion is often restricted and carefully managed.

Temporary Datasets

Temporary datasets exist only for the duration of the job or job step. They are useful for intermediate data processing that doesn't need to be preserved after the job completes.

Using Temporary Names with Ampersands

The most common way to create a temporary dataset is to use a name with double ampersands (&&):

jcl
1
2
3
//TEMPDD DD DSN=&&TEMP,DISP=(NEW,PASS), // SPACE=(TRK,(10,5)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)

This temporary dataset can be referenced in subsequent steps of the same job:

jcl
1
2
3
4
5
//STEP1 EXEC PGM=PROGRAM1 //TEMPOUT DD DSN=&&TEMP,DISP=(NEW,PASS), // SPACE=(TRK,(10,5)),DCB=(RECFM=FB,LRECL=80) //STEP2 EXEC PGM=PROGRAM2 //TEMPIN DD DSN=&&TEMP,DISP=(OLD,DELETE)

Using DSN=* (In-stream Data)

Another form of temporary data is in-stream data, specified with DSN=* or the * shorthand:

jcl
1
2
3
4
5
//SYSIN DD * Data line 1 Data line 2 Data line 3 /*

This is equivalent to:

jcl
1
//SYSIN DD DSN=*,DISP=(NEW,DELETE)

Using DISP=(NEW,PASS)

You can create a regular dataset with DISP=(NEW,PASS) to make it temporary for just the current job:

jcl
1
2
3
//DD1 DD DSN=USER.TEMP.DATA, // DISP=(NEW,PASS), // SPACE=(TRK,(5,1))

Datasets created with DISP=(NEW,PASS) are automatically deleted at the end of the job unless a later step changes the disposition to KEEP or CATLG.

Common JCL Data Set Specification Patterns

1. Creating and Cataloging a New Dataset

jcl
1
2
3
4
//NEWDS DD DSN=USER.NEW.DATASET, // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(10,5)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)

2. Adding Records to an Existing Dataset

jcl
1
2
//APPEND DD DSN=USER.EXISTING.DATASET, // DISP=(MOD,CATLG,KEEP)

3. Reading from a Dataset

jcl
1
//INPUT DD DSN=USER.INPUT.DATASET,DISP=SHR

4. Creating a Temporary Dataset for Job Steps

jcl
1
2
3
4
//TEMP DD DSN=&&TEMPDS, // DISP=(NEW,PASS), // SPACE=(TRK,(5,1)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)

5. Creating a GDG Dataset

jcl
1
2
3
4
//GDGDS DD DSN=USER.MONTHLY.DATA(+1), // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(50,10)), // DCB=(RECFM=FB,LRECL=100,BLKSIZE=1000)

6. Referencing a Specific Version of a GDG

jcl
1
//OLDGDG DD DSN=USER.MONTHLY.DATA(-1),DISP=SHR

Best Practices

  • Always specify a complete DISP parameter - Include all three subparameters (status, normal, abnormal) for clarity and safety
  • Use SHR instead of OLD when possible - This allows better parallel processing and reduces contention
  • Be careful with DELETE disposition - Double-check before using DELETE on important datasets
  • Use descriptive dataset names - Follow your organization's naming standards and use names that clearly indicate the dataset's purpose
  • Consider using temporary datasets for intermediate results - This keeps the catalog clean and saves disk space
  • Document special dataset requirements - Include comments in your JCL to explain unusual dataset specifications

Summary

Data set specification is a fundamental aspect of JCL programming. The DSN and DISP parameters are essential for managing datasets within your jobs.

  • The DSN parameter identifies the dataset to be used by name
  • The DISP parameter controls dataset status and disposition
  • NEW, OLD, SHR, and MOD specify how a dataset is initially accessed
  • KEEP, CATLG, DELETE, and PASS control what happens to a dataset after the step completes
  • Temporary datasets provide storage for intermediate processing steps

Understanding these concepts allows you to effectively manage data in your JCL jobs, ensuring that your programs have access to the right data at the right time.

Practice Exercise

Create JCL DD statements for each of the following scenarios:

  1. Create a new sequential dataset called USER.NEW.DATA with fixed-block records of length 80, allocating 5 tracks with 2 tracks of secondary space. The dataset should be cataloged if the step completes successfully or deleted if it fails.
  2. Read from an existing dataset called PROD.MASTER.FILE that can be shared with other jobs.
  3. Create a temporary dataset to be used by multiple steps in the same job.
  4. Append records to an existing dataset called REPORT.MONTHLY.DATA.
  5. Create a new generation (+1) of a GDG dataset called USER.BACKUP.DATA.