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

Multiple levels in ALV TREE

Former Member
0 Likes
2,597

Hi Guys,

I'm trying to display data in alv tree.it is 2 level tree(i.e. header and details).But it is showing only the headers.If I comment the part where header is added,then all items are displayed.I guess somehow levels of tree is getting set as 1.

Please help me on the same

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,456

Hi Vivek ,

Please use the code below for reference ..

 *&      Form  CREATE_ALVTREE_HIERARCHY
*&-------------------------------------------------------------*
*       text
*--------------------------------------------------------------*
*       Builds ALV tree display, (inserts nodes, subnodes etc)
*--------------------------------------------------------------*
form create_alvtree_hierarchy.
  data: ls_sflight type sflight,
        lt_sflight type sflight occurs 0.
  data: ld_ebeln_key type lvc_nkey,
        ld_ebelp_key type lvc_nkey.

  loop at it_ekko into wa_ekko.
    perform add_ekko_node using      wa_ekko
                                     ''
                            changing ld_ebeln_key.


    loop at it_ekpo into wa_ekpo where ebeln eq wa_ekko-ebeln.
      perform add_ekpo_line using      wa_ekpo
                                       ld_ebeln_key
                              changing ld_ebelp_key.
    endloop.
  endloop.

* calculate totals
  call method gd_tree->update_calculations.

* this method must be called to send the data to the frontend
  call method gd_tree->frontend_update.
endform.                    " CREATE_ALVTREE_HIERARCHY

*&---------------------------------------------------------------------*
*&      Form  ADD_EKKO_NODE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_EKPO  text
*      -->P_0553   text
*      <--P_EBELN_KEY  text
*----------------------------------------------------------------------*
form add_ekko_node using    ps_ekko like wa_ekko
                            value(p_relate_key)
                   changing p_node_key.

 data: ld_node_text type lvc_value,
       ls_sflight type sflight.

* Set item-layout
  data: lt_item_layout type lvc_t_layi,
        ls_item_layout type lvc_s_layi.
  ls_item_layout-t_image   = '@3P@'.
  ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
  ls_item_layout-style     = cl_gui_column_tree=>style_default.
  ld_node_text             = ps_ekko-ebeln.
  append ls_item_layout to lt_item_layout.

* Add node
  call method gd_tree->add_node
    exporting
          i_relat_node_key = p_relate_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = ld_node_text
          is_outtab_line   = ps_ekko
          it_item_layout   = lt_item_layout
       importing
          e_new_node_key = p_node_key.
endform.                    " ADD_EKKO_NODE


*&---------------------------------------------------------------------*
*&      Form  ADD_EKPO_LINE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_EKPO  text
*      -->P_LD_EBELN_KEY  text
*      <--P_LD_EBELP_KEY  text
*----------------------------------------------------------------------*
form add_ekpo_line using    ps_ekpo like wa_ekpo
                            value(p_relate_key)
                   changing p_node_key.

 data: ld_node_text type lvc_value,
       ls_sflight type sflight.

* Set item-layout
  data: lt_item_layout type lvc_t_layi,
        ls_item_layout type lvc_s_layi.
  ls_item_layout-t_image   = '@3P@'.
  ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
  ls_item_layout-style     = cl_gui_column_tree=>style_default.
  ld_node_text             = ps_ekpo-ebelp.
  append ls_item_layout to lt_item_layout.

* Add node
  call method gd_tree->add_node
    exporting
          i_relat_node_key = p_relate_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = ld_node_text
          is_outtab_line   = ps_ekpo
          it_item_layout   = lt_item_layout
       importing
          e_new_node_key = p_node_key.
endform.                    " ADD_EKPO_LINE

