EGL Reference Guide for iSeries

case

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.



Syntax diagram for the case statement

criterion
An item, constant, literal, or system variable, including sysVar.eventKey or sysVar.systemType.

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.

when
The beginning of a clause that is invoked only in these cases:

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.

matchExpression
One of the following values:

The primitive type of matchExpression value must be compatible with the primitive type of the criterion value. For details on compatibility, see Logical expressions.

logicalExpression
A logical expression.
statement
An EGL statement.
otherwise
The beginning of a clause that is invoked if no when clause runs.

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


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]