Developing Apama Applications > Developing Apama Applications in EPL > Defining What Happens When Matching Events Are Found > Defining actions > Format for defining actions
Format for defining actions
The format for defining an action that takes no parameters and returns no value is as follows:
action actionName() {
   // do something
}
Optionally, an action can do either one or both of the following:
*Accept parameters
*Return a value
The format for defining an action that accepts parameters and returns a value is as follows:
action actionName(type1 param1, type2 param2, ...) returns >type3 {
   // do something
  return type3_instance;
}
For example:
action complexAction(integer i, float f) returns string {
   // do something
  return "Hello";
}
An action that accepts input parameters specifies a list of parameter types and corresponding names in parentheses after the action name. Parentheses always follow the action name, in declarations and calls, whether or not there are any parameters.
Parameters can be of any valid EPL type. The correlator passes primitive types by value and passes complex types by reference. EPL types and their properties are described in Types in the Apama EPL Reference.
When an action returns a value, it must specify the returns keyword followed by the type of value to be returned. In the body of the action, there must be a return statement that specifies a value of the type to be returned. This can be a literal or any variable of the same type as declared in the action definition.
An action can have any name that is not a reserved keyword. Actions with the names onload(), onunload() and ondie() can only appear once and are treated specially as already described in About monitor contents. It is an EPL convention to specify action names with an initial lowercase letter, and a capital for each subsequent word in the action name.
Before Apama Release 4.1, actions and variables were allowed to have the same names. For example, you were allowed to coassign an event to a variable that had the same name as the action that handled the event:
on all Update():update update();
With Apama 4.1, this is no longer allowed since you can now declare action type variables. See Using action type variables. If you have any code that uses the same identifier for an action and a variable, you must change it. For example:
on all Update():update handleUpdate();
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.