mikelcid
New Member
Hi all!
I am doing a method that create a dataset adding relations between different tables and selecting from then some data filtered by where clauses, all this done dynamically because I give the names of the tables, the fields used to add the relations and the where clauses in variables.
So the question is, in the following code where should I place FILL-WHERE-STRING to filter each table?
I am doing a method that create a dataset adding relations between different tables and selecting from then some data filtered by where clauses, all this done dynamically because I give the names of the tables, the fields used to add the relations and the where clauses in variables.
So the question is, in the following code where should I place FILL-WHERE-STRING to filter each table?
Code:
CREATE DATASET phDataSet. DO iEntry = 1 TO NUM-ENTRIES(pcBuffers):
phDataSet:ADD-BUFFER(WIDGET-HANDLE(ENTRY(iEntry, pcBuffers))).
END.
DEFINE VARIABLE iw_tablas AS INTEGER NO-UNDO.
iw_tablas = NUM-ENTRIES(pcSources, ",").
DO iEntry = 1 TO iw_tablas:
FOR EACH _File WHERE _File._File-Name = ENTRY(iEntry,pcSources,",") NO-LOCK,
EACH _Index WHERE _Index._File-recid = RECID(_File) NO-LOCK:
IF _Index._Unique = TRUE THEN DO:
FOR EACH _Index-Field WHERE _Index-Field._Index-recid = RECID(_Index) NO-LOCK,
FIRST _Field OF _INdex-Field NO-LOCK:
IF pcSourceKeys = "" THEN
pcSourceKeys = _Field._Field-Name.
ELSE
pcSourceKeys = pcSourceKeys + "," + _Field._Field-Name.
END.
END.
END.
END.
DEFINE VARIABLE tablas AS CHARACTER NO-UNDO.
DEFINE VARIABLE iw_relaciones AS INTEGER NO-UNDO.
DEFINE VARIABLE t1 AS INTEGER NO-UNDO.
DEFINE VARIABLE t2 AS INTEGER NO-UNDO.
iw_relaciones = NUM-ENTRIES(pcFields, "|").
DO iEntry = 1 TO iw_relaciones:
tablas = ENTRY(iEntry,pcTablas,"|").
t1 = INT(ENTRY(1,tablas,",")).
t2 = INT(ENTRY(2,tablas,",")).
phDataSet:ADD-RELATION(phDataSet:GET-BUFFER-HANDLE(t1),
phDataSet:GET-BUFFER-HANDLE(t2),
ENTRY(iEntry,pcFields,"|")).
END.
DO iEntry = 1 TO NUM-ENTRIES(pcSources):
CREATE DATA-SOURCE hDataSource.
CREATE BUFFER hBuffer FOR TABLE ENTRY(iEntry, pcSources).
hDataSource:ADD-SOURCE-BUFFER(hBuffer, ENTRY(iEntry,pcSourceKeys)).
IF lp_batch THEN
phDataSet:GET-BUFFER-HANDLE(iEntry):BATCH-SIZE = 100.
phDataSet:GET-BUFFER-HANDLE(iEntry):ATTACH-DATA-SOURCE(hDataSource).
END.
phDataSet:FILL().