Consultor Eletrônico



Kbase P5172: Is it possible to use table name as a variable and run: FOR EACH
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   16/10/2008
Status: Unverified

GOAL:

Is it possible to use table name as a variable and run: FOR EACH <variable name>

GOAL:

Is it possible to use table name as a variable

FACT(s) (Environment):

All Supported Operating Systems
Progress 9.x
OpenEdge 10.x

FIX:

It is not possible to do this per se, however you can use a Dynamic Buffer with a Dynamic Query in Version nine and later to accomplish this.
e.g.
DEFINE INPUT PARAMETER pcName AS CHARACTER NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
CREATE BUFFER hBuffer FOR TABLE pcName.
CREATE QUERY hQuery.

hQuery:SET-BUFFERS(hBuffer).
hQuery:QUERY-PREPARE("FOR EACH " + pcName). /* Concatenate your query predicate to this */
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().
DO WHILE NOT hQuery:QUERY-OFF-END:
hQuery:GET-NEXT().
END.
/* Make sure you cleanup all dynamically created objects */
hQuery:QUERY-CLOSE().
DELETE OBJECT hQuery.
DELETE OBJECT hBuffer.