Iterate OpenEdge collections and maps - Forum - OpenEdge Development - Progress Community

Iterate OpenEdge collections and maps

 Forum

Iterate OpenEdge collections and maps

This question is answered

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?

Verified Answer
  • 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
  • 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.
     
     
  • Thanks for your fast response, Peter

  • 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...

  • I completely agree Lieven

  • +1 from me too, Peter and Lieven

  •  
    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.

     

    Architect of the SmartComponent Library and WinKit

    Consultingwerk Ltd.