The CASE statement
- Last Updated: January 22, 2026
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
IF,THEN,ELSE clauses that all operate on different
values of the same variable or expression, you can combine these into a single block
using the CASE statement, which has this syntax:
|
The expression can be a simple field or variable or any other
expression involving multiple fields or values. Part of the optimization of the
CASE statement is that it evaluates the expression only once, when
the CASE statement is entered. By contrast, nested IF
statements evaluate the expression in each IF clause, even if the
expression is the same each time.
Following the block header are a number of WHEN clauses, each of which
starts with a value for the expression, followed by
THEN, followed by a statement or block to execute if the expression
has that value. You can combine multiple WHEN clauses with
OR if the same block or statement executes on multiple values of
the expression.
Finally, the CASE block can conclude with an optional
OTHERWISE clause with a statement or block to execute if the
expression matches none of the values in the WHEN clauses.
The CASE statement is most useful when a variable or field can have one
of a small number of possible values, and the procedure needs to react differently to
each value.
Here is a simple example that uses the CASE statement to count the
number of Orders of different types. There are four valid values for
the OrderStatus field. The OTHERWISE clause tallies
any that do not match any of the valid values (as it turns out, there are not any):
|