Skip to Content

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.

     endif.

   else.

     raise exception type cx_wdr_rt_exception

         exporting

            textid = cx_wdr_rt_exception=>method_not_valid_for_phase

            msgv1  = ‘IF_WD_VIEW_CONTROLLER~GET_CURRENT_ACTION’

            msgv2  = ‘WDDOBEFOREACTION’.

   endif.

endmethod.

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:

METHOD Y_GET_CURRENT_ACTION .

   IF me->action_accessor->is_valid = abap_true.

     result = me->action_accessor->current_action.

   ENDIF.

ENDMETHOD.

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.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply