Sorting is correct until it is too slow. Broadcom explicitly warns that sorting during Easytrieve program execution significantly increases CPU overhead—batch windows shrink, chargeback codes spike, and capacity planners ask why a report step consumed more MSU than last month when record counts barely moved. Performance is not a single knob: key width and count, record volume, internal SEQUENCE versus external SORT, VIRTUAL MEMORY spill behavior, SIZE underestimation, repeated sorts on identical keys, and whether DFSORT already ran in JCL all interact. Beginners optimize report LINE masks while ignoring a million-row SORT inside every nightly run. This page teaches how to measure sort cost, reduce rows before sort with BEFORE SELECT, choose one shared SORT over multiple SEQUENCE passes, set SIZE responsibly, coordinate with operations on installation sort work data sets, and document trade-offs when stakeholders demand report-time ordering only. Targets are Easytrieve Report Generator 11.6 batch and report flows on z/OS unless noted for CICS packaged sort.
Compare operations dominate sort CPU: each record participates in multiple comparisons during merge passes. Wider keys and more keys increase compare cost per decision. I/O dominates elapsed time when work data sets exceed memory and the installation sort writes intermediate runs to SORTWK volumes. Easytrieve adds prescreen procedure overhead for every input record when BEFORE is coded—cheap IF tests on millions of rows still add up. REPORT SEQUENCE adds PRINT spool I/O before sort even begins. External SORT on full-width records moves more bytes than SEQUENCE on trimmed spool fields, but one full-file sort may still beat three SEQUENCE passes sorting overlapping key sets on the same run.
| Factor | Impact | Mitigation |
|---|---|---|
| Record count | High | BEFORE SELECT; upstream extract filtering |
| Repeated sorts same keys | High | One SORT; remove duplicate SEQUENCE |
| Key width and count | Medium | Shortest keys that satisfy breaks; avoid redundant keys |
| Work data set I/O | High on large files | JCL DFSORT tuning; VIRTUAL MEMORY for medium work files |
| SIZE underestimate | Failure or extra passes | Refresh SIZE when volumes grow |
| In-program vs JCL sort | Operational | Shared extract → JCL DFSORT once |
Consider a program with three reports: summary by region, detail by branch, and exception list by employee. If each REPORT declares SEQUENCE (REGION, BRANCH) on the same keys, Easytrieve may sort three spool files independently. If JOB already needs region-branch order for FIRST-DUP logic, a single SORT PERSNL TO SORTWRK USING (REGION, BRANCH) before JOB lets all three PRINT statements read ordered input—SEQUENCE may be omitted when print order matches file order. Exception report needing employee name as minor key might still need SEQUENCE (REGION, BRANCH, EMP-NAME) while others use sorted input only—a deliberate second sort with narrower spool. Document the choice in source comments so future maintainers do not add a fourth SEQUENCE blindly.
12345678910* Performance-friendly chain: SORT PERSNL TO SORTWRK USING (REGION, BRANCH) SIZE 1200000 JOB INPUT SORTWRK NAME NIGHTLY PRINT RPT-SUMMARY PRINT RPT-DETAIL PRINT RPT-EXCEPTION REPORT RPT-EXCEPTION SEQUENCE (REGION, BRANCH, EMP-NAME) * Only this report needs extra minor key on spool
SIZE tells the sort utility how many records to plan for when Easytrieve cannot infer count from a prior activity output. Use production peak counts plus growth margin—not last Tuesday's small test file. SIZE too low risks sort failure or degraded multi-pass behavior; SIZE too high wastes virtual storage and work space reservations. WORK names an alternate work file for sort intermediate data when site standards require separating sort scratch from VIRTUAL TO output. Coordinate WORK DD with operations; developers name the FILE; JCL binds physical volumes.
12345678SORT PERSNL TO SORTWRK USING (DEPT, EMP-NAME) BEFORE ACTIVE-ONLY ACTIVE-ONLY. PROC IF STATUS NE 'A' EXIT END-IF SELECT END-PROC
If thirty percent of rows are inactive status, prescreening removes them before compare operations—roughly thirty percent fewer sort records. Combine business filters in BEFORE rather than SORT then JOB DELETE patterns that still paid sort cost for dropped rows. Keep procedures tight: complex BEFORE logic on every row can rival sort savings if it triggers expensive field conversions per record.
| Signal to pre-sort in JCL | Reason |
|---|---|
| Same extract feeds three Easytrieve programs | One DFSORT step amortized |
| Operations already tune SORTWK for payroll extract | Reuse known control cards |
| Need INREC/OUTREC/SUM during sort | DFSORT features beyond Easytrieve SORT |
| Easytrieve BEFORE filter changes weekly | Keep volatile logic in program; coarse JCL sort on stable keys |
FILE SORTWRK VIRTUAL MEMORY favors keeping intermediate activity data in memory until policy forces spill. Medium nightly extracts often see better elapsed time than cataloged scratch data sets with heavy allocation. Million-row sorts exceed memory and spill regardless— plan DISK or installation SORTWK space. RETAIN on VIRTUAL extends lifetime across activities; forgotten RETAIN work files hold memory until job end—performance and region pressure continue after you no longer need the file.
| Anti-pattern | Outcome |
|---|---|
| SORT million rows then JOB filters ninety percent | Paid sort for rows immediately dropped |
| SEQUENCE on every report identically | Repeated sort CPU |
| SIZE left at decade-old test value | Sort failure on production peak |
| Sorting on 200-byte name field | Wide key compare overhead |
| Ignoring operations DFSORT tuning offer | Higher MSU than necessary |
Sorting is like organizing a huge pile of trading cards. The bigger the pile, the longer it takes. If you remove cards you do not want before organizing, the pile shrinks and you finish faster—that is BEFORE SELECT. If three friends each reorganize the same pile their own way, you do triple work—that is three SEQUENCE on the same keys. If one friend organizes the pile once and everyone shares the neat stack—that is one SORT. If the pile is so big it does not fit on the table, you need extra side tables—that is SORTWK work space. Smart kids measure how long sorting took last time before adding another sort just because a new game wants cards in a slightly different order.
1. Broadcom warns that sorting during Easytrieve execution:
2. Three reports each with SEQUENCE on identical keys often costs:
3. SIZE on SORT helps when:
4. BEFORE SELECT filtering before SORT primarily saves:
5. Pre-sorting a million-row extract in JCL DFSORT before Easytrieve is often best when: