Try OpenEdge Now
skip to main content
BPM Events User's Guide
The rule language : Controlling the actions of a rule : Iterative action statements
 

Iterative action statements

Iterations (loops) can execute repetitive actions. They are generally used to iterate over infopad cells.
There are two general syntactical forms for iterative statements. They are:
<IterativeStatement> ::=
    "for" <index_increment_expr> <ActionStatement> |
    "do" <ActionStatement> "from" <value_set> "where" <condition>
The following statement iterates over the rows of the infopad employees. It adds to the salary of an employee a value contained in the raise attribute of an event evt1. The name attribute of the event contains the name of the employee to select. Note that the ActionStatement of the loop is a conditional statement, embedded inside {...} like compound statements, for readability. Note also that the identifier "i" is declared as a variable (var) as its value changes, while the maximum rows are used as a constant value and therefore are declared as a value (val) to ensure that no action changes it.
val rt= employees.rowCount();
for (var i = 1; i <= rt; i++ )
{ if (employees[i][1].name = evt1.name)
    employees[i][1].salary += evt1.raise; }
There is also another way to express an iteration over infopad cells, using the rowKeySet()(or colKeySet()) function that generates the list of indexes for the dimension of interest. Each of these functions actually produces the list of labels (not indexes) associated with the index values of the corresponding dimension. In case no labels were given to the dimension, default labels were generated (string version of the actual index value). In that case, these default labels are returned and used in the iteration.
do employees[xi][1].salary += evt1.raise;
from xi:employees.rowKeySet()
where (employees[xi][1].name = evt1.name);
A similar loop for the cells of the two-dimensional mypad infopad is as follows. Note that nested loops are not necessary:
do mypad[xi][yi].attstr := evt1.myname
from xi:mypad.rowKeySet(), yi:mypad.colKeySet()
where (mypad[xi][yi].attnum > 100);
These last iteration statements require the creation in memory of value sets resulting from the function calls rowKeySet() and colKeySet(). This may be inconvenient in terms of overhead (memory) for large infopads.