Table name as parameter

bohrmann

Member
Hello,
I'd like to develop a code which handles queries submitted by users. Users can select which table they want to see.
I'm listing the tables via a screen using _file system table, and when a user selected one of them, I store it in a char variable. But I can't pass it to the include file like this:

def var v_table as char.
{query.i &tbl = "v_table"}

The .i file inserts v_table itself, not its value, thus it can't be compiled:

for each {&tbl} :
display {&tbl}.
end.

The error message is :
Unknown or ambiguous table v_table

Is there any way to resolve this situation? I use only character interface, in Unix.
Thanks in advance.
 
This won't work - the include file is expanded out at compile time, and so you can't use includes to produce a flexible FOR EACH like this. FOR EACH is a static construct, and unless you want to compile-on-the-fly, you won't be able to achieve anything in this manner.

You don't mention your progress version. If your version supports it, you need to use a dynamic query to do this.
 
Thanks for your answer, I was expecting something like this. Progress 9, so it should be possible to use dynamic query, just I've never done...
Anyway, I'll try this way.
 
Thanks again, Andrew, works fine, but an additional problem came up when trying this :

DO WHILE NOT qh:QUERY-OFF-END :
DO i = 1 TO bh:NUM-FIELDS :
PUT bh:BUFFER-FIELD(i):BUFFER-VALUE.
END.
qh:GET-NEXT().
END.

I was not able to export tables that contain extent fields.
Any idea?
 
Yeah, with extents you have to loop through them all. So this:

DO i = 1 TO bh:NUM-FIELDS :
PUT bh:BUFFER-FIELD(i):BUFFER-VALUE.
END.

becomes something like this:

Code:
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
DEFINE VARIABLE iField AS INTEGER NO-UNDO.
DEFINE VARIABLE iExtent AS INTEGER NO-UNDO.
 
DO iField = 1 TO hBuffer:NUM-FIELDS:
    hField = hBuffer:BUFFER-FIELD(iField).
    IF hField:EXTENT > 0 THEN
    DO:
        DO iExtent = 1 TO hField:EXTENT:
            PUT hField:BUFFER-VALUE[iExtent].
        END.        
    END.
    ELSE
    DO:
        PUT hField:BUFFER-VALUE.        
    END.
END.
 
Back
Top