In DFSORT IFTHEN, WHEN=ANY applies to records that matched at least one preceding WHEN=(logical expression) clause. So it is the opposite of WHEN=NONE: WHEN=NONE is the "else" branch (no match); WHEN=ANY is the "any match" branch—add something common to every record that matched any of the conditions. That lets you apply a single OVERLAY or BUILD to all "matched" records without repeating it in each WHEN=(logexp) branch. WHEN=ANY is processed after WHEN=(logexp) and WHEN=NONE. This page explains what WHEN=ANY does, when it runs, typical uses (e.g. a common flag for all matched records), and how it differs from WHEN=NONE and WHEN=(logexp).
WHEN=ANY answers the question: "Did this record match any of the WHEN=(logexp) clauses?" If yes, the WHEN=ANY action (BUILD, OVERLAY, or FINDREP) is applied. So WHEN=ANY is a way to say: "For every record that matched at least one condition, do this extra thing." That is useful when you have several WHEN=(logexp) branches (e.g. record type 'A', 'B', 'C') and you want to add the same overlay (e.g. a "matched" flag or a suffix) to all of them without writing the same OVERLAY in each branch. You write it once in WHEN=ANY, and it applies to every record that matched A or B or C.
Records that matched no WHEN=(logexp) do not get WHEN=ANY; they get WHEN=NONE (if you have that clause). So WHEN=ANY and WHEN=NONE partition the records: NONE = no match; ANY = at least one match.
WHEN=ANY is evaluated after the WHEN=(logexp) and WHEN=NONE clauses. So for each record:
So the record that WHEN=ANY sees is already the result of the INIT (and optionally GROUP) and of one WHEN=(logexp) or WHEN=NONE. WHEN=ANY then adds its overlay or build on top of that.
Suppose you have three record types (bytes 1–1 = 'A', 'B', or 'C') and you want to overlay position 80 with the constant 'X' for type A, 'Y' for type B, and 'Z' for type C. You also want to set position 81 to '1' for every record that is A, B, or C (i.e. every record that matched one of the conditions). Without WHEN=ANY you would have to add OVERLAY=(81:C'1') in each of the three WHEN=(logexp) clauses. With WHEN=ANY you do it once:
12345OUTREC IFTHEN=(WHEN=INIT,BUILD=(1:1,82)), IFTHEN=(WHEN=(1,1,CH,EQ,C'A'),OVERLAY=(80:C'X')), IFTHEN=(WHEN=(1,1,CH,EQ,C'B'),OVERLAY=(80:C'Y')), IFTHEN=(WHEN=(1,1,CH,EQ,C'C'),OVERLAY=(80:C'Z')), IFTHEN=(WHEN=ANY,OVERLAY=(81:C'1'))
Every record that is A, B, or C gets the type-specific overlay at 80 (X, Y, or Z) and then WHEN=ANY sets position 81 to '1'. Records that are not A, B, or C would be handled by WHEN=NONE if you added it (and would not get WHEN=ANY). So position 81 becomes a "matched one of the types" flag without repeating it in three places.
| Use case | Reason |
|---|---|
| Add a common flag or marker to all records that matched any WHEN=(logexp) | One OVERLAY in WHEN=ANY instead of the same OVERLAY in every branch. |
| Add a suffix or prefix to every "matched" record | Same BUILD or OVERLAY for all matched records. |
| Set a "processed" or "matched" indicator | Downstream can tell that the record matched at least one condition. |
If you only have one WHEN=(logexp) and WHEN=NONE, you usually do not need WHEN=ANY—the single WHEN=(logexp) already handles its records. WHEN=ANY shines when you have multiple WHEN=(logexp) clauses and want one action for "any of them matched."
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) or it matched none (and gets WHEN=NONE). You can have both in the same IFTHEN: WHEN=NONE for the else layout, WHEN=ANY for the common "matched" overlay.
As with other WHEN types, you can use BUILD= or OVERLAY= (or FINDREP) in WHEN=ANY. OVERLAY is common: add one or more fields (e.g. a flag byte) to the record without rebuilding the whole thing. BUILD would replace the entire record for all matched records; that is less common because you usually already built or overlayed in the WHEN=(logexp) branch. So typically WHEN=ANY has OVERLAY to add a common piece.
Imagine you have cards: some have "A," some "B," some "C," and some have something else. You put a different sticker on A, B, and C cards (that is WHEN=(logexp)). Then you say: "Every card that got an A, B, or C sticker also gets a gold star." That gold star is WHEN=ANY—one rule that applies to everyone who got any of those stickers. The cards that didn't get A, B, or C don't get the star (they get WHEN=NONE if you have a rule for them). So WHEN=ANY is the "everybody who matched something gets this extra thing" rule.
1. When does WHEN=ANY apply?
2. What is a typical use of WHEN=ANY?
3. Is WHEN=ANY processed before or after WHEN=(logexp)?
4. Can WHEN=ANY use OVERLAY?
5. If no WHEN=(logexp) matches a record, does WHEN=ANY apply to it?