How to populate a temp-table Dynamically

Hi,

Please tell me how can I populate the temp-table from a Dataset.

I have set of datasets each has more than one Temp table schema and data (Each time temp table structure varies ). What I would like to do is after a procedure run , I should be able to write code

For each temp-XXXXX :
Disp temp-XXXXX.YYYY.
end.

For this I need to create the temp-table dynamically. Is it possible?

FYI - I could prepare the query from the following code. But my requirement is to prepare the temp-table. Is it possible? Please help me.

REPEAT icount = 1 TO hDataSet:NUM-TOP-BUFFERS:
hBuffer = hDataSet:GET-TOP-BUFFER(iCount).
RUN p_querybuild(INPUT hBuffer).
END.

PROCEDURE p_querybuild :
DEFINE INPUT PARAMETER iphBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
DEFINE VARIABLE iField AS INTEGER NO-UNDO.
CREATE QUERY hQuery.
hQuery:SET-BUFFERS((iphBuffer)).
hQuery:QUERY-PREPARE("FOR EACH " + iphBuffer:TABLE + " NO-LOCK").
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().
OUTPUT TO c:\X.txt APPEND.
DO WHILE hQuery:QUERY-OFF-END = FALSE:
DO iField = 1 TO iphBuffer:NUM-FIELDS:
hField = hBuffer:BUFFER-FIELD(iField).
EXPORT hField:BUFFER-VALUE.
END.
hQuery:GET-NEXT().
END.
OUTPUT CLOSE.
END PROCEDURE.
 
The FOR EACH you mention you want to use is reference to a static TEMP-TABLE. Whether you can access the TEMP-TABLE that way depends on the fact how the TEMP-TABLE is defined at compile time ( static ) or created at runtime ( dynamic ) in the first place. TEMP-TABLE which are defined at compile time can be accessed using the static buffer associated with them, but you can also access them "dynamically" when you grab the handle ( hHandle = BUFFER ttMyTable:HANDLE ) to the buffer associated with it. TEMP-TABLES which are created at runtime can only be accessed via their handle or the handle to a buffer associated with them.

The same is mostly true for ProDataSets. When they are defined at compile time you can directly reference the static temp-tables they contain. When they are created dynamically at runtime you need to go and grab the handle to the temp-table.

As for the prepare: You don't prepare a static TEMP-TABLE, you do this only for dynamic ones, instead you define them at design time. But if you use a dynamic TEMP-TABLE then there is no way a classic FOR EACH will work.

First you should check how the ProDataSet is defined or created.

Heavy Regards, RealHeavyDude.
 
Back
Top