Easytrieve Internal Sort

Sorting in Easytrieve is not one single mechanism. Operations teams talk about internal sort when ordering happens inside the report generator's own processing cycle—without standing up a separate JCL sort step or declaring a full-file SORT activity that hands records to DFSORT through prescreen exits. The flagship internal pattern is REPORT SEQUENCE: after PRINT spools detail lines to a temporary work file, Easytrieve sorts only the fields that report needs, then TITLE and LINE formatting read the sorted spool. On CICS and non-mainframe deployments, Broadcom documents a sort packaged with the product rather than your site's installation sort program—another internal path distinct from z/OS E15/E35 external sort. Beginners who treat every sort as SORT USING are surprised when a program with no SORT activity still produces ordered pages because SEQUENCE ran invisibly after PRINT. This page explains internal sort scope, spool work files, VIRTUAL declarations, how SEQUENCE keys relate to CONTROL breaks, packaged sort environments, limits compared with external SORT, and decision rules for when internal ordering is enough versus when you must sort the whole input file first.

Progress0 of 0 lessons

Internal Versus External Sort — Definitions

How this tutorial names sort paths
TermMechanismTypical use
Internal sortREPORT SEQUENCE; packaged Easytrieve sort on CICS/non-z/OSOne report needs print order; spool-only reorder
External sortSORT activity on z/OS calling installation DFSORT/Syncsort via E15/E35Whole file reorder for JOB, writes, or multiple reports

External sort is covered in the companion external sort tutorial. Internal sort does not mean in-memory quicksort written in PROC code—it means the product-owned report spool pipeline or bundled sort module handles ordering without you coding a separate SORT TO dataset activity for that purpose. Both paths consume CPU; internal sort often processes fewer bytes per record because spool layouts omit fields you never PRINT.

REPORT SEQUENCE — The Primary Internal Pattern

Declare SEQUENCE on the REPORT statement with the same key fields you would use in USING on a SORT line—region, branch, pay amount, and so on. Minor keys follow major keys left to right. Append D immediately after a key name for descending order on that key only; other keys remain ascending unless they also carry D. When JOB logic executes PRINT for that report, Easytrieve copies selected fields to an internal work file, invokes sort on those spool records, then drives page building from sorted output. CONTROL break headers align with SEQUENCE keys when you list the same fields on CONTROL—if you CONTROL REGION BRANCH but SEQUENCE only REGION, branch subtotals may fire at wrong boundaries.

text
1
2
3
4
REPORT RPT1 SEQUENCE (REGION, BRANCH D, EMP-NAME) CONTROL REGION BRANCH TITLE 'PAYROLL BY REGION AND BRANCH' LINE REGION BRANCH EMP-NAME GROSS-PAY

REGION sorts ascending, BRANCH descending within each region, EMP-NAME ascending within each branch group. No SORT activity appears in the program—ordering is internal to RPT1. JOB may still read input in arrival sequence while the printed report shows sorted detail. That split is valid when file order does not matter for GET logic but readability does matter on paper.

Spool Work Files and VIRTUAL

Internal sort depends on temporary sequential files Easytrieve allocates for spool and merge. You rarely name these explicitly for SEQUENCE—the product manages report work files. When you chain activities manually, FILE SORTWRK VIRTUAL COPY input-layout creates scratch space the Virtual File Manager holds in memory or on spill datasets until CLOSE or job end. VIRTUAL MEMORY favors smaller extracts; VIRTUAL DISK spills to work DDs when row counts exceed memory policy. RETAIN keeps a VIRTUAL file across activities in one execution pass so a second JOB can read intermediate results without rewriting JCL. Internal SEQUENCE work files are typically shorter than full input records because only PRINT-selected fields enter the spool.

Packaged Sort on CICS and Non-Mainframe

Broadcom states z/OS batch invokes the installation sort program. CICS Easytrieve and non-mainframe editions use the sort packaged with the product. From your source code perspective SEQUENCE and SORT syntax look the same, but operations cannot tune DFSORT control cards for those internal invocations the way a standalone sort step allows. Capacity planning for online Easytrieve programs that SEQUENCE large extracts must account for region and sort work inside the transaction or batch region hosting the product—not a separate sort job step on the JES queue.

What Internal Sort Does Not Do

  • Rewrite your primary input FILE for downstream jobs that read the extract later tonight.
  • Replace DFSORT INREC, OUTREC, SUM, or JOINKEYS transformations—you need external sort or preprocessing.
  • Order TABLE ARG rows—tables require ascending ARG at load time for binary SEARCH, not SEQUENCE.
  • Fix CONTROL breaks when JOB skipped both SORT and SEQUENCE—keys must change once per group on the path feeding PRINT.
  • Deduplicate by key during SEQUENCE—duplicate spool rows remain unless PRINT logic omitted them.

SEQUENCE Key Options Explained

