The LOOP function executes a function or group of functions a specified number of times. LOOP is generally used to process arrays (repeating groups) and/or to write multiple target records from a single source.
Category
Specialized
Syntax
LOOP(condition) { action }
Parameters and Descriptions
Parameter | Description |
---|---|
condition | This parameter specifies a logical value that is tested to determine if the associated action is to be executed. If the condition of the logical function is true, then the action is executed. Otherwise, the action is not executed. |
action | A function or group of functions that are to executed if the condition is true. |
Example
Each time the value of source field SRC_FLD1 is an A, write ten (10) target records to the target datastore TGT_DS. Use variable V_COUNTER for loop control.
DECLARE V_COUNTER 2 '0';
IF SRC_FLD1 = 'A'
{
V_COUNTER = 0
LOOP(V_COUNTER < '10')
{
SRC_FLD1 = TGT_FLD1
SRC_FLD2 = TGT_FLD2
OUTDS(TGT_DS)
V_COUNTER = INCREMENT(V_COUNTER)
}
}