Skip to Content

Standard account assignment search helps in Custom SRM Developments

Why

When creating custom developments in SRM I often struggled on the creation of proper search helps for account assignment types like WBS-element or cost center. A lot of times I solved this problem by creating an Search help in SRM by using a search help exit I called an RFC in the back-end system(ERP). The problem with this approach is that it doesn’t reflect the search helps which you can find for example in the account assignment tab in the shopping cart.

Step by step

In this blog I’ll describe step by step how you can attach the same account assignment search helps as in for example the account assignment tab of the shopping cart.

In this step by step description I used the example displayed below.

This basic example can be download as a nugget file. More information on how to import nugget files into your sap system see the following page:

SAPlink – ABAP Development – SCN Wiki

Note: If you use the example. The context attribute names of the account_assingment element need to be changed from costcenter to cost_ctr and wbs_element to wbs_elem_e

Step 1 – Component Usage

We want to use the standard search helps therefore we first need to define a component usage for the Web Dynpro Component which we are going to use.

This can be done at the tab Used components as follows:

For the Component use name use for example “USAGE_SH_F4”.

The WD Component which is providing us the searchhelps is “/SAPSRM/WDC_UI_BACKEND_SH”.

At the view where we want to use the account assignment search helps add the component usages. This can be done at the properties tab of the view.

Step 2 – Context binding and event handler creation

We need to change some values in the context node of the used component for getting the values from the searchhelp to for example the Cost Center field which is defined in our example application.

To be able to access the context node drag the selection node from the right to the left.

To retrieve the selected data from the search help and display it in the view we need to handle the DATA_SELECTED event of the /SAPSRM/WDC_UI_BACKEND_SH component. This can be done by adding a event handler in the method tab of the view.

Step 3 –  Set the input help mode

To be able to show the correct search help we need to set the Input help mode from ‘Automatic’ to ‘Freely Programmed’ and as Input Help Component Usage we set ‘USAGE_SH_F4’ and per context item we need to set which search help needs to be opened.

This can be programmed in the method WDDOMODIFYVIEW of the view.


 DATA:  lo_helper       TYPE REF TO /sapsrm/if_pdo_acct_assgt_hlpr.
   DATA   lr_node_data    TYPE REF TO if_wd_context_node.
   DATA   lr_node_info    TYPE REF TO if_wd_context_node_info.
   DATA   lt_logsys       TYPE bbpt_logical_system.
   DATA   ls_logsys       LIKE LINE OF lt_logsys.
   DATA   lt_messages     TYPE bbpt_balmi.

   IF first_time EQ abap_true.
     lr_node_data = wd_context->get_child_node( 'ACCOUNT_ASSINGMENT' ).
     lr_node_info = lr_node_data->get_node_info( ).

 * Set logsys for Search helps
     CALL FUNCTION 'BBP_GET_BACKEND_SYSTEMS'
       TABLES
         et_logical_systems = lt_logsys
         et_messages        = lt_messages.

     READ TABLE lt_logsys INTO ls_logsys INDEX 1.
     IF sy-subrc EQ 0.
       lo_helper = /sapsrm/cl_pdo_valhelp_factory=>get_acct_assgt_helper( ).
       lo_helper->set_searchhelp_control( EXPORTING iv_logsys = ls_logsys-logsys ).
     ENDIF.

 * Set the searchhelp for WBS-Element
     lr_node_info->set_attribute_value_help(
       EXPORTING
         name            = 'WBS_ELEM_E'
         value_help_mode = lr_node_info->c_value_help_mode-application_defined
         value_help      = 'USAGE_SH_F4' ).

 * Set the searchhelp for Cost Center
     lr_node_info->set_attribute_value_help(
       EXPORTING
         name            = 'COST_CTR'
         value_help_mode = lr_node_info->c_value_help_mode-application_defined
         value_help      = 'USAGE_SH_F4' ).

   ENDIF.



The search helps will now be shown.

The only thing now to do is to get the selected account asignment and handle the data selected event ‘DATA_SELECTED’.

Step 4 – Retrieving the selected data

To retrieve the selected data the earlier defined event handler ‘ON_F4_SELECTED’ needs to be implemented.


*--------------------------------------------------------------------*
 * Set the selected value to the corresponding field value.
 *--------------------------------------------------------------------*
   DATA: lr_node      TYPE REF TO if_wd_context_node,
         ls_selection TYPE if_v_main=>element_selection.

   lr_node = wd_context->get_child_node( 'SELECTION' ).
   lr_node->get_static_attributes( IMPORTING static_attributes = ls_selection ).
   lr_node = wd_context->get_child_node( 'ACCOUNT_ASSINGMENT' ).

   CASE ls_selection-field_name.
     WHEN 'WBS_ELEM_E'.
       lr_node->set_attribute( name = 'WBS_ELEM_E' value = ls_selection-field_data ).
     WHEN 'COST_CTR'.
       lr_node->set_attribute( name = 'COST_CTR'   value = ls_selection-field_data ).
   ENDCASE.



In this example code we move the values from the ‘SELECTION’ node to the corresponding attribute in the ‘ACCOUNT_ASSIGNMENT’ node.

Final

If all steps are followed you should be able to select a value with the search help provided by the standard web dynpro component ‘/SAPSRM/WDC_UI_BACKEND_SH’.

The final result can also be download as a nugget.

Final result

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