WHEN(trigger, action [, BEFORE | SUCCESS | FAILURE] )

triggerA dataset or action that launches the action.
actionThe action to execute.
BEFOREOptional. Specifies an action that should be executed before the input is read.
SUCCESSOptional. Specifies an action that should only be executed on SUCCESS of the trigger (e.g., no LIMITs exceeded).
FAILUREOptional. Specifies an action that should only be executed on FAILURE of the trigger (e.g., a LIMIT was exceeded).

The WHEN function associates an action with a trigger (dataset or action) so that when the trigger is executed the action is also executed. This allows job scheduling based upon triggers.


//a FUNCTION with side-effect Action
namesTable := FUNCTION
   namesRecord := RECORD
     STRING20 surname;
     STRING10 forename;
     INTEGER2 age := 25;
   o := OUTPUT('namesTable used by user <x>');
   ds := DATASET([{'x','y',22}],namesRecord);

z := namesTable : PERSIST('z');
  //the PERSIST causes the side-effect action to execute only when the PERSIST is re-built

See Also: FUNCTION Structure, WHEN, WAIT