Access to Input Streams

Within method and timer code in Flex operators, you can examine records in any of the input streams.

More precisely, there are implicitly declared variables: The variable InputStream_stream is quite useful for looking up values. The InputStream_iterator is less commonly used and is for advanced users.
For example, suppose you are processing events from an input stream called Trades, with the following records:
[ Symbol='T'; | Shares=10; Price=22.88; ]
You might have another input stream called Earnings that contains recent earnings data, storing records:
[ Symbol='T'; Quarter="2008Q1"; | Value=10000000.00;  ]
In processing events from Earnings, you can look up the most recent Trades data using:
Trades := Trades_stream[Earnings];
The record in the Trades stream that has the same key field Symbol. If there is no matching record in the Trades stream, the result is null.
When processing events from the Trades stream, you can look up earnings data using:
Earnings := Earnings_stream{ [ Symbol = Trades.Symbol; | ] };
The syntax here uses curly braces rather than square brackets because the meaning is different. The Trades event does not have enough fields to look up a value by key in the Earnings stream. In particular, it's missing the field called Quarter. The curly braces indicate "find any record in the Earnings stream whose Symbol field is the same as Trades.Symbol". If there is no matching record, the result is null.
If you have to look up more than one record, you can use a for loop. For instance, you might want to loop through the Earnings stream to find negative earnings:
for (earningsRec in Earnings_stream) {
  if ( (Trades.Symbol = Earnings.Symbol) and (Earnings.Value < 0) ) {
    negativeEarnings := 1;
    break;
  }
}
As with other for loops in SPLASH, the variable earningsRec is a new variable whose scope is the body of the loop. You can write this slightly more compactly:
for (earningsRec in Earnings_stream where Symbol=Trades.Symbol) {
  if (Earnings.Value < 0) {
    negativeEarnings := 1;
    break;
  }
}
This loops only over the records in the Earnings stream that have a Symbol field equal to Trades.Symbol. If you happen to list the key fields in the where section, the loop runs very efficiently. Otherwise, the where form is only nominally faster than the first form.
Using a Flex operator, you can access records in the stream itself. For instance, if the Flex operator is called Flex1, you can write a loop just as you can with any of the input streams:
for (rec in Flex1) {
  ...
}