Using Consultingwerk foreach includes

The following document describes how to use the Consultingwerk foreach include files. With the use of these include files your code is more comfortable to read due to the fact that recurring code like the variable definition or the enumerator is removed from your actual source code. Every include file simplifies the usage of Lists and Enumerators in the ABL, similar to the foreach statement in C#.

Here is the list of the include files:

Include File Name

Use to iterate what kind of Lists


Used to iterate .NET Lists, Arrays, etc. Works with any set that implements the System.Collections.IEnumerable interface. This include file is in particular very helpful to translate C# code to ABL code.


Used to iterate the Consultingwerk List and GenericList classes or any other type that implements the Consultingwerk.Framework.Base.IEnumerable   interface.


Used to iterate the Consultingwerk list of ABL primitive values (CharacterList, IntegerList, etc.).

DEFINE VARIABLE poNodes AS Infragistics.Win.UltraWinTree.TreeNodesCollection.
{Consultingwerk/foreach.i Infragistics.Win.UltraWinTree.UltraTreeNode oNode in poNodes}
    IF oNode:IsRootLevelNode = TRUE THEN
        oNode:Override:NodeAppearance:BackColor = System.Drawing.Color:Green.

The example demonstrates the functionality of the “foreach.i” include. The foreach statement repeats a group of embedded statements for each element in a .NET array or an object collection that implements the System.Collections.IEnumerable interface.

The first parameter is the type of the variable that holds the element which is in the current iteration of the loop, the second parameter is the variable name used to access the current element in the loop. Third parameter "in" should always be "in", to simulate the C# syntax as a place holder. The fourth parameter is the reference to the collection which you need to iterate through. The optional fifth parameter may be set as "nodefine" to avoid the creation of the variables. Set the fifth parameter to “nodefine”, if you need to iterate the same collection twice in the same method. The “nodefine” parameter has to be added to the second iteration to avoid the declaration of the variables with the same name in the include file again.

DEFINE VARIABLE oList AS Consultingwerk.ListNameValuePair NO-UNDO.

oList:Add ("Carlo", "cat":U).
oList:Add ("Susi", "dog":U).
oList:Add ("Mickey", "mouse":U).
{Consultingwerk/foreachABL.i Consultingwerk.NameValuePair oPair in oList}
    MESSAGE oPair:Value

This example demonstrates how to use similar code to iterate the elements referenced in a set of ABL objects. The collection has to implement the Consultingwerk.Framework.Base.IEnumerator interface. The parameter description is the same as in the first example.

DEFINE VARIABLE oElements AS Consultingwerk.Framework.Collections.CharacterList NO-UNDO.
oElements:Add ("cat").
oElements:Add ("dog").
oElements:Add ("mouse"). 
{Consultingwerk/foreachPrimitiveList.i Character cEntry in oElements}               
    MESSAGE cEntry        

This example demonstrates how to use similar code to iterate the elements referenced in a set of ABL primitive values. The following types of enumerators are currently implemented:

The parameter description is the same as in the first example.


As the first parameter to the foreachABLPrimitiveList.i Include File is used to build the name of the Enumerator class (e.g. CharacterEnumerator) it is recommended to use the casing of the element parameter type exactly as “Character”, “Integer” and “Handle” (capital first letter only). Customers that may have to deploy to Unix or Linux systems may encounter runtime or compile time errors otherwise.