Understanding how to specify and manage datasets in JCL
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.
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:
1//ddname DD DSN=dataset.name,other-parameters
Key points about data set names:
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:
123//DD1 DD DSN=SYS1.LINKLIB,DISP=SHR //DD2 DD DSN=PAYROLL.MASTER.FILE,DISP=OLD //DD3 DD DSN=USERX.TEST.DATA,DISP=SHR
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 jobDSN=&SYSUID..tempname
- Using system symbols to create unique dataset names123//TEMPDD DD DSN=&&TEMP,DISP=(NEW,PASS), // SPACE=(TRK,(10,5)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
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:
123//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
The DISP (Disposition) parameter is one of the most critical parameters in JCL. It serves three main purposes:
Basic Syntax:
1//ddname DD DSN=dataset.name,DISP=(status,normal-disp,abnormal-disp)
The first subparameter of DISP indicates the current status of the dataset:
NEW
- Create a new datasetOLD
- 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 createdData 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.
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 jobThe third subparameter indicates what to do with the dataset if the job step abnormally terminates:
KEEP
- Keep the dataset even if the step failsCATLG
- Catalog the dataset even if the step failsDELETE
- Delete the dataset if the step failsNote:
PASS is not valid as an abnormal termination disposition.
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:
1234//NEWDD DD DSN=USER.NEW.DATASET, // DISP=(NEW,CATLG,DELETE), // SPACE=(allocation parameters), // DCB=(dataset characteristics)
Example of creating a new sequential dataset:
1234//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):
1234//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.
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).
Use DISP=OLD when you need to update a dataset and no other job should access it concurrently:
12//UPDATE DD DSN=PAYROLL.MASTER,DISP=(OLD,KEEP) //UPDATE DD DSN=PAYROLL.MASTER,DISP=(OLD,CATLG,KEEP)
Use DISP=SHR when you only need to read a dataset or when multiple jobs can safely access it simultaneously:
123//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.
Properly managing dataset disposition is crucial for efficient job flow and to prevent unintended data loss.
The KEEP disposition maintains a dataset on the volume but does not catalog it:
12//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:
1//DD3 DD DSN=USER.TEMP.DATA,DISP=OLD,VOL=SER=VOLID1
The CATLG disposition catalogs a dataset, which makes it easily accessible in subsequent jobs:
12//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:
1//DD3 DD DSN=USER.IMPORTANT.DATA,DISP=SHR
The DELETE disposition removes a dataset from the system:
12//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 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.
The most common way to create a temporary dataset is to use a name with double ampersands (&&):
123//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:
12345//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)
Another form of temporary data is in-stream data, specified with DSN=* or the * shorthand:
12345//SYSIN DD * Data line 1 Data line 2 Data line 3 /*
This is equivalent to:
1//SYSIN DD DSN=*,DISP=(NEW,DELETE)
You can create a regular dataset with DISP=(NEW,PASS) to make it temporary for just the current job:
123//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.
1234//NEWDS DD DSN=USER.NEW.DATASET, // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(10,5)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
12//APPEND DD DSN=USER.EXISTING.DATASET, // DISP=(MOD,CATLG,KEEP)
1//INPUT DD DSN=USER.INPUT.DATASET,DISP=SHR
1234//TEMP DD DSN=&&TEMPDS, // DISP=(NEW,PASS), // SPACE=(TRK,(5,1)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
1234//GDGDS DD DSN=USER.MONTHLY.DATA(+1), // DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(50,10)), // DCB=(RECFM=FB,LRECL=100,BLKSIZE=1000)
1//OLDGDG DD DSN=USER.MONTHLY.DATA(-1),DISP=SHR
Data set specification is a fundamental aspect of JCL programming. The DSN and DISP parameters are essential for managing datasets within your jobs.
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.
Create JCL DD statements for each of the following scenarios: