Sort & Utility Programs
Learn about the general-purpose utility programs every mainframe shop relies on: IDCAMS for VSAM dataset management, and DFSORT/SORT for sorting, copying, and reformatting data.
Introduction
Not every task on a mainframe requires a custom-written program. An enormous amount of everyday work — sorting a file into a different order, copying data from one dataset to another, creating or deleting a VSAM cluster, reformatting records — is handled by general-purpose IBM utility programs that ship with z/OS and are simply invoked from JCL like any other program. This lesson covers the two you will encounter constantly: IDCAMS and DFSORT (often just called SORT).
Why Utility Programs Matter
Writing a custom COBOL program every time you needed to sort a file or set up a new VSAM dataset would be enormously wasteful — these are common, well-understood operations that do not vary in their fundamental logic from one shop to the next. IBM utility programs solve this the same way PROCs solve JCL duplication: write the logic once, extremely well, and let every job that needs it simply invoke the utility with the right control statements for that specific case.
A utility program is a general-purpose tool controlled entirely through DD statements and a small control-statement language of its own (fed through a SYSIN DD), rather than through custom compiled logic. You are not writing a program — you are configuring an existing one for your specific task.
IDCAMS: Managing VSAM Datasets
IDCAMS (Access Method Services) is IBM's utility for defining, deleting, listing, backing up, and reorganizing VSAM datasets — the KSDS, ESDS, and RRDS cluster types you learned about earlier in this course. Where IEFBR14 with a DD statement is enough to allocate a simple sequential dataset, VSAM clusters have enough structure (key ranges, index and data components, control intervals) that they need a dedicated utility with its own command language to define them correctly.
| IDCAMS Command | Purpose |
|---|---|
| DEFINE CLUSTER | Creates a new VSAM cluster (KSDS, ESDS, or RRDS), specifying key ranges, space, and record sizes |
| DELETE | Removes a VSAM cluster (or other catalog entry) entirely |
| LISTCAT | Lists catalog information about existing datasets, useful for confirming attributes or troubleshooting |
| REPRO | Copies records from one dataset to another, commonly used to load a VSAM cluster or make a backup |
| Prints the contents of a dataset in a readable format, useful for inspecting data during troubleshooting |
A DEFINE CLUSTER Example
//IDCJ010 JOB (ACCT77),'M PATEL',CLASS=A,MSGCLASS=X//STEP010 EXEC PGM=IDCAMS//SYSPRINT DD SYSOUT=*//SYSIN DD * DEFINE CLUSTER (NAME(PROD.CUSTMAST.KSDS) - INDEXED - KEYS(9 0) - RECORDSIZE(200 200) - TRACKS(50 25) - FREESPACE(10 10) - VOLUMES(VOL001))/*Click Run to see what this code prints.
DFSORT / SORT: Sorting and Reformatting
DFSORT (commonly invoked simply as SORT) is IBM's high-performance utility for sorting, merging, copying, and reformatting sequential data. It is used constantly in batch processing — sorting transactions into account number order before applying them to a master file, extracting only certain fields or record types, or simply copying a dataset with light reformatting. Its control statements are fed through a SYSIN DD, in a compact but readable syntax.
| SORT Control Statement | Purpose |
|---|---|
| SORT FIELDS= | Specifies which field(s) to sort by, their position, length, data type, and ascending/descending order |
| INCLUDE COND= | Keeps only records matching a specified condition, discarding the rest |
| OMIT COND= | Discards records matching a specified condition, keeping the rest |
| OUTREC FIELDS= | Reformats or rearranges fields in the output records |
A Complete SORT JCL Example
//SORTJ010 JOB (ACCT77),'M PATEL',CLASS=B,MSGCLASS=X//STEP010 EXEC PGM=SORT//SORTIN DD DSN=PROD.TRANS.RAW,DISP=SHR//SORTOUT DD DSN=PROD.TRANS.SORTED,// DISP=(NEW,CATLG,DELETE),// SPACE=(CYL,(10,5),RLSE),// DCB=(RECFM=FB,LRECL=100)//SYSOUT DD SYSOUT=*//SYSIN DD * SORT FIELDS=(1,10,CH,A) INCLUDE COND=(11,2,CH,EQ,C'DR')/*Click Run to see what this code prints.
Other Common Utilities
IDCAMS and SORT are the two you will meet most often, but a small set of other IBM utilities appear regularly enough in real job streams to be worth recognizing by name.
IEFBR14
A true "do-nothing" program, often used purely to allocate or delete datasets through its DD statements, without any real processing (as seen in this unit's first lesson).
IEBGENER
A simple, widely used utility for copying a sequential dataset from one place to another, optionally with light reformatting.
IEBCOPY
Copies, compresses, and merges partitioned datasets (PDS/PDSE) and their members.
IEBPTPCH
An older utility for printing or punching dataset contents, still occasionally seen in legacy job streams.
Common Mistakes
- Confusing IDCAMS's trailing-hyphen continuation syntax for SYSIN control statements with JCL's own trailing-comma continuation rule — they are different and easy to mix up.
- Miscounting field positions and lengths in SORT FIELDS= or INCLUDE COND=, which silently sorts or filters on the wrong data rather than producing an obvious error.
- Forgetting that SORTOUT (or an equivalent) must have adequate SPACE= allocated — sort jobs on large files can fail simply from insufficient output space.
- Assuming REPRO and DEFINE CLUSTER always need to be run together — a cluster must exist (via DEFINE CLUSTER) before REPRO can load data into it.
Best Practices
- Always check SYSPRINT (for IDCAMS) or SYSOUT (for SORT) after running a utility step — both produce detailed diagnostic messages that make troubleshooting straightforward.
- Double check field positions and lengths against the actual record layout before running SORT with INCLUDE/OMIT conditions on production data.
- Use LISTCAT to confirm a VSAM cluster's attributes before assuming what space or key structure it currently has.
- Favor well-tested, centrally maintained utility PROCs over hand-writing raw utility JCL for common operations, for the same reasons covered in the previous lesson.
Frequently Asked Questions
In practice, on IBM Z, yes — DFSORT is IBM's sort product, and PGM=SORT is simply the traditional program name used to invoke it. You will see both terms used interchangeably in shops and documentation.
No. IDCAMS is specifically for VSAM cluster management (and some catalog operations). Simple sequential datasets can typically be allocated directly through a DD statement's DISP and SPACE parameters, without IDCAMS.
Yes. Despite the name, DFSORT can also copy, merge, filter (INCLUDE/OMIT), and reformat (OUTREC) data, which is why it shows up in so many batch pipelines beyond strictly "sorting" tasks.
REPRO copies records from a source dataset into a target dataset, commonly used to initially load data into a newly defined VSAM cluster, or to make a straightforward backup copy of an existing one.
Key Takeaways
- General-purpose IBM utility programs handle common tasks (sorting, copying, VSAM management) without needing custom-written code.
- IDCAMS manages VSAM datasets: DEFINE CLUSTER creates them, DELETE removes them, REPRO loads or copies data, LISTCAT reports on them.
- DFSORT/SORT sorts, merges, filters, and reformats sequential data, controlled by compact SYSIN control statements.
- Utility control statements are supplied through a SYSIN DD, distinct from the JCL statements that invoke the utility program itself.
- A handful of other utilities (IEFBR14, IEBGENER, IEBCOPY) appear frequently enough to recognize by name and general purpose.
Summary
IDCAMS and DFSORT/SORT are two of the most-used programs on any mainframe, precisely because they solve extremely common problems — managing VSAM structures and reordering or filtering data — without requiring custom code. With JCL and its most common utilities now covered, this course turns to a different but closely related topic: where COBOL, the language most of these JCL jobs ultimately run, fits into the picture.