MainframeMaster

WHEN=ANY

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

Conditional Processing
Progress0 of 0 lessons

What WHEN=ANY Does

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.

Processing Order

WHEN=ANY is evaluated after the WHEN=(logexp) and WHEN=NONE clauses. So for each record:

  1. WHEN=INIT and WHEN=GROUP (if present) run first.
  2. The first matching WHEN=(logexp) or WHEN=NONE is applied (unless HIT=NEXT allows more).
  3. Then WHEN=ANY is evaluated. If the record matched at least one WHEN=(logexp), the WHEN=ANY action is applied.

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.

Typical Use: Common Overlay for All Matched Records

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:

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

When to Use WHEN=ANY

Use WHEN=ANY when
Use caseReason
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" recordSame BUILD or OVERLAY for all matched records.
Set a "processed" or "matched" indicatorDownstream 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=ANY vs WHEN=NONE

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.

BUILD and OVERLAY in WHEN=ANY

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.

Explain It Like I'm Five

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.

Exercises

  1. You have WHEN=(1,1,CH,EQ,C'H') and WHEN=(1,1,CH,EQ,C'D') with different OVERLAYs. You want position 90 set to '1' for every record that is H or D. How do you do it without repeating OVERLAY=(90:C'1') in both branches?
  2. What is the difference between WHEN=ANY and WHEN=NONE in terms of which records they apply to?
  3. In what order is WHEN=ANY processed relative to WHEN=(logexp) and WHEN=NONE? Why does that order matter?

Quiz

Test Your Knowledge

1. When does WHEN=ANY apply?

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

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

  • To filter out records
  • To apply additional formatting (e.g. OVERLAY) to every record that matched at least one WHEN=(logexp)—e.g. add a common flag or suffix
  • To replace WHEN=NONE
  • Only for the first matching record

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

  • Before; WHEN=ANY runs first
  • After; WHEN=ANY is evaluated after the WHEN=(logexp) and WHEN=NONE clauses, and applies to records that matched at least one WHEN=(logexp)
  • At the same time as WHEN=NONE
  • Only when HIT=NEXT is used

4. Can WHEN=ANY use OVERLAY?

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

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

  • Yes
  • No; WHEN=ANY applies only to records that matched at least one WHEN=(logexp). Records that matched none get WHEN=NONE (if present), not WHEN=ANY
  • Only when WHEN=NONE is omitted
  • Only for the last record