Build SAP ALV tree Hierarchy

The following ABAP code and information shows you how to build the tree hierarchy for the example ALV tree report. Simply follow the below instructions and copy and paste the ABAP code into the appropriate includes(PBO and FORM include).


* Add following code to 'STATUS_0100'(PBO module)
*-----------------------------------------------*
* Create ALVtree Hierarchy
  PERFORM create_alvtree_hierarchy.
* Add following code to 'Z......F01' INCLUDE
*--------------------------------------------------*
*&-------------------------------------------------------------*
*&      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

Return to the full list of instructions on how to create an example ALV tree report and find the next steps required to create the fully working demo.


Related Articles

Activate user interaction within SAP ALV tree
Add button to SAP ALV tree toolbar using ABAP code
ABAP ALV Tree tutorial to create a fully working ALVTree Control SAP dynpro program
Create ALV Tree Custom control and add to sap dynpro screen
Final ABAP code for the ALV Tree PBO(..O01) and FORM(..F01) includes
Create SAP ALV Tree Container in ABAP dynpro screen container
Create Container and Object
Create ALV tree main program including Data & Event declaration
SAP ALV Tree fieldcatalog creation
Set SAP ALV tree table for first display and user interaction
Build SAP ALV tree Hierarchy Header
Add alv tree already exists check to pbo module
Create all includes required for the ALV tree report
Full ABAP code listing of main ALV tree program
Module creation screen
Create SAP ALV Tree object within ABAP dynpro screen container/H1>
Create ok code to store ALV tree user interaction
Example Output from ALV tree display
Create screen control
Create Screen along with PBO and PAI modules
Create Pf-status(screen menu functionality)
Refresh ALVtree
Build Report Header(Title)
ALVtree toolbar processing
Implement user defined buttons to ALVtree toolbar
ALVtree user interaction processing
Implement ALVtree user interaction processing
Setup ALVtree variant
Main Steps to create ALV simple Tree(Using Objects)
Create Add Custom control to screen
Final code for the PBO(..O01) and FORM(..F01) includes
Create Container and Object
Create and register events for user interaction
Create ALVtree Hierarchy
Add already exists check!
Create Includes for ALVtree report
Full ABAP code listing of main program
Create Container and Object
Create screen control
Example Output from ALV simple tree display
Create screen control
Create Screen along with PBO and PAI modules
Create Pf-status(screen menu functionality)