MainframeMaster

WHEN=NONE

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).

Conditional Processing
Progress0 of 0 lessons

What WHEN=NONE Does

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).

Processing Order

WHEN=NONE is evaluated in the same phase as WHEN=(logexp). For each record:

  1. WHEN=INIT and WHEN=GROUP (if present) run first and establish a base record.
  2. DFSORT then evaluates WHEN=(logexp) clauses in order. The first one that matches is applied.
  3. If no WHEN=(logexp) matched, WHEN=NONE is applied (if you specified it).
  4. Later, WHEN=ANY (if present) can apply to records that matched at least one WHEN=(logexp).

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.

Typical Use: Default or Unknown Record Type

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:

text
1
2
3
4
5
OUTREC 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.

When to Use WHEN=NONE

Use WHEN=NONE when
Use caseReason
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 typesOverlay a flag (e.g. 'U') so downstream can filter or report.
Provide a safe fallback for bad or unexpected dataBuild 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 vs WHEN=ANY

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.

BUILD and OVERLAY in WHEN=NONE

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).

Explain It Like I'm Five

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.

Exercises

  1. You have WHEN=(1,1,CH,EQ,C'H') and WHEN=(1,1,CH,EQ,C'D') with different OVERLAYs. What happens to a record with byte 1 = space if you do not specify WHEN=NONE? What if you add WHEN=NONE with OVERLAY=(1,1,C'?')?
  2. What is the difference between WHEN=NONE and WHEN=ANY in terms of which records they apply to?
  3. Why might you want to use WHEN=NONE even when you believe all valid records match one of your WHEN=(logexp) conditions?

Quiz

Test Your Knowledge

1. When does WHEN=NONE apply?

  • To all records
  • Only to records that did not match any preceding WHEN=(logexp)
  • To records that matched at least one WHEN=(logexp)
  • Only to the first record

2. What is a typical use of WHEN=NONE?

  • To filter out records
  • To apply a default layout or overlay to records that did not match any WHEN=(logexp)—e.g. unknown record type or fallback format
  • To replace WHEN=ANY
  • Only for the last record

3. Is WHEN=NONE processed before or after WHEN=(logexp)?

  • Before; WHEN=NONE runs first
  • After; WHEN=NONE is evaluated when no WHEN=(logexp) matched—it is the else branch
  • At the same time as WHEN=ANY
  • Only when HIT=NEXT is used

4. Can WHEN=NONE use OVERLAY?

  • No; only BUILD
  • Yes; WHEN=NONE can use BUILD, OVERLAY, or FINDREP like other WHEN types
  • Only in INREC
  • Only when WHEN=INIT is present

5. If a record matches a WHEN=(logexp), does WHEN=NONE apply to it?

  • Yes
  • No; WHEN=NONE applies only to records that matched no WHEN=(logexp). Records that matched a condition get that clause's action, not WHEN=NONE
  • Only when WHEN=ANY is omitted
  • Only for the last matching record