Developing Apama Applications > Developing Apama Applications in EPL > Working with Streams and Stream Queries > Using dynamic expressions in stream queries > Examples of using dynamic expressions in stream queries > Example of actions and methods in dynamic expressions
Example of actions and methods in dynamic expressions
Actions and methods can be considered to be dynamic elements. There are various reasons why you might want to use actions and methods in queries:
*If you are using a particular common complex expression in several places in queries within a monitor, it might be preferable to implement this as an action.
*If you are using a method that is implemented in a plug-in.
*To add protection to expressions that, if unprotected, might cause run-time errors. For example:
stream<Tick> basketPrices :=
   from p in prices
   partition by p.symbol
   retain 1
   select sum( p.price * getBasketVolume(t.symbol) );
...
action getBasketVolume( string symbol) returns float {
if ( basketVolume.hasKey(t.symbol) ) then {
   return basketVolume[t.symbol];
} else {
   return 0.0;
}
}
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.