Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Parent and child relationship using OOPS

Former Member
0 Likes
697

Hello experts,

I have to create a tree that displays parents with its childrens. I have code from which i have created a tree but next what i want to do is achieve relationship as

  • Product_1
    • Child A
    • Child B
  • Product_2

I have attached code and screen shot of table below if anybody have idea regarding this issue please share it with me.

form create_hierarchy .

   data: lt_products type table of /nyh/ap_products,

         ls_products type /nyh/ap_products,

         lr_product type ref to /nyh/cl_ap_product,

         lt_versions type /nyh/ap_t_version,

         ls_versions type /nyh/ap_s_version,

         lr_version type ref to /nyh/cl_ap_version,

*        lt_versions type table of /nyh/versions,

         ls_version type /nyh/ap_versions,

         lt_packages type table of /nyh/ap_packages,

         ls_packages type /nyh/ap_packages,

         ls_tree type /nyh/ap_s_tree_data,

         l_version type c length 8.

   data: l_top_key type lvc_nkey,

         l_product_key type lvc_nkey,

         l_version_key type lvc_nkey,

         l_last_key type lvc_nkey.

* Add one Generic node at the top

   ls_tree-node_type = c_node_top.

   perform add_node using 'Applicon Products'

                          ls_tree

                          ''

                 changing l_top_key.

   select *

     from /nyh/ap_products

     into table lt_products.

   loop at lt_products into ls_products.

     clear: ls_tree, lt_versions, ls_versions, lt_packages, ls_packages.

     create object lr_product

       exporting

         i_product         = ls_products-product

       exceptions

         product_not_found = 1

         others            = 2.

     if sy-subrc <> 0.

       continue.

     endif.

     move-corresponding ls_products to ls_tree.

     ls_tree-node_type = c_node_product.

     perform add_node using ls_products-product

                            ls_tree

                            l_top_key

                   changing l_product_key.

     call method lr_product->get_versions

       receiving

         et_versions       = lt_versions

       exceptions

         no_versions_found = 1

         others            = 2.

     if sy-subrc <> 0.

       continue.

     endif.

     loop at lt_versions into ls_versions.

       clear: l_version, ls_tree.

       ls_version = ls_versions-r_version->get_version( ).

       move-corresponding ls_version to ls_tree.

       ls_tree-node_type = c_node_version.

       call function 'CONVERSION_EXIT_ZVERS_OUTPUT'

         exporting

           input  = ls_version-version

         importing

           output = l_version.

       perform add_node using l_version

                              ls_tree

                              l_product_key

                     changing l_version_key.

       lt_packages = ls_versions-r_version->get_packages( ).

       loop at lt_packages into ls_packages.

         clear: ls_tree.

         move-corresponding ls_products to ls_tree.

         move-corresponding ls_versions to ls_tree.

         move-corresponding ls_packages to ls_tree.

         ls_tree-node_type = c_node_package.

         perform add_leaf using ls_tree

                                l_version_key

                       changing l_last_key.

       endloop.

     endloop.

   endloop.

   call method gr_alv_tree->expand_node

     exporting

       i_node_key = l_top_key.

endform.                    " CREATE_HIERARCHY






Thanks,


Avadhut

Hello experts,

I have to create a tree that displays parents with its childrens. I have code from which i have created a tree but next what i want to do is achieve relationship as

  • Product_1
    • Child A
    • Child B
  • Product_2

I have attached code and screen shot of table below if anybody have idea regarding this issue please share it with me.

form create_hierarchy .

   data: lt_products type table of /nyh/ap_products,

         ls_products type /nyh/ap_products,

         lr_product type ref to /nyh/cl_ap_product,

         lt_versions type /nyh/ap_t_version,

         ls_versions type /nyh/ap_s_version,

         lr_version type ref to /nyh/cl_ap_version,

*        lt_versions type table of /nyh/versions,

         ls_version type /nyh/ap_versions,

         lt_packages type table of /nyh/ap_packages,

         ls_packages type /nyh/ap_packages,

         ls_tree type /nyh/ap_s_tree_data,

         l_version type c length 8.

   data: l_top_key type lvc_nkey,

         l_product_key type lvc_nkey,

         l_version_key type lvc_nkey,

         l_last_key type lvc_nkey.

* Add one Generic node at the top

   ls_tree-node_type = c_node_top.

   perform add_node using 'Applicon Products'

                          ls_tree

                          ''

                 changing l_top_key.

   select *

     from /nyh/ap_products

     into table lt_products.

   loop at lt_products into ls_products.

     clear: ls_tree, lt_versions, ls_versions, lt_packages, ls_packages.

     create object lr_product

       exporting

         i_product         = ls_products-product

       exceptions

         product_not_found = 1

         others            = 2.

     if sy-subrc <> 0.

       continue.

     endif.

     move-corresponding ls_products to ls_tree.

     ls_tree-node_type = c_node_product.

     perform add_node using ls_products-product

                            ls_tree

                            l_top_key

                   changing l_product_key.

     call method lr_product->get_versions

       receiving

         et_versions       = lt_versions

       exceptions

         no_versions_found = 1

         others            = 2.

     if sy-subrc <> 0.

       continue.

     endif.

     loop at lt_versions into ls_versions.

       clear: l_version, ls_tree.

       ls_version = ls_versions-r_version->get_version( ).

       move-corresponding ls_version to ls_tree.

       ls_tree-node_type = c_node_version.

       call function 'CONVERSION_EXIT_ZVERS_OUTPUT'

         exporting

           input  = ls_version-version

         importing

           output = l_version.

       perform add_node using l_version

                              ls_tree

                              l_product_key

                     changing l_version_key.

       lt_packages = ls_versions-r_version->get_packages( ).

       loop at lt_packages into ls_packages.

         clear: ls_tree.

         move-corresponding ls_products to ls_tree.

         move-corresponding ls_versions to ls_tree.

         move-corresponding ls_packages to ls_tree.

         ls_tree-node_type = c_node_package.

         perform add_leaf using ls_tree

                                l_version_key

                       changing l_last_key.

       endloop.

     endloop.

   endloop.

   call method gr_alv_tree->expand_node

     exporting

       i_node_key = l_top_key.

endform.                    " CREATE_HIERARCHY






Thanks,


Avadhut

1 REPLY 1
Read only

Former Member
0 Likes
649

This message was moderated.