Only for Specialist? How to build a 4-GL-FIND LAST/FIRST-Statement as a dynamic query

psuter

New Member
Example:

tabA:
Contract#
Plan#
Generation#
Datebegin

4-GL-Statement:

FIND FIRST tabA WHERE taba.contract# = 10 AND taba.plan# = 99 AND taba.datebegin = TODAY().

Please, don't return dynamic solutions like:
...
whQuery:OpenQuery("FOR EACH tabA WHERE taba.contract# = 10 AND taba.plan# = 99 AND taba.datebegin = TODAY()").

whQuery:GET-FIRST().
...

Thanks for your help, Pascal

---------------------------------------
Pascal Suter
G: 01 284 42 14
P: 01 383 89 84
e-Mail: pascal.suter@swisslife.ch
---------------------------------------
 
Pascal

I think the only way to create dynamic queries is to use the methods like open-query and get-first.

Please excuse this solution if it's trival but it's the only thing I can guess you may be after:

Code:
def var li_contact as integer no-undo.
def var li_plan as integer no-undo.
def var ld_begin as date no-undo.

assign
    li_contact = 10
    li_plan = 99
    ld_begin = today().

find first tabA where
    tabA.contact# = li_contact and
    tabA.plan# = li_plan and
    tabA.datebegin = ld_begin
    no-lock no-error.

Of course the variables assigned above could be collected by user input with the update statement.

Simon
 

psuter

New Member
Thans for your help. I see, the only way to do this dynamically is an QUERY-Open(..) and a GET-FIRST(..). In the meanwhile I have realized that the QUERY-OPEN(..) function does not start the query and return records to the client. This happens, when I use the GET-FIRST(), GET-NEXT() or GET-LAST() Function afterwards. I made a test where I set the CACHE attribute of the query-handle to 100000 and called GET-LAST() on a table with many 10000 records:

whQuery:QUERY-PREPARE("FOR EACH TabA NO-LOCK").
whQuery:QUERY-OPEN().
whQuery:CACHE = 100000.
whQuery:GET-LAST().

I did not have to wait one second, because only one record is returned and not all records of tabA.

First I wondered, why progress does not allow a dynamic Query-Statement like "FOR LAST .." or "FOR FIRST ..", but only "FOR EACH ..". Now, I think there must be a reason, because the "FOR EACH.." query in combination with GET-FIRST() or GET-LAST() has the same effect as writing FOR LAST
TabA or FOR FIRST tabA.

Am I right?

Pascal
:chat:
 
Top