× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



David,

The fastest and easiest way I have found is to use a table function.
You would write your recursive logic in RPG and wrap that in a table
function. Your program gets called with statuses like begin, next record
and close. You just open the file and return data with a level indicator
when your read requests come in.

David Morris

>>> DSmith@xxxxxxxxx 03/30/05 7:47 AM >>>
I am looking for a good example of breaking down a table that forms a
parent child relationship of unknown levels (Tree structure).

 

PARENT           CHILD

                        A

A                      B          

A                      C          

A                      D                      

B                      E                      

B                      F                      

E                      G                      

E                      J                                   

G                      K                      

H                      L          

 

I saw some good examples of recursive SQL on the web but apparently
that's not allowed on the iSeries V5R2.   I believe in won't be
allowed
under V5R3 but I can not find where I read that.  

 

I get the following message when trying a recursive SQL statement:
Message: [SQL0346] Recursion not allowed for common table expressions.

 

This is the result I'm looking for:

 

LEVEL              PARENT           CHILD  

1                      A                      B          

2                      B                      E          

3                      E                      G          

4                      G                      K          

3                      E                      J

2                      B                      F


1                      A                      C

1                      A                      D

1                      H                      L

 

I can then easily show this as:

LEVEL  1          2          3          4                      

            A          B

                        B          E

                                    E          G

                                                G          K

                                    E          J

                        B          F

            A          C

            A          D

            H          L                      

 

I want to do this for a warehousing application to show who feeds who.
I was able to union a bunch of SQL statements together to achieve the
desired results but it's ugly and does not account for unlimited
levels.
I can do it using RPG or using a combination of RPG and embedded SQL.
Is there a simple SQL only solution that I'm missing?

 

David Smith

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.