SEQUENCE key modifiers
SyntaxEffectCompared to USING on SORT
KEYAscending order for that keySame as USING without D
KEY DDescending for that key onlySame D suffix rules as USING
(KEY1, KEY2)Major-to-minor composite sortIdentical key ordering concept

Field definitions must be fixed length for keys—varying length, K-type, or M-type fields are invalid sort keys and fail at compile time. OFFSET and length on FILE DEFINE must match the bytes SEQUENCE compares; a one-byte slip shifts department codes into wrong sort buckets.

When Internal Sort Is the Right Choice

  1. Exactly one report needs a presentation order different from input arrival sequence.
  2. No other activity in the program—or downstream job step—requires the same ordered file.
  3. Spool field set is smaller than full record, so sorting spool is cheaper than sorting the extract.
  4. You want to avoid an extra SORT activity and extra VIRTUAL TO file in source maintenance.
  5. Online or CICS report where packaged internal sort is the supported path.

When two or more reports need the same keys, or JOB must detect FIRST-DUP after ordering, external SORT once before JOB usually beats multiple internal SEQUENCE passes on identical keys—see sort performance tutorial for CPU comparisons.

Internal Sort Activity Flow

text
1
2
3
4
5
6
7
8
9
10
JOB INPUT PERSNL NAME PAY-RUN PRINT RPT1 * * Internal path for RPT1 only: * PRINT -> spool work file -> SEQUENCE sort -> format TITLE/LINE * REPORT RPT1 SEQUENCE (DEPT, EMP-NAME) CONTROL DEPT TITLE 'EMPLOYEE LISTING BY DEPARTMENT' LINE DEPT EMP-NAME SALARY

PERSNL records are read in whatever order the extract arrived. Each PRINT adds spool rows. Before formatting, internal sort orders spool by DEPT then EMP-NAME. CONTROL DEPT prints department headers when DEPT changes on sorted spool. Without SEQUENCE, headers would appear whenever a new department happened to appear in random input—a classic beginner failure mode.

Common Internal Sort Mistakes

Symptoms and fixes
SymptomLikely fix
CONTROL fires every lineAdd SEQUENCE on same keys as CONTROL
Report sorted, file notExpected for SEQUENCE-only; add SORT if JOB needs order
Wrong descending groupsPlace D immediately after the key that should descend
Compile error on SEQUENCE keyRemove varying-length or invalid key field types
Three reports, triple sort costOne external SORT plus shared ordered input

Explain It Like I'm Five

You are putting on a school play. The class list on the teacher's desk is in random order because kids signed up as they walked in. Internal sort is like sorting only the index cards of kids who are actually in the play, right before you read their names on stage—you do not reorder the whole class list in the office filing cabinet. You shuffle the small stack of performer cards alphabetically, then read from that stack. External sort would be the secretary reordering every student file in the cabinet before the play starts. If only the stage needs order, sorting the performer cards is enough. If the nurse and the librarian also need the whole school in alphabetical order, the secretary should sort the cabinet once instead of three people each sorting their own smaller stacks.

Exercises

  1. Write REPORT SEQUENCE (REGION D, CITY) and explain the first three spool rows after sort.
  2. Draw a diagram: input file random order, PRINT spool, internal sort, LINE output.
  3. List four cases where SEQUENCE alone is sufficient versus four where SORT activity is required.
  4. Given CONTROL DEPT LOCATION, write matching SEQUENCE keys and justify the match.
  5. Explain packaged sort on CICS in one paragraph for a new hire from z/OS batch only.
  6. Compare bytes sorted: full 500-byte record file versus 80-byte spool with ten PRINT fields.

Quiz

Test Your Knowledge

1. Which Easytrieve feature is the classic internal sort for one report?

  • REPORT SEQUENCE
  • FILE TABLE
  • WRITE DELETE
  • SCREEN REFRESH

2. On CICS or non-mainframe Easytrieve, the sort utility is typically:

  • Packaged with Easytrieve rather than site DFSORT
  • Always DFSORT from JCL only
  • Not available—SEQUENCE is forbidden
  • Replaced by SQL ORDER BY only

3. SEQUENCE sorts which records?

  • Only spool rows PRINT wrote for that report
  • Every record in the input FILE
  • TABLE ARG rows only
  • VSAM KSDS index slots

4. Internal sort work files are often declared as:

  • FILE name VIRTUAL
  • FILE name TABLE INSTREAM
  • FILE name INDEXED
  • FILE name PRINTER

5. When is internal SEQUENCE a better fit than external SORT?

  • Only one report needs a special print order and no downstream file needs reordering
  • Every job step must share one sorted permanent file
  • You need INREC/OUTREC record transformation in DFSORT
  • Input is VSAM KSDS you must rewrite in key order
Published
Read time18 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 SEQUENCE Statement, Sequenced Reports, Sorting FilesSources: Broadcom Easytrieve 11.6 Sequenced Reports; SEQUENCE Statement; Sorting Files; REPORT StatementApplies to: Easytrieve internal report sorting with SEQUENCE and packaged sort environments