Spend Management Blogs by Members
Check out community member blog posts about spend management and SAP Ariba, SAP Fieldglass, and SAP Concur solutions. Post or comment about your experiences.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member184741
Active Contributor

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.
DATA:
         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 ).
ENDIF.
ENDIF.
IF lv_guid IS NOT INITIAL.
*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 ).
ENDIF.
ENDIF.




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 :smile: . 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
lv_string = 'IF_V_DO_ACCOUNTING~MO_DODM_ACCOUNTING'.
*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
lv_string2 = 'IF_COMPONENTCONTROLLER~MO_BOM'.
*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 :smile: . 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
           lo_el_user_details->get_static_attributes(
           IMPORTING
             static_attributes =  ls_account ).
         ENDIF.
ENDIF.


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 :smile:

10 Comments