Recursive logic using datastage

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Sandeepch19
Participant
Posts: 36
Joined: Fri May 21, 2010 12:40 am
Location: Bangalore

Recursive logic using datastage

Post by Sandeepch19 »

Hi,
We have a requirement to implement a recursive logic for example

Key ParentKey
1 2
2 3
4 1
5 4
3 6

1 is the record i have but i need to get parent and its grand parent and its great grang parent.like this i have to go till i don't find any record.

Can we implement the above logic using DS 8.7 . Please let me know

Regards,
Sandeep
Sandeep Chandrashekar
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Re: Recursive logic using datastage

Post by SURA »

If your source is from table, then better to do it there!
Thanks
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
ssnegi
Participant
Posts: 138
Joined: Thu Nov 15, 2007 4:17 am
Location: Sydney, Australia

Reply

Post by ssnegi »

create parameter pInitialValue to determine starting point for Key
Then sort the data in ascending order based on Key.
Then add transformer stage.
Create stage variables vkey and vparent.
vkey derivation :
if DSLink.Key = pInitialValue or DSLink.Key = parent then DSLink.Key else 0
vparent derivation :
DSLink.Parent
In the output put contraint : vkey <> 0
In the output columns put the stage variables vkey, vparent

This will work is the parent key is greater than the key for every record.
Post Reply