Dynamic Looping

Is it possible to write a dynamic for each loop to display records on different sorting fields based on variable conditions??

i.e. when condition 1:
for each table1 by field1:
disp field1 field2.
end.

when condition 2:
for each table1 by field2:
disp field1 field2.
end.

Since all the logic remains the same, I don't want to be so silly to write 2 exact loop just different on sorting sequence. Can any expert give me advice??
 

mra

Junior???? Member
Hi Kenneth.

It's not too difficult to do, all you have to do is to use dynamic queries (Form version 9.0 I think).


NOTE HOWEVER!!

On HPUX-11 Progress version 9.0 and maybe later, there is a bug when using dynamic queries. I you fire many dynamic queries in a row (A loop where each iteration fires a dynamic query), the progress server will dump with an out of memory error.


Regards
Mike

Example:

def var hQry as handle.
def var hBuf as handle.
def var hField as handle.
def var cQuery as char no-undo.

create buffer hBuf for table "CUSTOMER".
create query hQry.


cQuery = substitute( "for each CUSTOMER where CUST_NO = 1234" ).

hQry:set-buffers( hBuf ).
hQry:query-prepare( cQuery ).
hQry:query-open.
hQry:get-first.

do while not hQry:query-off-end :
hField = hBuf:buffer-field( "NAME" ).
disp hField:buffer-value.
hQry:get-next.
end.

hQry:query-close.

delete object hBuf.
delete object hQry.
 
Top