How to replace a table's name

CLK

New Member
How can I replace this code and convert it code in a dynamic query code:

For each Customer:
display Customer.Name.
end.

I 'm using V8.3 and I want create a Custome Query (dynamic Query), I want replace the table's name with a variable... for example:

define var v_TableName AS character no-undo.
define var v_FieldName AS character no-undo.

ASSIGN
v_TableName = "Customer"
v_FieldName = "Name".

FOR EACH v_TableName:
DISPLAY v_Field:Name.
END.

Thank
 
in v8 you would have to use preprocessores its not dynamic but you dont have to code much.

&glob tablename customer
&glob FieldName name

FOR EACH {&TableName}:
DISPLAY {&Name}.
END.
 
Sorry, no "real" dynamic stuff in version 8 (so an upgrade to version 9 might be a great idea if you want to go really dynamic)...

But, apart from pre-processors you can also use an include file to do at least something with version 8:
Create an include file (say we will call it foreach.i) that contains:
Code:
FOR EACH {1} NO-LOCK:
  DISPLAY {2}.
END.
And then use it in your programs:
Code:
{foreach.i "TableName" "Field1 Field2 Field3"}
That way you can at least re-use your code.
 
Back
Top