SELECT

Purpose

Read syntax diagramSkip visual syntax diagram
>>-SELECT--;---------------------------------------------------->

   .---------------------------------------------------.   
   V                                                   |   
>----WHEN--expression--+---+--THEN--instruction--+---+-+-------->
                       '-;-'                     '-;-'     

>----OTHERWISE--+-----------------+----+---+--END--;-----------><
                | .-------------. |    '-;-'           
                | V             | |                    
                '---instruction-+-'                    

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 */
Note:
  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.

Reference Reference

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/dfhrxam.html