Skip to end of metadata
Go to start of metadata

Author: Thomas Jung
Submitted: April 12, 2007

Description

The same person who had asked me how to hook an event handler into the standard ALV APPEND/INSERT buttons came back a day later and had a good follow up question. He said that he had the eventing and everything working just great on his first ALV component, but now he had a new requirement: he needed to be able to use more than one ALV within the same view.

Solution

This is not difficult to do at all, so I set out to adjust the first example by adding in a tabstrip. In one tab I would display SFLIGHT in an ALV. In the second tab I would display the contents of a related sample table - SBOOK in another ALV component.

  • We start off be declaring a second component usage for the same SALV_WD_TABLE component. This works fine because each usage gets its own unique name (you will see in moment how this effects access to the component via coding). This is like in OO when you have the same class, but you want to have two or more instances of the class. You just create two different object references.
  • The same holds true for the Used Controllers/Components references at teh controller or view level. You just need to add the second component usage.
  • Now we can adjust the initialization coding in the DOINIT method of the Component Controller. The component controller class is generated, so it has methods to reflect the names of each component usage. In the earlier example we accessed the component usage named ALV via the method WD_CPUSE_ALV. To access the second usage named 2ND_ALV, we use the method that was generated for this name - WD_CPUSE_2ND_ALV. Pretty Cool!
      DATA isflight TYPE STANDARD TABLE OF sflight.
      DATA isbook   TYPE STANDARD TABLE OF sbook.
      SELECT * FROM sflight INTO TABLE isflight.
      SELECT * FROM sbook   INTO TABLE isbook.
    
      DATA:
        node_sflight                        TYPE REF TO if_wd_context_node,
        node_sbook                          TYPE REF TO if_wd_context_node.
    
    *   navigate from <CONTEXT> to <SFLIGHT> via lead selection
      node_sflight = wd_context->get_child_node( name = wd_this->wdctx_sflight ).
      node_sbook   = wd_context->get_child_node( name = wd_this->wdctx_sbook ).
    
    *   @TODO handle not set lead selection
      IF ( node_sflight IS INITIAL ).
        EXIT.
      ENDIF.
    
      node_sflight->bind_table( isflight ).
      node_sbook->bind_table( isbook ).
    
      DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.
      l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
      IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
        l_ref_cmp_usage->create_component( ).
      ENDIF.
      DATA l_salv_wd_table TYPE REF TO iwci_salv_wd_table.
      l_salv_wd_table = wd_this->wd_cpifc_alv( ).
      DATA l_table TYPE REF TO cl_salv_wd_config_table.
      l_table = l_salv_wd_table->get_model( ).
    
      l_table->if_salv_wd_table_settings~set_read_only( abap_false ).
      l_table->if_salv_wd_std_functions~set_edit_insert_row_allowed( ).
      l_table->if_salv_wd_table_settings~set_data_check( if_salv_wd_c_table_settings=>data_check_on_cell_event ).
    
    
      DATA: l_ref_cmp_usage2 TYPE REF TO if_wd_component_usage.
    
      l_ref_cmp_usage2 =   wd_this->wd_cpuse_2nd_alv( ).
      IF l_ref_cmp_usage2->has_active_component( ) IS INITIAL.
        l_ref_cmp_usage2->create_component( ).
      ENDIF.
      DATA l_salv_wd_table2 TYPE REF TO iwci_salv_wd_table.
      l_salv_wd_table2 = wd_this->wd_cpifc_2nd_alv( ).
      DATA l_table2 TYPE REF TO cl_salv_wd_config_table.
      l_table2 = l_salv_wd_table2->get_model( ).
      l_table2->if_salv_wd_table_settings~set_read_only( abap_false ).
      l_table2->if_salv_wd_std_functions~set_edit_insert_row_allowed( ).
      l_table2->if_salv_wd_table_settings~set_data_check( if_salv_wd_c_table_settings=>data_check_on_cell_event ).
    
    
  • Next we will change the design of our view to have the tabstrip. In side each tab, we will place a ViewUIElementContainer.
  • From the window maintenance, each separate container is available. Inside each we can place the appropriate ALV Component Usage.
  • It is even possible to go back to the view and have separate event handlers for each inner ALV component usage. That way we have a nice clear association between event handler methods and the objects they are listed for events from.
  • Finally you can see that the example results in two completely independent instances of the ALV Component running within the same view. We used a tab strip to separate them in this example, but there is really no reason why they couldn't have even be side by side.

Source Code

If you would like to import the entire Web Dynpro Component of this example; the following is a link to a SAPlink SLNK file that contains the project. You will need at least the 1.3 version of SAPlink and the Web Dynpro Component plug-in to import the SLNK.
http://abap-sdn-examples-tpj.googlecode.com/files/WDYN_ZMULTIPLE_ALV.slnk