ForEach Statement

This command provides a simplified statement to select data and iteration over the resulting set or subset. This also provides the ability to invoke direct functionality through the set-instance (iterator) variable. The new construct can be used to iterate over any kind of collection.

The general syntax is:

foreachstatement  =
'ForEach', qualifier, 'In', collection, [qualifiers] [gsoption], newline, statements, newline, End

Where 'qualifier' is the instance variable name and 'collection' is the data set to be iterated over.

The ForEach statement allows iteration over a set which might comprise:

  1. Data base records (instances of the data of a persistent class (For example, Ispec)) which might be further selected by use of a where clause or a profile.

  2. The records of an extract file.

  3. The elements of an array.

  4. Items in a list attribute.

While the ForEach statement has sufficient flexibility to replace all current uses of DETERMINE and the looping (multi-retrieval) forms of LOOK.UP, the DETERMINE and LOOKUP commands are still supported to allow users to assimilate the changes more gradually. It will have available the same qualifiers as are available on these commands (SECURE, SERIAL, KEYONLY).

Note: ForEach command does not support MULTI and Group UNTIL option.