Use the CASE statement to define a multi-way conditional branch based on
a comparison between a variable and one or more constants. When a match is
found between a variable and a constant specified by a WHEN keyword, execution
begins at the indicated WHEN keyword and continues until the next WHEN keyword,
or until the end of the CASE structure.
An OTHERWISE statement is optional. You can use OTHERWISE to specify actions
to be performed when none of the specified constants match. If OTHERWISE is
not used and if none of the specified constants match, no action is taken
and execution is resumed at the first statement following the ENDCASE statement.
There is a limit of 45 WHEN statements.
Example
CASE msgtype OF
WHEN 1:
which_msg = newmsg;
WHEN 2:
which_msg = savedmsg;
ENDCASE
Procedure
Use the following procedure to define a CASE statement:
- Selecting the CASE statement: Click Statements —>
Case.
The system displays the Case Definition window.
- Specifying the variable: Type the name of the variable
that is to be tested in the Case field, or click Case to
display the Term Definition window to select the variable.
- Adding WHEN keywords: Click Add once for
each test you want to perform in the CASE statement.
A Value field
appears in the window each time you select Add.
- Type a value in each Value field that you want to compare to
the Case variable, or click Value to display the Term Definition
window to specify the value.
- Deleting a value field: To delete a Value field,
clear the field value (backspace) and click Delete.
- Adding the statement to the prompt: Click OK.
The CASE statement is added to the prompt.
- Defining WHEN statements: To define the statements
to be executed at each WHEN condition, position the cursor anywhere on the
line that contains the WHEN keyword, then click Statements to define
the required statements.
Note: The semicolon (;) following the WHEN
keyword is automatically included when you define the CASE statement. Statements
may immediately precede the semicolon, or may follow the semicolon. If no
statements follow the WHEN keyword, the semicolon ensures legal syntax.
The statements are added to the prompt following the WHEN keywords.
- Defining OTHERWISE statements: To define statements
to be executed when none of the WHEN conditions are true, position the cursor
anywhere on the line that contains the OTHERWISE keyword, then click Statements to define the required statements.
The statements are added
to the script following the OTHERWISE keyword.