Skip to main content


ITERATE(recordset, transform [, LOCAL ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )

recordsetThe set of records to process.
transformThe TRANSFORM function to call for each record in the recordset.
UNORDEREDOptional. Specifies the output record order is not significant.
ORDEREDSpecifies the significance of the output record order.
boolWhen False, specifies the output record order is not significant. When True, specifies the default output record order.
STABLEOptional. Specifies the input record order is significant.
UNSTABLEOptional. Specifies the input record order is not significant.
PARALLELOptional. Try to evaluate this activity in parallel.
numthreadsOptional. Try to evaluate this activity using numthreads threads.
ALGORITHMOptional. Override the algorithm used for this activity.
nameThe algorithm to use for this activity. Must be from the list of supported algorithms for the SORT function's STABLE and UNSTABLE options.

LOCAL Optional. Specifies the operation is performed on each supercomputer node independently, without requiring interaction with all other nodes to acquire data; the operation maintains the distribution of any previous DISTRIBUTE.

Return: ITERATE returns a record set.

The ITERATE function processes through all records in the recordset one pair of records at a time, performing the transform function on each pair in turn. The first record in the recordset is passed to the transform as the first right record, paired with a left record whose fields are all blank or zero. Each resulting record from the transform becomes the left record for the next pair.

TRANSFORM Function Requirements - ITERATE

The transform function must take at least two parameters: LEFT and RIGHT records that must both be of the same format as the resulting recordset. An optional third parameter may be specified: an integer COUNTER specifying the number of times the transform has been called for the recordset or the current group in the recordset (see the GROUP function).


ResType := RECORD
  INTEGER1 Rtot;

Records := DATASET([{1,0},{2,0},{3,0},{4,0}],ResType);
/* these are the recs going in: 
Val Rtot 
 1   0
 2   0
 3   0
 4   0 */

ResType T(ResType L, ResType R) := TRANSFORM
  SELF.Rtot := L.Rtot + R.Val;
  SELF := R;

MySet1 := ITERATE(Records,T(LEFT,RIGHT));

/* these are the recs coming out: 
Val Rtot
 1   1
 2   3
 3   6
 4   10 */

//The following code outputs a running balance:
Run_bal := RECORD
  INTEGER8 Balance := 0;
TradesBal := TABLE(Trades,Run_Bal);

Run_Bal DoRoll(Run_bal L, Run_bal R) := TRANSFORM
  SELF.Balance := L.Balance + IF(validmoney(R.trd_bal),R.trd_bal,0);
  SELF := R;

MySet2 := ITERATE(TradesBal,DoRoll(LEFT,RIGHT));

See Also: TRANSFORM Structure, RECORD Structure, ROLLUP