Try OpenEdge Now
skip to main content
Programming Interfaces
Database Administration Entity Collection Interface Reference : IIterator interface : Examples for using the Iterator method
 

Examples for using the Iterator method

The following code illustrates the use of a collection and iterator, in this case a tenant collection and the iterator used to loop through and allocated tenants:
define variable tenantSet as ITenantSet no-undo.
define variable tenant as ITenant no-undo.
define variable iterator as IIterator no-undo.

tenantSet = service:GetTenants().
iterator = tenantSet:Iterator().
do while iterator:HasNext():
  tenant = cast(iterator:Next(), ITenant).
  If tenant:IsAllocated = false and tenant:Type = "Regular" then
  tenant:Allocate().
end.
service:UpdateTenants(TenantSet).
The Iterator( ) method on IDataAdminCollection is overloaded with a parameter to allow the returned iterator to be filtered, sorted, or both. The following code illustrates the use of the iterator filter to achieve the same result as in the previous example:
define variable tenantSet as ITenantSet no-undo.
define variable tenant as ITenant no-undo.
define variable iterator as IIterator no-undo.

tenantSet = service:GetTenants().
iterator = tenantSet:Iterator("IsAllocated = 'false' and type = 'Regular'").
do while iterator:HasNext():
  tenant = cast(iterator:Next(), ITenant).
  tenant:Allocate().
end.
service:UpdateTenants(TenantSet).
For more information on filtering and sorting entity collections with the IDataAdminCollection iterator, see Filtering and sorting.
See also:
*IDataAdminCollection interface