Search code examples
progress-4glopenedge4gl

4GL ABL Openedge loop through handle?


here is my current code

def var hbTT as handle.

for each Cust:
  hbTT:buffer-create().
  assign
    hbTT::Name    = Cust.Name
    hbTT::address = Cust.Address.
end.

now what I want to do is to loop through hbtt. How can I do that?

I tried

for each hbTT:
  /* Do something */
end.

the error I get is

unknown or ambiguous table hbTT. (725)

thank you


Solution

  • You won't be able to do a loop that way, as for each requires a static name. Instead, try this:

    DEFINE VARIABLE hQuery AS HANDLE      NO-UNDO.
    
    create query hQuery.
    hQuery:set-buffers(hbtt).
    hquery:query-prepare('for each tt'). /* <-- Where tt is the original buffer name */
    hquery:query-open().
    
    hquery:get-first().
    do while not hquery:query-off-end:
        disp hbtt::name hbtt::address .
        hquery:get-next().
    end.