IBM SC34-5764-01 Server User Manual


 
SELECT
Purpose
 SELECT;
WHEN expression THEN instruction
;;
OTHERWISE
instruction
;
END ; 
SELECT conditionally calls one of several alternative instructions.
Each expression after a WHEN is evaluated in turn and must result in 0 or 1. If the result is 1, the
instruction following the associated THEN (which may be a complex instruction such as IF, DO, or
SELECT) is processed and control then passes to the END. If the result is 0, control passes to the next
WHEN clause.
If none of the WHEN expressions evaluates to 1, control passes to the instructions, if any, after
OTHERWISE. In this situation, the absence of an OTHERWISE causes an error (but note that you can
omit the instruction list that follows OTHERWISE).
Example:
balance=100
check=50
balance = balance - check
Select
when balance > 0 then
say 'Congratulations! You still have' balance 'dollars left.'
when balance = 0 then do
say 'Warning, Balance is now zero! STOP all spending.'
say "You cut it close this month! Hope you do not have any"
say "checks left outstanding."
end
Otherwise
say "You have just overdrawn your account."
say "Your balance now shows" balance "dollars."
say "Oops! Hope the bank does not close your account."
end /* Select */
Notes:
1. The instruction can be any assignment, command, or keyword instruction, including any of the more
complex constructs such as DO, IF, or the SELECT instruction itself.
2. A null clause is not an instruction, so putting an extra semicolon (or label) after a THEN clause is not
equivalent to putting a dummy instruction. The NOP instruction is provided for this purpose.
3. The symbol THEN cannot be used within expression, because the keyword THEN is treated differently,
in that it need not start a clause. This allows the expression on the WHEN clause to be ended by the
THEN without a ; (delimiter) being required.
SELECT
Chapter 13. Keyword Instructions 163