In DFSORT IFTHEN, WHEN=NONE applies to records that matched no preceding WHEN=(logical expression) clause. It is the else or default branch: when you have several WHEN=(logexp) conditions (e.g. record type 'A', 'B', 'C'), any record that does not match A, B, or C gets the WHEN=NONE action. That lets you define a fallback layout or overlay for unknown record types, invalid data, or anything that did not fit your other conditions. WHEN=NONE is evaluated in the same phase as WHEN=(logexp); it runs only for records for which no WHEN=(logexp) was true. This page explains what WHEN=NONE does, when it runs, typical uses (default values, unknown-type handling), and how it differs from WHEN=ANY and WHEN=(logexp).
WHEN=NONE answers the question: "Did this record match none of the WHEN=(logexp) clauses?" If yes, the WHEN=NONE action (BUILD, OVERLAY, or FINDREP) is applied. So WHEN=NONE is the way to say: "For every record that did not match any of my conditions, do this." That is essential when you have a finite set of conditions (e.g. record types A, B, C) and you need to handle everything else explicitly—for example, to overlay a default value, set an "unknown type" flag, or build a safe record layout so that downstream programs never see an unhandled format.
Records that did match a WHEN=(logexp) do not get WHEN=NONE; they get that matching clause's action. So WHEN=NONE and the WHEN=(logexp) clauses partition the records: each record gets exactly one of the conditional branches (unless you use HIT=NEXT to allow multiple clauses to apply).
WHEN=NONE is evaluated in the same phase as WHEN=(logexp). For each record:
So WHEN=NONE is the fallback: it runs only when no condition was true. You do not need to list every possible value in WHEN=(logexp); you can handle the "everything else" case in one place with WHEN=NONE.
Suppose you have record types in byte 1: 'A' (header), 'B' (detail), 'C' (trailer). You want to overlay position 80 with '1', '2', or '3' for A, B, C respectively, and for any other value (bad data, unknown type) you want position 80 set to '0' and position 81 set to 'U' for unknown. You would write:
12345OUTREC IFTHEN=(WHEN=INIT,BUILD=(1:1,82)), IFTHEN=(WHEN=(1,1,CH,EQ,C'A'),OVERLAY=(80:C'1')), IFTHEN=(WHEN=(1,1,CH,EQ,C'B'),OVERLAY=(80:C'2')), IFTHEN=(WHEN=(1,1,CH,EQ,C'C'),OVERLAY=(80:C'3')), IFTHEN=(WHEN=NONE,OVERLAY=(80:C'0',81:C'U'))
Every record with byte 1 = A, B, or C gets the corresponding overlay. Every other record (D, space, invalid, etc.) gets WHEN=NONE and thus 80='0' and 81='U'. Downstream can then treat '0'/'U' as unknown type and handle or reject accordingly.
| Use case | Reason |
|---|---|
| Define a default layout or overlay for records that match no WHEN=(logexp) | Ensures every record is explicitly handled; no "fall-through" with unexpected content. |
| Mark unknown or invalid record types | Overlay a flag (e.g. 'U') so downstream can filter or report. |
| Provide a safe fallback for bad or unexpected data | Build a minimal valid record or overlay default values to avoid abends. |
If you omit WHEN=NONE and a record matches no WHEN=(logexp), it keeps whatever was set by WHEN=INIT (or remains as it was). Sometimes that is fine; other times you need an explicit else so that "everything else" gets a known format.
WHEN=NONE applies to records that matched no WHEN=(logexp)—the default or else branch. WHEN=ANY applies to records that matched at least one WHEN=(logexp). So for every record, exactly one of these is true: it matched at least one condition (and can get WHEN=ANY, and does not get WHEN=NONE) or it matched none (and gets WHEN=NONE, and does not get WHEN=ANY). You can have both in the same IFTHEN: WHEN=NONE for the else layout, WHEN=ANY to add something common to all matched records.
As with other WHEN types, you can use BUILD= or OVERLAY= (or FINDREP) in WHEN=NONE. OVERLAY is common: set one or more positions to default or flag values without rebuilding the whole record. BUILD would replace the entire record for all "else" records; use it when you want a completely different layout for unknown or default records (e.g. a fixed 80-byte safe record with blanks and a type code).
Imagine you have cards: some say "A," some "B," some "C," and some say something else or are scribbled. You have a rule for A cards, a rule for B cards, and a rule for C cards. The cards that are not A, B, or C get one more rule: "do this." That last rule is WHEN=NONE—it catches everybody who didn't get a sticker from the A, B, or C rules. So WHEN=NONE is the "everyone else" box: you put a default sticker or format on them so nobody is left unhandled.
1. When does WHEN=NONE apply?
2. What is a typical use of WHEN=NONE?
3. Is WHEN=NONE processed before or after WHEN=(logexp)?
4. Can WHEN=NONE use OVERLAY?
5. If a record matches a WHEN=(logexp), does WHEN=NONE apply to it?