MainframeMaster

Custom Collations

A custom collation is a user-defined order for comparing character (CH) sort keys. By default, DFSORT uses the EBCDIC collating sequence: each byte has a fixed position. When you need a different order—for example, case-insensitive (treat A and a as equal), or a special order for digits and symbols—you can define an alternate collating sequence using the ALTSEQ control statement. ALTSEQ lets you map certain input bytes to other bytes for the purpose of comparison, so that when DFSORT compares two CH keys it uses your order instead of (or in addition to) the default. The actual record bytes are not changed; only the order used for comparison changes. Custom collation applies only to CH keys; numeric formats (PD, ZD, BI, FL) compare by numeric value and ignore collation. This page explains when and how to use custom collations with ALTSEQ.

SORT Statement Deep Dive
Progress0 of 0 lessons

Why Custom Collation?

You might need a custom order when: (1) Case-insensitive sort—map lowercase to uppercase (or vice versa) so A and a compare equal. (2) Special character order—e.g. you want digits 0–9 to sort before letters, or a specific symbol order. (3) Locale or language—e.g. accented characters or a different alphabet order. (4) Normalizing—treat several characters as the same for sort (e.g. space and hyphen as equal). The default EBCDIC order is fixed; ALTSEQ lets you override or extend it for CH comparison.

How ALTSEQ Works

ALTSEQ specifies a mapping: for comparison purposes, byte value X is treated as byte value Y. So when DFSORT compares two keys, it uses the mapped value (Y) instead of the actual byte (X). You can map many bytes (e.g. all lowercase a–z to their uppercase A–Z). Bytes you do not map keep the default EBCDIC order. The syntax and options (e.g. code page, table name) are product-dependent—see your DFSORT manual. Typically you add ALTSEQ to SYSIN before or with the SORT statement.

Record Content Unchanged

ALTSEQ does not change the record. The bytes read from the input and written to the output are the same. Only the comparison used during the sort is altered. So if the input has "smith", the output still has "smith"; but for ordering it was compared as if it were "SMITH" (if you mapped lowercase to uppercase).

CH Only

Custom collation applies only to CH keys. If you use PD, ZD, BI, or FL, the key is interpreted as a number and compared by value—the collating sequence (default or ALTSEQ) is not used. So ALTSEQ has no effect on numeric sort keys.

Explain It Like I'm Five

Custom collation is like making your own "alphabet" for sorting. Normally the computer uses one order (A, B, C, …). You can say "when you compare, treat small letters like big letters" or "put these characters in this order instead." The words on the page don’t change—only the order we use to line them up.

Exercises

  1. Name two uses for ALTSEQ (custom collation).
  2. Does ALTSEQ change the bytes in the output record? Why or why not?
  3. If you have one key CH and one key PD, does ALTSEQ affect both? Explain.

Quiz

Test Your Knowledge

1. What is the main way to define a custom collation in DFSORT?

  • SORT FIELDS=COLLATE
  • ALTSEQ control statement—define an alternate collating sequence so CH comparison uses your order
  • OPTION COLLATE
  • Only EBCDIC is supported

2. Does ALTSEQ change the record bytes in the output file?

  • Always
  • No—ALTSEQ only affects the order used for comparing CH keys; the actual record content is unchanged
  • Only for the key
  • Yes for CH keys

3. When might you use a custom collation?

  • Never
  • Case-insensitive sort (map a–z to A–Z), special character order (e.g. digits before letters), or locale-specific order
  • Only for numeric keys
  • Only for the first key

4. Can you mix default EBCDIC and custom mappings in ALTSEQ?

  • No
  • Yes—you typically specify only the bytes you want to change; the rest keep the default sequence
  • Only for letters
  • ALTSEQ replaces everything

5. Do custom collations apply to PD or ZD keys?

  • Yes
  • No—only CH (character) keys use the collating sequence; numeric formats compare by value
  • Only when OPTION COLLATE
  • Only for the first key