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.
This article is a good starting point:
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().