Skip to Content
Author's profile photo Sergei Korolev

Obtaining current action reference for standard commands of WDA ALV component

When developing a WDA you can run into a problem when you need to perform different tasks depending on actual standard action the user selected. The proper place to do this is your view WDDOBEFOREACTION method. The problem is that WD runtime does not return proper reference to the IF_WD_ACTION interface for standard SALV component actions while calling back your WDDOBEFOREACTION. Namely lo_api_controller->get_current_action( ) returns null reference.

The reason why get_current_action returns nothing is that the controller of the action is not the current view controller as seen in the IF_WD_VIEW_CONTROLLER~GET_CURRENT_ACTION method:

method if_wd_view_controller~get_current_action.

   data: l_action type ref to if_wdr_action.

   if me->action_accessor->is_valid = abap_true.

     l_action ?= me->action_accessor->current_action.

     if l_action->controller = me.

       result = me->action_accessor->current_action.



     raise exception type cx_wdr_rt_exception


            textid = cx_wdr_rt_exception=>method_not_valid_for_phase


            msgv2  = ‘WDDOBEFOREACTION’.



After some digging into the source code I found a solution. The key point  is that when you obtain a reference to the current view controller by calling

wd_this->wd_get_api method actually you receive a reference to an instance of cl_wdr_delegating_view class. I enhanced the class by adding the following method:


   IF me->action_accessor->is_valid = abap_true.

     result = me->action_accessor->current_action.



In WDDOBEFOREACTION I use the following snippet to call enhanced method:

   DATA lo_delegating_view TYPE REF TO cl_wdr_delegating_view.

   DATA lo_api_controller TYPE REF TO if_wd_view_controller.

   lo_api_controller = wd_this->wd_get_api( ).

   lo_delegating_view ?= lo_api_controller.

     lo_action = lo_delegating_view->y_get_current_action( ).

Still works.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      in this sentence is happening a dump

      lo_delegating_view ?= lo_api_controller.