Skip to Content
Author's profile photo Sankara Bhatta

WD_BADI_DOMODIFYVIEW- Little known things

I am sure every developer worked in SAP SRM 7.0 knows this BADI by heart. It is used to modify SRM webUI dynamically using some custom logic(look at my blog for more details Web UI modifications in SRM7). Till sometime back I was under the impression that we can only access layout and context of a specific view inside this BADI. But recently I have discovered that there are lot of thing that we can access inside this BADI. In this blog I am going to discuss my findings about those.

Access the document data during creation of document

Developers often faced challenge of accessing document data inside this BADI during document creation stage ( please note the data is not stored in database yet, it is still in buffer ). to solve this puzzle we can take help of task container classes. Below is the code snippet for the same

Data Declarations for all the code snippets involved in this blog

DATA: lo_comp TYPE REF TO  cl_wdr_delegating_view,
         lo_co_name TYPE string,
         lo_co TYPE REF TO cl_wdr_delegating_component,
         lo_task_container_factory TYPE REF TO /sapsrm/if_cll_taskcon_factory.
   lo_task_container type ref to /sapsrm/if_cll_task_container,
   lo_pd_model type ref to /sapsrm/if_pdo_model_access.
         lt_item               TYPE bbpt_pd_item,
         ls_item               TYPE bbp_pds_item,
         ls_item_e             TYPE bbp_pds_sc_item_d,
         ls_header             TYPE bbp_pds_header,
         ls_tab_requested      TYPE bbps_detail_requested,
         lv_value TYPE string,
         lv_guid TYPE crmd_orderadm_h-guid,
         lo_sc_instance TYPE REF TO /sapsrm/if_pdo_bo_sc_adv.
   FIELD-SYMBOLS: <lo_dodm_acc> TYPE REF TO /sapsrm/if_cll_dodm_account,
                  <lo_bom> TYPE REF TO /sapsrm/if_cll_bo_mapper.
DATA: lv_string TYPE string,
         lv_string2 TYPE string,
         lo_co_context TYPE REF TO if_wd_context_node,
         lo_co_delegate TYPE REF TO if_wdr_component_delegate.
   DATA: lo_view_delegate TYPE REF TO if_wdr_view_delegate,
         lo_nd_user_details TYPE REF TO if_wd_context_node,
         lo_nd_comp TYPE REF TO if_wd_context_node,
         lo_el_user_details TYPE REF TO if_wd_context_element,
         ls_account TYPE /sapsrm/s_ch_wd_map_acc.

Code to retrieve document details from buffer

*get object reference to task container factory

   lo_task_container_factory =  /sapsrm/cl_ch_wd_taskcont_fact=>get_instance( ).
IF lo_task_container_factory IS NOT INITIAL.
*get reference to task container
     lo_task_container = lo_task_container_factory->get_task_container( ).
IF lo_task_container IS NOT INITIAL.
*read the GUID.
       lo_task_container->get_bo_guid( RECEIVING rv_bo_guid = lv_guid ).
*Get instance of PDO model
       lo_pd_model = /sapsrm/cl_pdo_model_factory=>get_instance( ).
*Fill in the flags for the required data
       ls_tab_requested-item_tab = abap_true.
       ls_tab_requested-orgdata_tab = abap_true.
*Get details of the document from the Buffer. This is like a call to FM BBP_PROCDOC_DETAIL
       lo_pd_model->get_detail( EXPORTING iv_guid = lv_guid
*                                     iv_object_id = iv_object_id
                                          iv_object_type = /sapsrm/if_pdo_obj_types_c=>gc_pdo_shop
                                          iv_with_itemdata = 'X'
                                          is_read_flags = ls_tab_requested
IMPORTING es_header = ls_header
                                          et_item  = lt_item ).

Get the WD component and View name that we are currently viewing

I think getting the view name is straight forward and many of you might already know it, but getting the WD component name is bit tricky. Here is the code snippet

*Do a widening cast of VIEW instance to  cl_wdr_delegating_view
   lo_comp ?= view.
*Read attribute 'COMPONENT' and do a widening cast to cl_wdr_delegating_component
     lo_co ?= lo_comp->component .
*Read attribute 'COMPONENT_NAME' which contains WD component name
     lo_co_name = lo_co->component_name.
