WHEN

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.

Example:

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

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

See Also: FUNCTION Structure, WHEN, WAIT