Easytrieve Ascending Sort

Ascending sort is the default Easytrieve assumes when you list keys without a D suffix. Numbers climb from small to large. Names walk A toward Z under the collating sequence. Dates move earlier to later when defined as true date fields. Regions list 01 before 02 before 10 when defined as numeric—not always what beginners expect if they think of 10 as before 2 lexically. Most control-break reports want ascending major keys so subtotals read naturally down the page. This page explains default ascending behavior on SORT USING and REPORT SEQUENCE, how each field type compares, signed versus unsigned numeric traps, EBCDIC and ALTSEQ effects on characters, multi-key ascending stacks, when ascending is the wrong business choice, and test data you should build before production. Pair this with the Descending sort page when only some keys need reverse order.

Progress0 of 0 lessons

Default Is Ascending

text
1
2
3
4
SORT PERSNL TO SORTWRK USING (REGION, BRANCH, EMP#) REPORT R1 SEQUENCE DEPT EMP#

Neither example uses D, so every key sorts ascending. REGION 01 precedes 02. Within region 01, BRANCH 100 precedes 200. Within equal region and branch, lower EMP# precedes higher. SEQUENCE on a report follows identical default: DEPT ascending, EMP# ascending within department.

Ascending by Field Type

Ascending comparison cheat sheet
TypeAscending meansExample order
N unsigned0, 1, 2, 10, 9910 after 2 numerically
N signedNegative to positive per sign rules-5 before +5
P packedNumeric magnitude1.00 before 9.99
A alphaCollating sequence low to highA before B before Z
D dateChronological early to lateJan before Feb

Display pictures mislead: zoned fields may show 02 before 10 while character fields might sort 10 before 2 if defined as alphanumeric text. Always know whether the key is N, P, or A in DEFINE.

Numeric Ascending Traps

  • Unsigned versus signed—negative values sort before positives only when signed is declared.
  • Packed length must include sign nibble; wrong length compares wrong digits.
  • Leading zeros in zoned display do not change numeric order for true numeric types.
  • Mixing zoned and packed keys in one file—sort each on its declared type consistently.
text
1
2
DEFINE WS-RANK W 3 N * Ascending: 1, 2, 3, 10 — not 1, 10, 2 as strings

Alphanumeric Ascending and Collating

On z/OS, A fields typically follow EBCDIC order unless your site installs an alternate sequence (ALTSEQ) for the sort utility or sets PARM SORT options. Punctuation and national characters sort relative to letters per that table—test with real data containing hyphens, spaces, and lowercase if allowed. Blank-filled keys sort before lower collating values in many sequences; trim or normalize in BEFORE if blanks should group last.

Multi-Key All Ascending

text
1
SORT TRANS TO SORTWRK USING (ACCT-DATE, ACCT-NO, SEQ-NO)

Transaction files often need date ascending (oldest first), account ascending within date, sequence ascending within account. All three keys ascending suits audit trails and GL registers. A statement extract needing newest date first would put D on ACCT-DATE only—see descending page—not change major key order blindly.

Ascending and CONTROL Reports

CONTROL DEPT on a report expects DEPT values to increase (or at least change once per group) as the sorted file is read. Ascending DEPT in USING (..., DEPT) means department 100 prints completely before department 200—ideal for subtotals that accumulate low to high department codes. If marketing wants department 900 first, that is a descending or custom-order problem, not default ascending.

When Ascending Is Wrong

Business need versus default ascending
Business needTypical fix
Highest pay first within deptGROSS D as minor key
Newest date firstDATE D as major or minor key
Z-to-A name listNAME D on that key
Latest transaction per account after date sortAscending date then duplicate logic in JOB

Testing Ascending Order

  1. Build ten records with known out-of-order keys.
  2. DISPLAY first three and last three key values after SORT.
  3. Verify numeric 2 appears before 10 for N keys.
  4. Verify character order with punctuation samples.
  5. Run CONTROL report—confirm one break per key group.

Common Ascending Mistakes

  • Expecting lexical string order on numeric fields.
  • Adding D everywhere when only one key needs descending.
  • Ignoring signed attribute on negative amounts.
  • Assuming MASK display order equals sort order.
  • Sorting unsigned employee IDs that include check digit letters as A.

Explain It Like I'm Five

Ascending is counting up stairs: 1, 2, 3, 4. For letters in ABC order, A comes before B. Easytrieve does that by default for each sort key unless you put a D on that key to walk down the stairs instead.

Exercises

  1. Write all-ascending USING for REGION BRANCH DEPT.
  2. Create ten-row test file; verify numeric ascending order.
  3. Explain signed versus unsigned ascending for -10 and +5.
  4. Match ascending USING to CONTROL on a sample report.
  5. Identify one key in your shop that needs D instead of ascending.

Quiz

Test Your Knowledge

1. Default sort order in USING is:

  • Ascending for each key unless D suffix
  • Descending always
  • Random
  • By record length

2. Ascending numeric N fields sort:

  • Low value to high value (per signed rules)
  • High to low always
  • By field name
  • By MASK

3. Ascending alphanumeric A fields follow:

  • Collating sequence (typically EBCDIC on z/OS)
  • Record number only
  • SQL order
  • MASK pattern

4. USING (REGION, BRANCH) ascending means:

  • REGION low to high, then BRANCH low to high within region
  • BRANCH before REGION globally
  • Descending within groups
  • Only first record kept

5. To keep default ascending on all keys you:

  • Omit D suffix on every key
  • Add D to every key
  • Remove USING
  • Use STOP
Published
Read time16 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 default ascending sort orderSources: Broadcom Easytrieve 11.6 Language Reference SORT USING, REPORT SEQUENCEApplies to: Easytrieve ascending sort comparisons