User:anonymousLog inRegister
Recents:
Recursive Data Providers

Data Providers can fill recursive structures, either directly or through recursive calls.

Consider an 'Employee' transaction with the following structure:

Employee

EmployeeId*

EmployeeName

BossId subtype of EmployeeId

BossName subtype of EmployeeName

Example 1

Suppose it is necessary to load an employee's information into a structure (for example to send it as a parameter to another object). First, the SDT should be defined as follows:

Image:Employee SDT

Note that this is a Recursive SDT. Then, a Data Provider receiving the employee will solve the problem:

Image:DP Load EmployeeSDT

Where:

Output: EmployeeSDT

Collection: False

Parm( &EmployeeId );

This is a recursive Data Provider. DPLoadEmployee is calling itself to fill the recursive member of the EmployeeSDT. For example, the XML output  (DPLoadEmployee( 123 ).toXML()) would be:

 <EmployeeSDT>
<Id>123</Id>
<Name>John Doe</Name>
<Manager>
<Id>99</Id>
<Name>Mary Shelley</Name>
<Manager>
<Id>69</Id>
<Name>Ernest Jackson</Name>
<Manager></Manager>
</Manager>
</Manager>
<EmployeeSDT>

Example 2

Now suppose that given an employee, we have to Output all his/her subordinates (direct or indirect), as shown below:

<SubEmployees>
<Employee>

<Id>99</Id>

<Name>Mary Shelley</Name>

<Subordinates>

<Employee>

<Id>123</Id>

<Name>John Doe</Name>

<Subordinates>

...

</Subordinates>

</Employee>

<Employee>

<Id>150</Id>

<Name>Camile Green</Name>

<Subordinates>

...

</Subordinates>

</Employee>

...

</Subordinates>

</Employee>

<Employee>

...

</Employee>

....

</SubEmployees>

This can be easily done with a Data Provider.

First, it is necessary to define the Output structure (this is done using an SDT):

Image:Recursive SDT 'SubEmployees'

Second, the Data Provider itself is:

Name:   DPLoadSubordinates
Output: SubEmployees
Rules: parm(&BossId)

SubEmployees

{

Employee

where BossId = &BossId

{

Id = EmployeeId

Name = EmployeeName

Subordinates = DPLoadSubordintates( EmployeeId )

}

}

Note that this is a recursive Data Provider (DPLoadSubordinates is calling itself).


Created: 07/14/07 09:59 PM by jnj Last update: 01/29/09 04:01 PM by lsilveira
 
Page
Categories
Group
 
Powered by GXwiki 3.0 (generated with GeneXus X Evolution 1 U3)