Hi,
I am trying to get the recursive data-relation example working but until now to no avail.
I have populated a db-table Employee with 4 records.
This is my code:
-
DEFINE TEMP-TABLE ttEmployee
FIELD cEmployee AS CHARACTER
FIELD cManager AS CHARACTER
FIELD iAge AS INTEGER
INDEX idxEmployee AS UNIQUE cEmployee.
DEFINE DATASET myRecurs FOR ttEmployee
DATA-RELATION r1 FOR ttEmployee, ttEmployee
RELATION-FIELDS (cEmployee, cManager) RECURSIVE.
DEFINE QUERY qEmp FOR Employee.
DEFINE DATA-SOURCE dsEmployee FOR QUERY qEmp Employee.
QUERY qEmp:QUERY-PREPARE("for each Employee where cEmployee = 'Dave'").
BUFFER ttEmployee:ATTACH-DATA-SOURCE(DATA-SOURCE dsEmployee:HANDLE).
DATASET myRecurs:FILL().
-
At the moment of filling the dataset I get a program exception error and Progress dies on me.
What am i doing wrong here? Am i missing something?
TIA
Pieter Brouwer
Assuming that your Employee table has the fields cEmployee, cManager and iAge, right?
Change the order of QUERY and BUFFER. Try this one:
DEFINE TEMP-TABLE ttEmployee
FIELD cEmployee AS CHARACTER
FIELD cManager AS CHARACTER
FIELD iAge AS INTEGER
INDEX idxEmployee AS UNIQUE cEmployee.
DEFINE DATASET myRecurs FOR ttEmployee
DATA-RELATION r1 FOR ttEmployee, ttEmployee
RELATION-FIELDS (cEmployee, cManager) RECURSIVE.
DEFINE QUERY qEmp FOR Employee.
DEFINE DATA-SOURCE dsEmployee FOR QUERY qEmp Employee.
BUFFER ttEmployee:ATTACH-DATA-SOURCE(DATA-SOURCE dsEmployee:HANDLE).
QUERY qEmp:QUERY-PREPARE("for each Employee where cEmployee = 'Dave'").
DATASET myRecurs:FILL().
Thank you Salvador. That made everything work as expected.
Does this mean that my original sequence of statements is actually wrong in every situation or only in the case of recursive relations?
(I guess your answer is going to be that it can't hurt to always do the prepare after the attach :-? )
When you can please log a call with TechSupport for the first code sample to investigate further the exception error.