Wednesday, 21 February 2018

How to implement Link to action in ABAP webdynpro ALV

If you include the standard webdynpro ALV component SALV_WD_TABLE into your own component, you could not directly change the ALV table column as usual. In ABAP Webdynpro an example of link to action element used in ALV looks like below. Once the column “Social Media Post ID” is clicked, it is expected our application could catch the event and implement our own event handling logic.

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

You could follow the steps below:
1. Define the component usage to ALV component by double clicking your webdynpro component in SE80 and maintain the component usage in tab “Used Web Dynpro Components”

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

2. Double click the INTERFACECONTROLLER_USAGE,add your own component for ALV component usage. The reason for this is you need to map the context node of your own component to ALV component, so that it can know which data from your application should display.

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

After that it is ready for mapping the context node of your component to the context node DATA of ALV component. You can achieve it via drag and drop or right click on DATA node, and choose “Define External Mapping” from context menu. After mapping is done, you could see the mapping path displayed below.

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

3. double click on your view, and insert a new element “ViewContainerUIElement”, which acts as the container for ALV interface view to be embedded.

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

then double click on window, right click the ViewContainerUIElement and choose “Embed View”, include the ALV interface view from drop down list.

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

The final settings looks like below. Now you should already see the ALV in your application UI.

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

Create a new method in view controller and implement the code below:
method RENDER_HYPERLINK .
  DATA:
    lr_alv_usage       TYPE REF TO if_wd_component_usage,
    lr_if_controller   TYPE REF TO iwci_salv_wd_table,
    lr_config          TYPE REF TO cl_salv_wd_config_table,
    lr_column_settings TYPE REF TO if_salv_wd_column_settings,
    lt_columns         TYPE        salv_wd_t_column_ref,
    lr_link            TYPE REF TO cl_salv_wd_uie_link_to_action.
   lr_alv_usage = wd_this->wd_cpuse_salv_wd_table( ).
   IF lr_alv_usage->has_active_component( ) IS INITIAL.
     lr_alv_usage->create_component( ).
   ENDIF.
   lr_if_controller = wd_this->wd_cpifc_salv_wd_table( ).
   lr_config        = lr_if_controller->get_model( ).
   lr_config->if_salv_wd_table_settings~set_cell_action_event_enabled( abap_false ).
   lr_column_settings ?= lr_config.
   lt_columns = lr_column_settings->get_columns( ).
   LOOP AT lt_columns ASSIGNING FIELD-SYMBOL(<column>).
      CASE <column>-id.
        WHEN 'INTERNAL_ID'.
          CREATE OBJECT lr_link.
          lr_link->set_text_fieldname( <column>-id ).
         <column>-r_column->set_cell_editor( lr_link ).
        WHEN OTHERS.
      ENDCASE.
   ENDLOOP.
endmethod.
And call it in wddomodifyview of view controller:

METHOD wddomodifyview .
  CHECK first_time = abap_true.
  render_hyperlink( ).
ENDMETHOD.
Note: according to sap help, the event ON_CLICK is only triggered if the method IF_SALV_WD_TABLE_SETTINGS~SET_CELL_ACTION_EVENT_ENABLED is set to FALSE Otherwise, the event ON_CELL_ACTION is triggered.

4. Create a event handler in view controller Methods tab. Choose the event name ON_CLICK from drop down list.

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

In the runtime, the selected item index and item value could be found in importing parameter R_PARAM:

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

UI Web Dynpro ABAP, SAP ABAP Development, SAP ABAP Guides, SAP ABAP Tutorials and Materials

2 comments:


  1. Useful Information, your blog is sharing unique information....
    Thanks for sharing!!!
    SAP Consulting Services in usa
    sas value added reseller

    ReplyDelete
  2. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    Online SuccessFactors training

    ReplyDelete