Easytrieve External Sort

When a report needs every record in key order before JOB logic runs—not just ordered spool lines on paper—you reach for external sort. In Easytrieve that means the SORT activity: a processing phase declared in your program that reads a sequentially processable input file, applies USING keys, optionally prescreens rows through a BEFORE procedure with SELECT, and writes a TO output file whose layout matches input unless lengths change. On z/OS batch, Broadcom interfaces to the installation sort program—DFSORT, Syncsort, or another licensed product—through E15 and E35 exits rather than reimplementing merge algorithms inside the report generator. External sort also describes the common pattern of running DFSORT in JCL before the Easytrieve step, producing a pre-sorted extract with no SORT statement in source at all. Beginners confuse this with REPORT SEQUENCE; external sort rewrites files for the whole job stream while SEQUENCE only reorders what one report PRINT spooled. This page teaches SORT syntax, TO and WORK files, SIZE estimation, BEFORE filtering, chaining into JOB, JCL preprocessing, installation sort tuning pointers, and operational pitfalls when input and output datasets collide.

Progress0 of 0 lessons

SORT Activity Structure

text
1
2
3
4
5
6
7
8
9
10
11
FILE PERSNL FB(150 1800) REGION 1 2 A BRANCH 4 4 A EMP-NAME 10 20 A PAY-NET 50 5 P 2 FILE SORTWRK FB(150 1800) VIRTUAL COPY PERSNL SORT PERSNL TO SORTWRK USING (REGION, BRANCH, PAY-NET D) SIZE 50000 BEFORE FILTER-HIGH-PAY

SORT names the input file PERSNL and output SORTWRK. USING lists composite keys major to minor; D after PAY-NET sorts pay descending within each region-branch group. SIZE hints record count to the sort utility when input was not produced by a prior Easytrieve activity— underestimation can cause sort failure or extra passes; overestimation wastes work space. BEFORE FILTER-HIGH-PAY names a procedure that must follow the SORT statement in source.

Installation Sort on z/OS

Easytrieve is a report generator that calls sort—it is not a replacement for DFSORT. When SORT executes, the product prepares control information from USING keys and FILE definitions, then invokes the site sort with standard exits. Your operations team tunes SORTWK DD allocations, SORTMAX, FASTSRT, and similar parameters in the sort product manual, not in Easytrieve Language Reference. Equal-key ordering among duplicates follows installation sort rules; Easytrieve retains all duplicate keys unless BEFORE excludes rows. Tie-breaker keys in USING make order deterministic when business rules require stable sequencing among equal pay amounts.

BEFORE Procedure and SELECT

text
1
2
3
4
5
6
7
8
SORT PERSNL TO SORTWRK USING (REGION, BRANCH) BEFORE SCREEN-REC SCREEN-REC. PROC IF PAY-NET LT 500 EXIT END-IF SELECT END-PROC

Easytrieve calls SCREEN-REC for each input record before it enters the sort utility. SELECT marks the record for inclusion. EXIT without SELECT drops the row from sort output—equivalent to filtering before external sort runs. SELECT twice on the same pass still writes one copy. SELECT followed by STOP on the same pass excludes the record. Invalid in sort procedures: GET, PRINT, REPORT, WRITE, and other statements Broadcom lists as forbidden because they fight the prescreen contract—only the current input record is in scope.

TO File Options

Common SORT output patterns
PatternTypical FILE declarationNotes
Scratch work fileFILE SORTWRK VIRTUAL COPY inputDiscarded at job end unless RETAIN; no JCL DD required
Permanent reorderFILE OUTFILE FB(...) with JCL DDDownstream jobs consume sorted dataset
In-place sortSORT FILEA TO FILEARisky; verify backup and consumer expectations

Chaining SORT Into JOB

text
1
2
3
4
5
6
7
SORT PERSNL TO SORTWRK USING (REGION, BRANCH, EMP-NAME) JOB INPUT SORTWRK NAME PAYROLL-RPT IF FIRST-DUP REGION BRANCH * count duplicate groups after external sort END-IF PRINT RPT1

Activities execute in source order unless PROGRAM EXECUTE redirects flow. JOB INPUT SORTWRK is explicit; if omitted, default INPUT may pick SORTWRK as TO of the immediately preceding SORT. Multiple SORT activities in one program reset which file JOB defaults to—document intent when maintainers add another SORT later. REPORT definitions may still use SEQUENCE for a different print order even when JOB reads sorted input—use sparingly to avoid double sort cost.

JCL External Sort Before Easytrieve

text
1
2
3
4
5
6
7
//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=PROD.PAYROLL.EXTRACT,DISP=SHR //SORTOUT DD DSN=&&SORTED,UNIT=SYSDA,SPACE=(CYL,(50,10)), // DISP=(NEW,PASS),DCB=(RECFM=FB,LRECL=150) //SYSIN DD * SORT FIELDS=(1,2,A,4,4,A,10,20,A),FORMAT=BI /*

