Consultor Eletrônico



Kbase 20295: Implementing FIRST-OF functionality against a dynamic query
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/15/2008
Status: Verified

FACT(s) (Environment):

Progress 9.x

SYMPTOM(s):

The FIRST-OF function does not work with a dynamic query

CAUSE:

In Progress 9.0A the query-object or "dynamic query" was introduced into the 4GL that gave Progress programmers a whole world of new functionality.

This functionality includes the ability to more easily and effectively develop applications for deployment in a distributed computing environment as well as the capability to completely modify the query at run-time.

With the query object however, the often called upon capability of the FOR EACH statement that allowed the programmer to create break groups and use the FIRST-OF and LAST-OF functions to determine if you are at the first or last of a group of records does not exist.

While this functionality is not available to the query-object by default, it is possible to regain the ability to accomplish this with the 4GL.


FIX:

The following code demonstrates how to emulate the FIRST-OF function when working with the query, buffer and buffer-field objects.

This code works with the Order table of the Sports2000 database:


DEFINE VARIABLE hQ AS HANDLE    NO-UNDO.
DEFINE VARIABLE hB AS HANDLE    NO-UNDO.
DEFINE VARIABLE hF AS HANDLE    NO-UNDO.
DEFINE VARIABLE hO AS HANDLE    NO-UNDO.
DEFINE VARIABLE cF AS CHARACTER NO-UNDO.

CREATE QUERY hQ.
CREATE BUFFER hB FOR TABLE "Order".

hQ:SET-BUFFERS(hB).
hQ:QUERY-PREPARE("FOR EACH Order NO-LOCK BY CustNum").
hQ:QUERY-OPEN().
hQ:GET-FIRST().

ASSIGN hF = hB:BUFFER-FIELD("CustNum")
 hO = hB:BUFFER-FIELD("OrderNum").

DO WHILE NOT hQ:QUERY-OFF-END:
 DISPLAY hF:BUFFER-VALUE hO:BUFFER-VALUE WITH DOWN FRAME xx.
 IF cF NE hF:BUFFER-VALUE THEN
DO:
    ASSIGN cF = hF:BUFFER-VALUE.
   DISPLAY "First-Of" WITH DOWN FRAME xx.
 END.
 DOWN WITH FRAME xx.
 hQ:GET-NEXT().
END.