Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Defining What Happens When Matching Events Are Found | Defining actions | Invoking an action from another action
 
Invoking an action from another action
To invoke an action from another action, specify the action name followed by parentheses. If the action takes one or more input parameters, specify values for the parameters inside the parentheses. For example:
// First action:
action myAction1() {
   myAction2();
}
 
// Second action that is called by the first action:
action myAction2() {
   // . . .
}
In the example above, myAction1() calls myAction2() from inside the myAction1() declaration block. myAction2() takes no parameters and does not return a value.
When an action returns a value, you can invoke that action only from within an expression. You cannot specify a standalone statement that invokes an action that returns a value. Discarding the return value is illegal in EPL. For example:
action myAction3() returns string {
   return "Hello";
}
 
action myAction4() {
   string response;
   response := myAction3(); // Valid
   myAction3(); // Invalid
}
Consider this extended example:
// First action:
//
action myAction1() {
   myAction2();
}
 
// Second action that is called by the first action:
//
action myAction2() {
   string answer1, answer2;
   myAction5(5, 10.5);
   on anEvent() myAction5(5, 10.5);
   answer1 := myAction6(256, 1423.2);
   answer2 := myAction7();
}
 
// Action that is called by myAction2:
//
action myAction5 (integer i, float f) {
...
}
 
// Another action that is called by myAction2:
//
action myAction6 (integer i, float f) returns string {
   return "Hello";
}
 
// Yet another action that is called by myAction2:
//
action myAction7() returns string {
   return "Hello again";
}
myAction2() takes no parameters and does not return a value.
myAction5() accepts input parameters. You can invoke it from a standalone statement:
myAction5(5, 10.5);
You can also invoke it as a listener action:
on anEvent() myAction5(5, 10.5);
myAction6() accepts input parameters and returns a value. You can invoke myAction6() only from within an expression:
answer1 := myAction6(256, 1423.2);
myAction7() returns a value but does not take any parameters. You can invoke it only from within an expression:
answer2 := myAction7();