WHEN ANY

Does the WHEN ANY statement get executed even if you state DECIDE FOR FIRST? So if the first When is true then the when any also gets executed? If this is the case then using FIRST option makes no sense.

Here’s an example of how I have used it:

DECIDE FOR FIRST CONDITION                                 
   WHEN #FISCAL-CCYY  = ' '                   
      MOVE 'No Fiscal Year passed to APNPOSTA.'            
                                  TO #RETURN-MSG  
      MOVE 'XOFY'                 TO #RETURN-CODE 
   WHEN #COMP         = ' '                   
      MOVE 'No Component passed to APNPOSTA.'              
                                  TO #RETURN-MSG  
      MOVE 'XOCM'                 TO #RETURN-CODE 
   WHEN #UIN          = ' '                   
      MOVE 'No Employee ID passed to APNPOSTA.'            
                                  TO #RETURN-MSG  
      MOVE 'XOUI'                 TO #RETURN-CODE 
   WHEN #APPT-NBR     = 0                     
      MOVE 'No Appt Number passed to APNPOSTA.'            
                                  TO #RETURN-MSG  
      MOVE 'XOAP'                 TO #RETURN-CODE 
   WHEN ANY                                                
      ESCAPE ROUTINE                                       
   WHEN NONE                                               
      IGNORE
END-DECIDE

Basically, it saves having ESCAPE ROUTINE within each WHEN clause.

The WHEN ANY in DECIDE FIRST/EVERY is a powerful feature that saves repeated coding for all evaluations. If it makes no sense, you don’t have to use it.

This WHEN ANY highlights Natural over other languages :wink:

Sorry Jennifer, your logic is terribly flawed.

Using FIRST prevents other tests from being done. Thus, clauses should be arranged by likelihood of being true to eliminate executing more tests than necessary.

ANY can easily be significant, even if FIRST is specified. It serves as a “complement” to NONE. Suppose I have five clauses in my DECIDE FOR. They are mutually exclusive. There are specific actions for each of the clauses. HOWEVER, there are also many actions that must be performed if at least one of the clauses is true.

If you do not use ANY, you would have to either:

  1. Duplicate the actions for ANY in each of the five clauses (an administrative nightmare)

  2. Set a flag in each of the five clauses, then test the flag after the DECIDE. Not a pretty way to code.

steve

I guess my confusion is in the manual that states “Only the first true condition is to be processed.” So if the first WHEN out of 3 WHENs is true then I would expect the WHEN ANY condition to not be processed because then it would be the second true condition right? I guess I can’t think of WHEN ANY as an actual “WHEN” clause.

Correct. WHEN ANY, ALL, and NONE are functionally not the same as the “real” WHEN clauses.

Try a DECIDE with two clauses; e.g. WHEN #A = 2 and WHEN #A GT 1 and give #A the value 2. Have a WHEN ANY and a WHEN ALL clause, they will both be executed.

steve

DECIDE FOR { FIRST | EVERY } CONDITION   
  {WHEN   logical-condition   statement }      
  [WHEN ANY   statement ]  
  [WHEN ALL   statement ]  
  WHEN NONE   statement   
END-DECIDE 
DECIDE ON { FIRST | EVERY } [VALUES] [OF] operand1   
  {VALUES operand2 [[,operand2] ... [:operand2]] statement ...}  
  [ANY [VALUES]   statement ]  
  [ALL [VALUES]   statement ]  
   NONE [VALUES] statement   
END-DECIDE  

Take the syntax definitions a little more literally, Jennifer. In the DECIDE FOR statement, “logical conditions” are not present in the WHEN ANY, WHEN ALL, and WHEN NONE clauses. So when the manual states

it refers only to the logical conditions that you provide.

The DECIDE ON statement’s ANY, ALL, and NONE clauses act in similar fashion.