*View name can be read by VIEW->name

Access attributes of the view

The plot thickens from here ūüôā . Here I have accounting WD component /SAPSRM/WDC_UI_DO_ACC and view  V_DO_ACCOUNTING as an example. let’s say we want to access attribute ‘MO_DODM_ACCOUNTING’. Below is the code snippet.

*We need this for accessing attribute reference
*Get the reference of view controller using DELEGATE attribute
       lo_view_delegate = lo_comp->delegate.
*We have to access the attribute dynamically. Static access is not possible
ASSIGN lo_view_delegate->(lv_string) TO <lo_dodm_acc>.

Now we have the reference to the attribute, we can use it to access attributes and methods accounting DODM class.

Access attributes from component controller

This was a surprise to me. I want to access MO_BOM attribute declared under component controller. here is the code snippet

*We need this for accessing attribute referencebute reference
*Get the reference for component controller using DELEGATE attribute
lo_co_delegate = lo_co->delegate.
*We have to access the attribute dynamically. Static access is not possible.
ASSIGN lo_co_delegate->(lv_string2) TO <lo_bom>.

Access context of component controller

I just tried it and it worked ūüôā . I want to access node ‘ACCOUNTING’ from component context. Here is the code snippet

*Get the reference to context of component controller
lo_co_context = lo_co->if_wdr_context~root_node
*Get the reference to node 'COMP_CONTEXT
   lo_nd_comp = lo_co_context->get_child_node( name = 'COMP_CONTEXT').
*Get the reference of child node 'ACCOUNTING'
   o_nd_user_details = lo_nd_comp->get_child_node( name = 'ACCOUNTING').
* @TODO handle non existant child
       IF lo_nd_user_details IS NOT INITIAL.
* get element via lead selection
         lo_el_user_details = lo_nd_user_details->get_element( ).
* @TODO handle not set lead selection
         IF lo_el_user_details IS NOT INITIAL.
* get values of  attributes
             static_attributes =  ls_account ).

This is the end of my tryst with WD_BADI_MODIFYVIEW BADI.

Thanks for taking time and reading my blog.

Have a nice day and keep sharing ūüôā

Assigned Tags

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

      Good Work

      Author's profile photo sankara rao bhatta
      sankara rao bhatta
      Blog Post Author

      Thanks tamil

      Author's profile photo Bharathi P
      Bharathi P

      Thoroughly enjoyed reading this where I was searching for these kind of information for a long time. Thanks a lot for sharing this info.

      Best Regards,


      Author's profile photo sankara rao bhatta
      sankara rao bhatta
      Blog Post Author

      Hi Bharathi,

      I am glad that the blog helped you.

      Author's profile photo Former Member
      Former Member

      Great job buddy. Seriously came to know lots of new things.

      Author's profile photo sankara rao bhatta
      sankara rao bhatta
      Blog Post Author

      Hi Siddarth,

      I am glad it helped you.

      Author's profile photo Former Member
      Former Member

      Hi Sankara,

      If I need to change field at runtime like process_type in the Shopping cart header. Can I change it from here?

      Author's profile photo sankara rao bhatta
      sankara rao bhatta
      Blog Post Author

      you can use doc_change badi

      Author's profile photo Former Member
      Former Member

      thanks Mr. Sankara,

      I make the enhancement in the bom class

      Author's profile photo Joseph Fryda
      Joseph Fryda

      Great job man

      I have a little question regarding access attributes.

      I wondering how to read attribute SIMU_COMP_ALL from component

      In the badi I wrote:

        DATA: lv_string        TYPE string,
      lo_view_delegate TYPE REF TO if_wdr_view_delegate,

      SPAN {
      font-family: "Courier New";
      font-size: 10pt;
      color: #000000;
      background: #FFFFFF;
      .L0S52 {
      color: #0000FF;
      .L0S55 {
      color: #800080;
      lo_comp                  TYPE REF TO  cl_wdr_delegating_view.

      lo_comp ?= view.
           lo_view_delegate = lo_comp->delegate.
      lv_string = 'IF_V_BID_COMPARISON~MV_ADV_COMP'.
      ASSIGN lo_view_delegate->(lv_string) to <mv_adv_comp>.

      But it is not working...
      Any ideas?