MainframeMaster

Using DFSORT with Cataloged Datasets

On z/OS, datasets are often cataloged so they can be referred to by name without specifying a volume. When you use DFSORT with cataloged datasets, you allocate SORTIN, SORTOUT, or SYSIN to existing or new cataloged datasets (or PDS members). This page explains what "cataloged" means in this context, how to reference cataloged datasets in your JCL, and how DISP and cataloging interact for input, output, and SYSIN.

Environment Setup
Progress0 of 0 lessons

What Is a Cataloged Dataset?

A cataloged dataset is one that is registered in the system catalog. The catalog is a system structure that maps dataset names to their location (volume, unit, and other attributes). When you reference a dataset by DSN= (dataset name) in JCL, the system can look up that name in the catalog to find the dataset. So you do not need to specify VOL=SER= for cataloged datasets—the catalog tells the system where they are. Most permanent (persistent) datasets in a shop are cataloged so that jobs and users can refer to them by a stable name.

When you create a new dataset and want it to be findable by name in the future, you catalog it by using DISP=(NEW,CATLG,...) or by running a separate catalog step. Once cataloged, the next time you use DSN=that.name, the system will find it from the catalog.

Using Cataloged Datasets for SORTIN

Your input dataset (SORTIN) usually already exists and is often cataloged. You reference it by name and use DISP=SHR so your job can read it. SHR (share) allows other jobs to read (or in some cases update) the same dataset at the same time, which is typical for input. Example:

jcl
1
//SORTIN DD DSN=PROD.DAILY.TRANSACTIONS,DISP=SHR

The system finds PROD.DAILY.TRANSACTIONS from the catalog. You do not need to know the volume. The dataset must exist before the step runs. If the dataset is not cataloged, you would need to supply VOL=SER= (and possibly UNIT=) so the system can find it, or catalog it first.

If your shop requires exclusive access to the input (e.g. for consistency), you might use DISP=OLD instead of SHR. OLD means no other job can open the dataset while yours has it. For read-only sort input, SHR is more common.

Creating and Cataloging SORTOUT

The output dataset (SORTOUT) is often new. You create it in the same step and usually want it cataloged so that later jobs or users can reference it by name. You use DISP=(NEW,CATLG,DELETE) (or CATLG,KEEP for the abnormal case). NEW creates the dataset; CATLG adds it to the catalog; the third parameter (DELETE or KEEP) says what to do if the step abends—delete the dataset or keep it. Example:

jcl
1
2
//SORTOUT DD DSN=PROD.DAILY.SORTED,DISP=(NEW,CATLG,DELETE), // SPACE=(CYL,(10,5)),DCB=(RECFM=FB,LRECL=80,BLKSIZE=27920)

After a normal completion, PROD.DAILY.SORTED exists and is cataloged. Any later job can use DSN=PROD.DAILY.SORTED,DISP=SHR to read it. The high-level qualifier (e.g. PROD) may need to match your user ID or a group prefix, depending on your site's catalog and security setup.

Using Cataloged Datasets or Members for SYSIN

SYSIN can point to a cataloged dataset instead of in-stream data. Common cases:

  • Sequential dataset: //SYSIN DD DSN=MY.CNTL.SORTIN,DISP=SHR — The dataset MY.CNTL.SORTIN contains the control statements and must exist and be cataloged.
  • PDS member: //SYSIN DD DSN=MY.PROCS(SORT1),DISP=SHR — The member SORT1 in the PDS MY.PROCS contains the control statements. The PDS is cataloged; the member is found by name. This is very common for reusing the same control statements across many jobs.

Using a cataloged member for SYSIN lets you maintain one copy of the control statements and reference them from many JCL jobs. When you change the member, all jobs that use it get the new logic (unless they override SYSIN).

Uncataloged and Temporary Datasets

Not every dataset is cataloged. Temporary (job) datasets (e.g. DSN=&&TEMP) are not cataloged; they exist only for the job. Work datasets (SORTWK01, …) are usually created with DISP=(NEW,DELETE,DELETE) and not cataloged. If you create a new dataset with DISP=(NEW,KEEP,DELETE) and do not use CATLG, the dataset exists on the volume but is not in the catalog—to use it again you would need to supply VOL=SER= or catalog it in a later step.

Catalog Concatenation and Qualifiers

Your site may use a job catalog or STEPCAT (or similar) so that short names get a high-level qualifier (HLQ) prefix. For example, if your JOB or STEP specifies a catalog that adds USERID as the HLQ, then DSN=DAILY.INPUT might resolve to USERID.DAILY.INPUT. The exact rules depend on your installation. When in doubt, use the fully qualified name (e.g. USERID.MY.DATASET) so the catalog can resolve it.

Explain It Like I'm Five

The catalog is like a phone book for datasets. When a dataset is "cataloged," its name is in the phone book, and the book says where it lives (which shelf/volume). So when you say "I want PROD.DAILY.TRANSACTIONS," the system looks in the phone book, finds it, and gets it. When you create a new dataset and "catalog" it, you add a new entry to the phone book so that next time someone asks for that name, the system knows where it is. Using DFSORT with cataloged datasets just means: your input and SYSIN are names that are in the phone book, and your output is a new entry you add to the phone book when you create it.

Exercises

  1. What does DISP=(NEW,CATLG,DELETE) do for a new SORTOUT dataset?
  2. Why would you put control statements in a cataloged PDS member instead of in-stream in the JCL?
  3. What is the difference between DISP=SHR and DISP=OLD when reading an existing input dataset?
  4. If a dataset is not cataloged, how might you still reference it in JCL?

Quiz

Test Your Knowledge

1. What does it mean for a dataset to be cataloged?

  • It is stored on tape
  • It is registered in the system catalog so it can be found by name
  • It is read-only
  • It is used only for SYSIN

2. Which DISP is typically used for an existing input dataset (SORTIN) that is cataloged?

  • DISP=(NEW,CATLG,DELETE)
  • DISP=SHR
  • DISP=OLD only
  • DISP=(MOD,DELETE,DELETE)

3. When creating a new SORTOUT that you want to keep, what DISP do you often use?

  • DISP=SHR
  • DISP=(NEW,CATLG,DELETE) or (NEW,CATLG,KEEP)
  • DISP=OLD
  • DISP=(NEW,DELETE,DELETE)

4. Can SYSIN point to a cataloged PDS member?

  • No, SYSIN must be in-stream
  • Yes, e.g. DSN=MY.PROCS(SORT1),DISP=SHR
  • Only for MERGE
  • Only if SORTOUT is also a member

5. Why would you use a cataloged dataset for SYSIN instead of in-stream data?

  • To make the job run slower
  • To reuse the same control statements in many jobs
  • To avoid using SORTIN
  • Cataloged SYSIN is required for MERGE