CASE Statement

<case statement>

── CASE ──<case expression>── of ── BEGIN ─────────────────────────────►
  ┌◄─────────────────────────── ; ───────────────────────────┐
  │     ┌◄──────────── , ────────────┐                       │
►─┴─ ( ─┴─<case constant expression>─┴─ ) ── : ──<statement>─┴─────────►
►─┬───────────────────────────────┬─┬─────┬─ END ──────────────────────┤
  └─ ; ── ELSE ── : ──<statement>─┘ └─ ; ─┘

<case expression>

──┬─ <integer expression> ─┬───────────────────────────────────────────┤
  └─ <string expression> ──┘

<case constant expression>

──┬─ <integer constant expression> ─┬──────────────────────────────────┤
  └─ <string constant expression> ──┘

Explanation

The CASE statement provides a way to dynamically select one of several alternative statements, depending on the value of the case expression.

The case constant expressions, in the parentheses that precede the statements, must be of the same type as the case expression. In addition, no two case constant expressions within the same CASE statement can have the same value.

The ELSE specification specifies an action to take if the value of the case expression is not equal to any of the case constant expressions. If there is no ELSE specification, and the case expression does not equal any of the case constant expressions, then a fatal run‑time error occurs.

Example

The following is an example job that uses the CASE statement:

?BEGIN JOB CASE/EXAMPLE(STRING DAY);
  CLASS=2;
  CASE DAY OF
    BEGIN
     ("MONDAY",
      "TUESDAY",
      "WEDNESDAY",
      "THURSDAY"): RUN OBJECT/DAILY/UPDATE;
     ("FRIDAY"): RUN OBJECT/WEEKLY/UPDATE;
     ("SATURDAY",
         "SUNDAY"): ; % NO RUN NEEDED
    ELSE: ABORT "INVALID INPUT STRING:" & DAY;
  END;
?END JOB.