The EGL case statement marks the start of multiple sets of statements, where at most only one of those sets is run. The case statement is equivalent to a C or Java switch statement that has a break at the end of each case clause.
If you specify criterion, each of the subsequent when clauses (if any) must contain one or more instances of matchExpression. If you do not specify criterion, each of the subsequent when clauses (if any) must contain a logical expression.
If you wish the when clause to have no effect when invoked, code the clause without EGL statements.
A case statement may have any number of when clauses.
The primitive type of matchExpression value must be compatible with the primitive type of the criterion value. For details on compatibility, see Logical expressions.
After the statements run in a when or otherwise clause, control passes to the EGL statement that immediately follows the end of the case statement. Control does not fall through to the next when clause under any circumstance. If no when clause is invoked and no default clause is in use, control also passes to the next statement immediately folowing the end of the case statement, and no error situation is in effect.
An example of a case statement is as follows:
case (myRecord.requestID) when (1) myFirstFunction(); when (2, 3, 4) try call myProgram; onException myCallFunction(12); end otherwise myDefaultFunction(); end
If a single clause includes multiple instances of matchExpression (2, 3, 4 in the previous example), evaluation of those instances is from left to right, and the evaluation stops as soon as one matchExpression is found that corresponds to the criterion value.
Related tasks
Syntax diagram
Related reference
EGL statements
Logical expressions
sysVar.eventKey
sysVar.systemType
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.