Quantcast
Channel: SCN : All Content - ABAP for SAP HANA
Viewing all articles
Browse latest Browse all 831

How to read the hierarchy data from the same table using loop in AMDP method

$
0
0

Hi All,

 

We have a requirement to get the top partner from BUT050 table.

Here the Top parent is nothing but the top most in the hierarchy of the partners from BUT050.

 

Example:

For partner 1234 (BUT050-PARTNER1) there is partner 3523(BUT050-PARTNER2) one level above

For partner 3523(BUT050-PARTNER1)  there is partner 4544 (BUT050-PARTNER2) last level .

 

so in this case for the partner 1234 the Top parent is 4544 .

 

I have created AMDP Procedure method to get the top-parnet and below given is the logic implemented in AMDP method.

Here i have implemented a recursive logic with the WHILE loop to get the top most hierarchy partner from the same table BUT050

 

IV_Parent is the input partner and ev_top_parent is the output value.

 

AMDP Procedure Method:

    DECLARE lv_date VARCHAR(8) := TO_VARCHAR (current_date, 'YYYYMMDD');

    DECLARE found INT := 1;

 

          iv_partner1 =  SELECT partner1 FROM but050

                          WHERE partner2 = iv_partner

                          AND reltyp = :iv_hierarchy

                          AND date_to >=  :lv_date

                          AND date_from <= :lv_date;

 

     WHILE found <> 0  do

 

       select partner1 into ev_top_parent from :iv_partner1;

                       iv_partner1 =  SELECT partner1 FROM but050

                       WHERE partner2 in ( select partner1 from :iv_partner1 where partner1 is not null)

                       AND reltyp = 'ZBP004'

                       AND date_to >= :lv_date

                       AND date_from <= :lv_date;

       select COUNT ( partner1 ) INTO found FROM :IV_PARTNER1;

    END WHILE;

 

This method is working fine, but here it is only taking one single partner and getting the top parent as output.

 

Now i would like to convert this mehtod so as to accept n number of partners (not one single partner) as input and should process each partner to get the top parent.

 

Could anyone guide me how can i handle the given AMDP method further so as to work some how it is within another loop from other AMDP method.

Thanks.

 

Regards,

Laxman.P


Viewing all articles
Browse latest Browse all 831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>