Refresh ALVtree

Refreshing the ALV tree display is not actually as simple as it sounds, as there is no actual refresh functionality available. You basically have to delete all the toplevel nodes and then re-add everything as if you are building the hierachy from new.


Declare table to store top leve nodes in top include

types: begin of t_topnodes,
 nodekey type lvc_nkey,
end of t_topnodes.
data: it_topnodes type standard table of t_topnodes,
      wa_topnodes like line of it_topnodes.


Add code to build top level node table
*&----------------------------------------------------------*
*&      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.

        wa_topnodes-nodekey = ld_ebeln_key.
        append wa_topnodes to it_topnodes.

    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


Add code to to the ALV Tree user command functionality
*************************************************
*  EXAMPLE CODE used for demonstration purpose **
************************************************* 
*-------------------------------------------------------------------*
*       CLASS lcl_toolbar_event_receiver IMPLEMENTATION
*-------------------------------------------------------------------*
*       ........                                                    *
*-------------------------------------------------------------------*
class lcl_toolbar_event_receiver implementation.
  method on_function_selected.
    data: ls_gmsec type zgmsec,
           ld_answer type c.
    case fcode.
      when 'CHNG'.
        data: ld_uname type zgmuserparam-uname.
        data: lt_selected_node type lvc_t_nkey.
        call method tree1->get_selected_nodes
          CHANGING
            ct_selected_nodes = lt_selected_node.
        call method cl_gui_cfw=>flush.
        data l_selected_node type lvc_nkey.
        check not lt_selected_node[] is initial.
        read table lt_selected_node into l_selected_node index 1.
        call method tree1->get_outtab_line
          EXPORTING
            i_node_key    = l_selected_node
          IMPORTING
            e_outtab_line = ls_gmsec.
        if ls_gmsec-uname is initial.
          message i010(ad) with 'Please choose a valid user'.
        else.

*       Example: i.e calls screen to allow user to make chnage
          call screen 0300.

* AT this point user has returned from a screen (i.e. 300) which
* allowed them to make changes to existing data/node
* The following code deletes all the existing nodes using the top
* node table populated earlier
          loop at it_topnodes into wa_topnodes.
            call method TREE1->DELETE_SUBTREE
              EXPORTING
                i_node_key = wa_topnodes-nodekey.
          endloop.
          call method cl_gui_cfw=>flush.

* Now you need to re-select your data and re-build your hierarchy
* from scratch. for example the code could look somthing like this.
          REFRESH: it_ekko, it_ekpo.
          SELECT ebeln
          UP TO 10 ROWS
            FROM ekko
            INTO corresponding fields of TABLE it_ekko.
          loop at it_ekko into wa_ekko.
            SELECT ebeln ebelp statu aedat matnr menge meins
                   netpr peinh
              FROM ekpo
              appending TABLE it_ekpo
             where ebeln eq wa_ekko-ebeln.
          endloop.
          perform create_alvtree_hierarchy. 

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
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)
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)