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.
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.
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.
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).
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.
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.
1. What is the main way to define a custom collation in DFSORT?
2. Does ALTSEQ change the record bytes in the output file?
3. When might you use a custom collation?
4. Can you mix default EBCDIC and custom mappings in ALTSEQ?
5. Do custom collations apply to PD or ZD keys?