Easytrieve Sort Optimization

Sort optimization is the art of paying for ordering once—not three times because three REPORT sections each coded SEQUENCE on the same keys, not twice because a nightly extract is sorted in DFSORT and again inside Easytrieve, and not on rows that SELECT would have discarded before the first compare. Easytrieve invokes the system sort product; CPU and work data set pressure scale with record count and key width. Beginners optimize too late—tweaking SORTWK cylinders while feeding millions of unfiltered rows. This page teaches volume reduction BEFORE SELECT, single SORT feeding multiple JOB activities, SIZE and WORK parameters when record count is unknown, presorted JCL extracts for shared consumers, tie-break keys for stable order, internal versus external sort selection, and a production checklist aligned with Broadcom performance guidance.

Progress0 of 0 lessons

Optimize Sort Volume First

The cheapest sort is the one that never sees rejected rows. Use JOB INPUT with IF and SELECT patterns, BEFORE SELECT on SORT when supported, or upstream extraction jobs that filter status codes before Easytrieve runs. Every removed row skips compare-merge I/O. Document filter predicates—optimization without audit trail confuses operations when counts drop.

text
1
2
3
4
5
6
7
8
SORT NAME ORDERED INPUT PAYFILE USING PAY-KEY EMP-KEY BEFORE SELECT IF STATUS NE 'A' SKIP END-IF END-SELECT

One SORT Versus Repeated SEQUENCE

Sort strategy comparison
PatternSort passesWhen to use
SORT once then multiple JOB PRINTOneSame keys, multiple reports
SEQUENCE per REPORTOne per REPORTAvoid for identical keys
DFSORT JCL presortZero inside EasytrieveShared extract many programs
Already sorted inputZero if monotonicUpstream warehouse order guaranteed

Key Design for Performance

Sort shortest effective key that preserves business order—packed keys narrower than character when collating rules allow. Multi-key sorts list major key first; unnecessary trailing keys add compare cost. Add tie-break key—employee number after department—when equal keys must be deterministic across runs. Broadcom documents that equal-key order depends on sort product; do not rely on accidental order for regression tests.

SIZE and WORK Parameters

When SORT input is not produced by a prior Easytrieve activity in the same run, SIZE supplies estimated record count so the sort utility allocates adequate work space—undersized work data sets cause spills and multipass merges that inflate elapsed time. WORK names sort work DDs per installation standards; coordinate SORTWK space with storage team. Test with peak month-end volume, not Tuesday sample.

Internal Versus External Sort

SORT activity is external sort integration—appropriate for large sequential files. Internal sort paths suit smaller volumes per release thresholds. Wrong choice shows as long CPU in step or excessive work data set allocation. External presort in JCL when file exceeds comfortable in-step limits or when multiple programs consume same order.

JCL DFSORT Presort Pattern

text
1
2
3
4
5
6
7
8
9
10
11
//PRESORT EXEC PGM=SORT //SORTIN DD DSN=RAW.PAYROLL,DISP=SHR //SORTOUT DD DSN=SORTED.PAYROLL,DISP=(,CATLG,DELETE), // SPACE=(CYL,(500,50)),UNIT=SYSDA //SYSIN DD * SORT FIELDS=(1,5,CH,A,10,8,PD,A) /* //EZT EXEC PGM=EZTPA00,... //INPUT DD DSN=SORTED.PAYROLL,DISP=SHR * Easytrieve JOB reads presorted — omit SORT activity

CONTROL and Sort Order Alignment

Report CONTROL fields must match sort key order major-to-minor. Optimizing sort without aligning CONTROL produces wrong subtotals without sort error message—worse than abend. SEQUENCE on REPORT documents expected order but does not replace physical sort.

Diagnostics Versus Optimization

PARM SORT(MSG(ALL)) helps test failures; it does not speed production. Remove after validating keys and work space. Runtime SORT messages wrapped in SYSPRINT point to key length mismatch or missing SORTWK—fix structure, not message suppression.

Sort Optimization Checklist

  1. Count input rows before and after SELECT filters.
  2. Confirm one sort pass per key set per job.
  3. Validate key offsets against DMAP listing.
  4. SIZE for external file inputs; test month-end volume.
  5. Add tie-break key if equal keys matter.
  6. Align CONTROL with sort keys.
  7. Evaluate DFSORT presort for shared extracts.
  8. Remove SORT(MSG(ALL)) from production PARM.

Common Sort Optimization Mistakes

  • SEQUENCE on every REPORT with identical keys.
  • Sorting before filtering inactive records.
  • Wrong packed key length—silent mis-sort.
  • Undersized SORTWK on peak runs.
  • Assuming input sorted without validation.
  • Ignoring CONTROL mismatch after presort change.

Explain It Like I'm Five

Sorting is lining up kids by height. Optimization is not inviting kids who are absent (filter first), lining up once for three photos (one SORT), and asking the gym teacher who already lined up the class (DFSORT presort) instead of shuffling again. If two kids are the same height, pick a second rule—like shirt color—so everyone stands in the same order tomorrow.

Exercises

  1. Redraw a three-REPORT program with one SORT activity.
  2. Write BEFORE SELECT filter reducing sort volume.
  3. List tie-break keys for REGION plus DEPT sort.
  4. When would SIZE be required on SORT?
  5. Compare CPU story: presort JCL versus in-program SORT.

Quiz

Test Your Knowledge

1. Best sort optimization often starts with:

  • Sorting fewer records via SELECT before SORT
  • Adding more REPORT sections
  • Removing all keys
  • Disabling FILE statements

2. One shared SORT before multiple PRINT reports:

  • Usually beats three SEQUENCE clauses on same keys
  • Is illegal
  • Requires SQL
  • Only works online

3. SIZE on SORT is needed when:

  • Record count cannot be inferred from prior Easytrieve activity
  • Keys are descending
  • Using SCREEN
  • TABLE lookup only

4. JCL DFSORT presort helps when:

  • Many jobs read same large extract in key order
  • Only one tiny report runs once
  • No keys exist
  • Input is instream TABLE

5. Equal keys without tie-break field:

  • Order may be non-deterministic across runs
  • Always sorts by ROWID
  • Compile error
  • Uses HIGH-VALUES automatically
Published
Read time13 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 SORT statement, sort performance guidanceSources: Broadcom Easytrieve 11.6 SORT processing, Using Best Practices, sort performance tutorial alignmentApplies to: Easytrieve SORT optimization and performance