The Easytrieve step reads &&SORTED with no SORT activity in source. This is external sort in the job stream sense—DFSORT owns tuning and work data sets. Choose JCL sort when the same extract feeds Easytrieve, COBOL, and a warehouse loader; choose in-program SORT when BEFORE SELECT logic is tightly coupled to Easytrieve fields and changes with every compile. Hybrid jobs DFSORT for coarse order and Easytrieve SORT for a smaller filtered subset are rare but valid when volumes differ wildly.

SORT Parameters Worth Knowing

SORT statement parameters (Broadcom 11.6)
ParameterPurpose
USINGSort keys; D suffix for descending on that key
TOOutput file receiving sorted records
SIZEEstimated record count for sort work space
WORKAlternate work file for sort passes
BEFOREPrescreen procedure name requiring SELECT
COMMITCheckpoint-related processing per release docs

Broadcom documents BEFORE for prescreening; there is no AFTER parameter on SORT—post-sort logic belongs in the following JOB or in report procedures. Variable-length input sorted to maximum defined length is a special case: verify downstream COPY and spool expectations when LRECL changes.

External Versus Internal — Decision Table

Choose external SORT when
ScenarioRecommended path
Multiple reports need same key orderOne SORT TO file, JOB reads sorted input
JOB uses FIRST-DUP / LAST-DUP on adjacent recordsExternal SORT before compare logic
Downstream job step needs sorted permanent fileSORT TO cataloged DS or JCL DFSORT
Only one report needs order, file order irrelevantInternal SEQUENCE may suffice
Need INREC/OUTREC/SUM in sortJCL DFSORT or ICETOOL, not Easytrieve SORT alone

Operational and Safety Notes

  • Document VIRTUAL versus cataloged TO datasets in runbooks for operations restart.
  • Match FB LRECL and COPY macros so SORTWRK fields align with PERSNL defines.
  • Filter early with BEFORE to shrink sort volume when only a subset needs reordering.
  • Coordinate SORTWK DD space with operations when SORT uses installation work data sets.
  • Test duplicate-key retention when audits require every input row in sorted output.

Explain It Like I'm Five

Picture a library with thousands of books scattered on carts. External sort is hiring the library's official sorting machine—the big one in the basement that every department shares—to rebuild entire shelves in call-number order before anyone reads. You push cartloads through the machine; it outputs new carts in perfect order. Easytrieve's SORT activity is your department asking that machine to run during your program. JCL DFSORT is the same machine running before your department arrives, leaving pre-sorted carts at the door. Internal SEQUENCE, by contrast, is only sorting the few books you pulled for today's story hour. When the whole library needs order for many teams, use the basement machine once. When only your story-hour pile needs order, sorting just that pile is enough.

Exercises

  1. Write SORT with BEFORE that keeps only REGION = 10 and USING (BRANCH, EMP-NAME).
  2. Sketch JCL: DFSORT step then Easytrieve step reading sorted work file—label DD names.
  3. Explain why GET is invalid inside a sort BEFORE procedure.
  4. List three tuning knobs in DFSORT manual versus three in Easytrieve SORT statement.
  5. Predict JOB default INPUT when two SORT activities precede JOB—why explicit INPUT helps.
  6. Design tie-breaker keys for USING when thousands of rows share identical PAY-NET.

Quiz

Test Your Knowledge

1. On z/OS batch, Easytrieve SORT activity invokes:

  • The installation sort program via standard exits
  • Only in-memory ARRAY sort
  • SQL ORDER BY
  • ISPF SORT command

2. SORT activity writes output to:

  • TO file named on SORT statement
  • PRINTER only
  • TABLE INSTREAM
  • SCREEN map

3. BEFORE proc-name on SORT requires you to:

  • Execute SELECT for each record to include in sort output
  • PRINT every record before sorting
  • CLOSE the input file first
  • Use GET inside the procedure

4. JCL DFSORT before Easytrieve with no SORT activity is:

  • External sort preprocessing—valid and common
  • Invalid—Easytrieve forbids pre-sorted input
  • Only allowed for VSAM
  • Replaced by SEQUENCE in every job

5. JOB omits INPUT after SORT when:

  • Default INPUT may be TO file of immediately preceding SORT
  • INPUT is always required explicitly
  • SORT disables JOB
  • Only SCREEN can follow SORT
Published
Read time19 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 SORT Statement, SORT Activities, SELECT (Sort Selection)Sources: Broadcom Easytrieve 11.6 SORT Statement; SORT Activities; SELECT Statement (Sort Selection); Sorting Files; JOB StatementApplies to: Easytrieve external file sorting with SORT activity and JCL DFSORT preprocessing