Creating dynamic query in Freeform query of browser

Posted by NEHA p. on 16-Sep-2016 07:59

Hi,

actually I am creating a browser based on a table name that is coming from another procedure. So for that I am taking a normal browser but I am not sure how to proceed further on this, since my table name is not fixed and fields are also not fixed, I need to populate fields of the TABLE-NAME that is coming as an input parameter. so I cannot simply use DEFINE QUERY and OPEN QUERY. How to write dynamic query in this case. Please suggest.

Thanks!

All Replies

Posted by Steve Moore on 16-Sep-2016 13:05

This article is a good starting point:

http://knowledgebase.progress.com/articles/Article/P64770

The main parts for your two programs would be something like this:

/* Prog1 */
RUN prog2 (INPUT "Customer",
           INPUT "Customer.CustNum,Customer.Name",
           INPUT "10,50").

/* Prog2 */
DEFINE INPUT PARAMETER pTable AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pFields AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pColWidths AS CHARACTER NO-UNDO.

DEFINE VARIABLE hColumn AS HANDLE NO-UNDO.
DEFINE VARIABLE vCount AS INTEGER NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.

....

CREATE QUERY hQuery.
CREATE BUFFER hBuffer FOR TABLE pTable.
hQuery:SET-BUFFERS(hBuffer).
BROWSE-1:QUERY = hQuery.
/* Add fields */
DO vCount = 1 TO NUM-ENTRIES(pFields):
   ASSIGN hColumn = BROWSE-1:ADD-LIKE-COLUMN(ENTRY(vCount,pFields))
          hColumn:WIDTH = DECIMAL(ENTRY(vCount,pColWidths)).
END.
BROWSE-1:SENSITIVE = YES.
hQuery:QUERY-PREPARE("FOR EACH " + pTable + " NO-LOCK").
hQuery:QUERY-OPEN().
This thread is closed