Iterate OpenEdge collections and maps

Posted by Johan Vergeer on 13-Jul-2017 07:45

Hi everyone, 

I just found out that OpenEdge does provide collections. https://documentation.progress.com/output/oehttpclient/oe116/index.html

Currnently I have succeeded in adding items to a map / collection. (That was the easy part). Now I am wondering on how to get the data out of the collection. 

A simple Example. 

CLASS Order:

    DEFINE PUBLIC PROPERTY OrderNo AS INT NO-UNDO

        GET.

        SET.

In a procedure. 

USING OpenEdge.Core.Collections.Map.

USING Order.

DEF VAR oOrder as Order NO-UNDO.

DEF VAR oOrders as Map NO-UNDO.

oOrders = new Map().

oOrder = new Order().

oOrder:OrderNo = 123456.

oOrders.Put(123456, oOrder).

// Now iterate over the collection. In C# this would be something like:

foreach (Order order in oOrders) {

System.Out.Println(order.OrderNo);

}

How van this be done in ABL for Collections and Maps?

Posted by Peter Judge on 13-Jul-2017 08:38

You have to do it ‘old school’ collection style
- get an iterator
- loop over the iterator - HasNext() + Next()
 
A simple example from the URI class
 
    method public integer GetQueryNames(output pcNames as character extent):
        define variable iCount    as integer   no-undo.
        define variable oIterator as IIterator no-undo.
       
        assign iCount    = this-object:QueryMap:Size
               oIterator = cast(this-object:QueryMap:KeySet, IIterable):Iterator()
               .
        if iCount gt 0 then
            assign extent(pcNames) = iCount.
       
        assign iCount = 0.
        do while oIterator:HasNext():
            assign pcNames[iCount + 1] = oIterator:Next():ToString()
                   iCount              = iCount + 1.
        end.
       
        return iCount.
    end method.
 
 
 

All Replies

Posted by Peter Judge on 13-Jul-2017 08:38

You have to do it ‘old school’ collection style
- get an iterator
- loop over the iterator - HasNext() + Next()
 
A simple example from the URI class
 
    method public integer GetQueryNames(output pcNames as character extent):
        define variable iCount    as integer   no-undo.
        define variable oIterator as IIterator no-undo.
       
        assign iCount    = this-object:QueryMap:Size
               oIterator = cast(this-object:QueryMap:KeySet, IIterable):Iterator()
               .
        if iCount gt 0 then
            assign extent(pcNames) = iCount.
       
        assign iCount = 0.
        do while oIterator:HasNext():
            assign pcNames[iCount + 1] = oIterator:Next():ToString()
                   iCount              = iCount + 1.
        end.
       
        return iCount.
    end method.
 
 

Posted by Johan Vergeer on 14-Jul-2017 00:20

Thanks for your fast response, Peter

Posted by Lieven De Foor on 14-Jul-2017 04:48

What we really need is generics so we can have typed collections.

Non-generic collections in the .NET framework are long deprecated (stackoverflow.com/.../are-non-generic-collections-in-net-obsolete, docs.microsoft.com/.../when-to-use-generic-collections).

While I appreciate the effort Peter has put into this, Progress should really start working on generics...

Meanwhile you can get somewhere near generic functionality by using include files but that's really just an ugly workaround...

Posted by Peter Judge on 14-Jul-2017 16:52

I completely agree Lieven

Posted by Johan Vergeer on 17-Jul-2017 00:29

+1 from me too, Peter and Lieven

Posted by Mike Fechner on 17-Jul-2017 01:24

 
Those are – like Lieven suggested – trying to work around this by using Include files. There are generic lists and dictionaries and a C# like foreach statement – eh Include file.
 
Von: Johan Vergeer [mailto:bounce-johanvergeer@community.progress.com]
Gesendet: Montag, 17. Juli 2017 07:31
An: TU.OE.Development@community.progress.com
Betreff: RE: [Technical Users - OE Development] Iterate OpenEdge collections and maps
 
Update from Progress Community
 

+1 from me too, Peter and Lieven

View online

 

You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

Flag this post as spam/abuse.

 

This thread is closed