SELECT/WHEN
Performs conditional execution of DGL statements. This statement is more powerful than theIF/THEN/ELSE
statement in that it allows you to systematically list multiple conditions for statement execution.Note thatWHEN
statements are composed of two parts: the trigger to the left of the arrow, and statements on the right side of the arrow. The trigger is any valid Boolean expression. The statements following a trigger are performed only when the trigger isTRUE
. Whether or not these statements are actually executed also depends on the value of theselection_mode
. In addition:
●
The
WHEN
ANY
statements are executed when one or more of the precedingWHEN
statements have been executed.
●
The
OTHERWISE
statements are executed only if noWHEN
statement within theSELECT
construct is triggered.Regardless of the mode, when all of the triggers are false, the tool will execute theOTHERWISE
clause, if it exists.SELECT [selection_mode]
WHEN trigger => statements
[ WHEN trigger => statements ]
.
.
[ WHEN ANY => statements ]
.
[ WHEN trigger => statements ]
.
.
[ WHEN ANY => statements ]
.
.
[ OTHERWISE => statements ]
END SELECT ;
Specifies the selection mode, which determines the way the statements are checked for possible execution. The possible values are as follows:
• FIRST—Only the first true trigger in the entireSELECT
construct is executed; the rest are ignored, regardless of whether their triggers are TRUE. This is the default value.
• ANY—If the selection mode isANY
, the statements are executed whenever their corresponding trigger is TRUE. The Documentor permits the nesting ofSELECT/WHEN
constructs.SELECT ANY
WHEN a = 5 => b := 10 ;
WHEN a > b => b := 10 ;
WHEN a = 0 => b := 0 ;
WHEN ANY => write (’a may influence b’) ;
WHEN c = 5 => b := 5 ;
WHEN c > b => b := 5 ;
WHEN c = 0 => b := 0 ;
WHEN ANY => write (’c may influence b’) ;
OTHERWISE => write (’b has not been changed’) ;
END SELECT;
●
Each
WHEN
statement is triggered if its corresponding expression is evaluated toTRUE
.
●
The first
WHEN
ANY
statement is triggered if a is equal to 5, greater thanb
, or equal to zero. The secondWHEN
ANY
statement is triggered if at least one of the previous conditions is true with respect to the variablec
instead ofa
.
●
The
OTHERWISE
statement is triggered only if the value ofb
has not been changed within theSELECT
statement’s evaluation.When processing a
WHEN
ANY
statement, the Documentor only “looks back” to the previousWHEN
ANY
construct (if one exists). Therefore, in this example, ifa = 0
and none of the tests ofc
were true, theWRITE
statement’s message “c may influence b” is not issued.Using the same example, what would happen if the selection mode is
FIRST
instead ofANY
, and the conditionsa
>
b
andc
=
5
are both true?In this case, the assignment
b:=
10
and the first write message (the correspondingWHEN ANY
statement) are executed. The assignment ofb
to 5, along with its correspondingWHEN
ANY
statement are not done becausec
=
5
is not the first true trigger.The statements following the
=>
symbol in theWHEN
constructs can be any valid DGL statements. You can even enter aSELECT
construct at this point. This allows you to nestSELECT
constructs. There is no limit to the depth of nestedSELECT
blocks.
●
●
●