User guide

Data Integration with Sybase Avaki Studio 149
Iterator
Iterator
The Iterator operator provides a looping construct for view models. Based on criteria
you specify, an Iterator repeatedly executes the portion of the flow upstream from its
position and accumulates the results. You might use an Iterator if, for example, you
need to execute a parameterized input source once for each of a series of dates, sales
regions, or customer IDs. You can use the Iterator operator in two ways:
Like a for loop. In this approach, which is similar to for loops in most program-
ming languages, the iteration is controlled by a set of expressions specifying the
starting and ending conditions, as well as how to increment the loop variables.
When you configure the upstream operators (those farther from the Result), you
can use variables defined in any Iterator operator downstream from them. In our
example, if you have an Input Source that takes a date parameter, you could map
the parameter to a Date variable that the Iterator operator increments.
Like a for each loop. Studio’s Iterator operator also gives you the option of
controlling the iteration with the results of another branch of the flow, referred to as
the range input. This approach is similar to the for each constructs in many pro-
gramming languages; it allows you to execute the main branch once for each row in
the range result set, which resembles a lookup table. (For example, a database oper-
ation might return a list of employee IDs, allowing you to execute the main branch
of the flow once per employee.) You use expressions to define variables based on
the values of each row in the range input source, and you can also use an expression
to trigger the premature termination of the loop.
Note You can create nested iterations (for example, a SELECT within a
SELECT) by incorporating multiple Iterator operators into your flow. In a pair of
Iterator operators, the downstream one forms the outer loop and the upstream
one forms the inner loop.