CASE statement
- Last Updated: February 11, 2026
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
Provides a multi-branch decision based on the value of a single expression.
Syntax
|
- expression
- The expression that determines which branch of code to execute. The expression parameter can be any valid ABL expression. It can include comparisons, logical operations, and parentheses.
- WHEN value[ OR WHEN value] . . . THEN
- Each value is an expression that evaluates to a possible value for expression. If value matches the current value of expression, then the associated block or statement executes.
- OTHERWISE
- Introduces a block or statement to execute when the value of expression does not match any value in any of the
WHENclauses. - block
- A
DO,FOR, orREPEATblock. If you do not use a block, then you can only use a single statement for theWHENorOTHERWISEclause. - statement
- A single ABL statement. If you want to use more than one statement,
you must enclose them in a
DO,FOR, orREPEATblock. - END [ CASE ]
- Indicates the end of the
CASEstatement. You can include theCASEkeyword here to improve readability; it has no effect on the code.
Example
The following fragment shows a simple example of a CASE
statement:
r-case.p
|
Notes
- Each value must have the same data type as expression. If the data types do not match, the compiler reports an error.
- Both value and expression can be enums, including ABL and .NET enums, but each value must be the same enum type as expression.
- You can specify any number of
WHENclauses within theCASEstatement. - You can specify only one
OTHERWISEclause for aCASEstatement. If you use theOTHERWISEclause, it must be the last branch in the statement. - When a
CASEstatement is executed, the AVM evaluates expression and evaluates each value for each branch in order of occurrence until it finds the first value that satisfies the condition. At that point the AVM executes that branch and does not evaluate any other value for that branch or any other branches. If no matching value is found, then theOTHERWISEbranch is executed, if given. If theOTHERWISEbranch is not given and no matching value is found, then no branch of theCASEstatement is executed and execution continues with the statement after theCASEstatement. - After a branch of the
CASEstatement is executed, the AVM leaves theCASEstatement and execution continues with the statement following theCASEstatement. - If a
LEAVEstatement is executed within any branch of aCASEstatement, the AVM leaves the closest block (other than aDOblock) that encloses theCASEstatement.