Developing Apama Applications > Developing Apama Applications in EPL > Working with Streams and Stream Queries > Using output from streams
Using output from streams
A stream listener passes output items from a stream to procedural code. You use a from statement to create a stream listener. The from statement has two forms.
The first form of the from statement creates a stream listener that takes items from an existing stream. For example:
from sA: a {
   /* Code here executes whenever an item is available from sA. */
}
The second form of the from statement contains a stream query definition, which creates a new stream query. The stream listener takes items from the output stream of the query. For example:
from a in sA select a : a {
   /* Code here executes whenever the query produces output. */
}
The syntax for the first form is as follows:
[listener:= ] from streamExpr : variable statement
listener
Optional. You can specify a listener variable to refer to the stream listener that the from statement creates. You can declare a new listener variable or a use an existing listener variable.
streamExpr
Specifies any expression of type stream except a stream query. This can be, for example, a stream variable or a stream source template. If you want to specify a stream query, use the other form of the from statement.
variable
Specifies a variable that you want to use to hold the stream output. You must have already declared the variable and the type of the variable must be the same type as the stream output. The from statement coassigns the stream output to this variable.
For details about the characters you can specify, see Identifiers in the Apama EPL Reference.
The output from a stream is referred to as a lot. Like an auction lot, a stream output lot can contain one or more items. If the stream output is a lot that contains more than one item, the from statement coassigns each item, in turn, to the variable. See Working with lots that contain multiple items.
A from statement cannot specify multiple coassignments.
statement
Specifies an EPL statement. Specify a single statement or enclose multiple statements in braces. The from statement coassigns each stream output item to the specified variable and executes the statement or block once for each output item.
If the steam output is a lot that contains more than one item, and you want to execute the statement or block just once for the lot rather than once for each item in the lot, coassign the result to a sequence. See Coassigning to sequences in stream listeners.
The syntax for the second form of the from statement is as follows:
[listener:=] StreamQueryDefinition : variable statement
listener
Optional. You can specify a listener variable to refer to the stream listener that the from statement creates. You can declare a new listener variable or a use an existing listener variable.
StreamQueryDefinition
Specifies a stream query. See Defining stream queries.
variable
Specifies a variable that you want to use to hold the query results. You must have already declared the variable and the type of the variable must be the same type as the query results. The from statement coassigns the query result to this variable.
For details about the characters you can specify, see Identifiers in the Apama EPL Reference.
If the query outputs lots that contain more than one item, the from statement coassigns each item in the lot, in turn, to the variable. See Working with lots that contain multiple items.
A from statement cannot specify multiple coassignments.
statement
Specifies an EPL statement. You can specify a single statement or you can enclose multiple statements in braces. The from statement coassigns each stream output item to the specified variable and executes the statement or block once for each output item.
If you want the statement to be executed once per lot rather than once per item coassign the results to a sequence. See Coassigning to sequences in stream listeners
Copyright © Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its Subsidiaries and or/its Affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.