Suppose you want your SPL routine to select elements from
the collection stored in the collection variable, one at time, so
that you can handle the elements.
To move through the elements
of a collection, you first need to declare a cursor using a FOREACH
statement, just as you would declare a cursor to move through a set
of rows. The following figure shows the FOREACH and END FOREACH statements,
with no statements between them yet.Figure 1. FOREACH and END FOREACH statements.
FOREACH cursor1 FOR
. . .
END FOREACH
The FOREACH statement is described in The FOREACH loop and the IBM®
Informix® Guide to SQL: Syntax.
The
next topic, The collection query, describes
the statements that are omitted between the FOREACH and END FOREACH
statements.
The examples in the following sections are based
on the polygons table of Figure 2.