You can refer to the whole code in link:[http://www.sapdev.co.uk/reporting/alv/alvtree/alvtree_basic.htm]

Hope this helps.

Regards,

Chitra

Hi Guys,

I'm trying to display data in alv tree.it is 2 level tree(i.e. header and details).But it is showing only the headers.If I comment the part where header is added,then all items are displayed.I guess somehow levels of tree is getting set as 1.

Please help me on the same

5 REPLIES 5
Read only

Former Member
0 Likes
1,457

Hi Vivek ,

Please use the code below for reference ..

 *&      Form  CREATE_ALVTREE_HIERARCHY
*&-------------------------------------------------------------*
*       text
*--------------------------------------------------------------*
*       Builds ALV tree display, (inserts nodes, subnodes etc)
*--------------------------------------------------------------*
form create_alvtree_hierarchy.
  data: ls_sflight type sflight,
        lt_sflight type sflight occurs 0.
  data: ld_ebeln_key type lvc_nkey,
        ld_ebelp_key type lvc_nkey.

  loop at it_ekko into wa_ekko.
    perform add_ekko_node using      wa_ekko
                                     ''
                            changing ld_ebeln_key.


    loop at it_ekpo into wa_ekpo where ebeln eq wa_ekko-ebeln.
      perform add_ekpo_line using      wa_ekpo
                                       ld_ebeln_key
                              changing ld_ebelp_key.
    endloop.
  endloop.

* calculate totals
  call method gd_tree->update_calculations.

* this method must be called to send the data to the frontend
  call method gd_tree->frontend_update.
endform.                    " CREATE_ALVTREE_HIERARCHY

*&---------------------------------------------------------------------*
*&      Form  ADD_EKKO_NODE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_EKPO  text
*      -->P_0553   text
*      <--P_EBELN_KEY  text
*----------------------------------------------------------------------*
form add_ekko_node using    ps_ekko like wa_ekko
                            value(p_relate_key)
                   changing p_node_key.

 data: ld_node_text type lvc_value,
       ls_sflight type sflight.

* Set item-layout
  data: lt_item_layout type lvc_t_layi,
        ls_item_layout type lvc_s_layi.
  ls_item_layout-t_image   = '@3P@'.
  ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
  ls_item_layout-style     = cl_gui_column_tree=>style_default.
  ld_node_text             = ps_ekko-ebeln.
  append ls_item_layout to lt_item_layout.

* Add node
  call method gd_tree->add_node
    exporting
          i_relat_node_key = p_relate_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = ld_node_text
          is_outtab_line   = ps_ekko
          it_item_layout   = lt_item_layout
       importing
          e_new_node_key = p_node_key.
endform.                    " ADD_EKKO_NODE


*&---------------------------------------------------------------------*
*&      Form  ADD_EKPO_LINE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_EKPO  text
*      -->P_LD_EBELN_KEY  text
*      <--P_LD_EBELP_KEY  text
*----------------------------------------------------------------------*
form add_ekpo_line using    ps_ekpo like wa_ekpo
                            value(p_relate_key)
                   changing p_node_key.

 data: ld_node_text type lvc_value,
       ls_sflight type sflight.

* Set item-layout
  data: lt_item_layout type lvc_t_layi,
        ls_item_layout type lvc_s_layi.
  ls_item_layout-t_image   = '@3P@'.
  ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
  ls_item_layout-style     = cl_gui_column_tree=>style_default.
  ld_node_text             = ps_ekpo-ebelp.
  append ls_item_layout to lt_item_layout.

* Add node
  call method gd_tree->add_node
    exporting
          i_relat_node_key = p_relate_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = ld_node_text
          is_outtab_line   = ps_ekpo
          it_item_layout   = lt_item_layout
       importing
          e_new_node_key = p_node_key.
endform.                    " ADD_EKPO_LINE

You can refer to the whole code in link:[http://www.sapdev.co.uk/reporting/alv/alvtree/alvtree_basic.htm]

Hope this helps.

Regards,

Chitra

Read only

Former Member
0 Likes
1,456

Hi,

This is a basic question.

There are several standard reports in your SAP system. Look for BCALVTREE in se38.

May it helps you.

Regards.

DS.

Read only

0 Likes
1,456

Thansk Deepak for your reply.

I've been trying.but not finding anything.In another program that I had created,it is working perfectly fine.and i've taken code from there only.This is a already existing module pool in which i'm trying to add a new modal screen.But at any time only one level of hierarchy is displaying only.How to solve that

Read only

0 Likes
1,456

Hi,

Well you can visit this links for your reference.

[ALV tree|http://www.sapdev.co.uk/reporting/alv/alvtree/alvtree_mainsetup.htm]

You can find more help on ALV tree through this link.

Furthermore you can get sample codes of alv tree on sap-technical and other useful sites like abapprogramming.

May it helps you.

Regards.

DS

Read only

Former Member
0 Likes
1,456

Found answer