Runtime Polymorphism / Dynamically load components in Web Dynpro for ABAP

...Previous  

7.     After using component controller will look like as follows:

8.     Now go to main view and select context tab. Now do the context mapping.

9.     Now go to Layout tab. Create one Dropdown UI element. Bind texts property of that UI element with country.

10.  Insert one view container in this view. Give Id as VCO.

11.  Now go to onSelect and write one action DROPDOWN .

12.  Now write the following code in this action.

**********************************************************************
*STEP1 : GET SELECTED COMPONENT NAME FROM DROPDOWN.
**********************************************************************
  
DATA lo_nd_country_comp TYPE REF TO if_wd_context_node.
  
DATA lo_el_country_comp TYPE REF TO if_wd_context_element.
  
DATA lv_wda_component TYPE string .

* navigate from <CONTEXT> to <COUNTRY_COMP> via lead selection
  lo_nd_country_comp 
wd_context->get_child_nodename wd_this->wdctx_country_comp ).

* get element via lead selection
  lo_el_country_comp 
lo_nd_country_comp->get_element( ).

  
IF lo_el_country_comp IS NOT INITIAL.


* get single attribute
    lo_el_country_comp
->get_attribute(
      
EXPORTING
        name 
=  `WDA_COMPONENT`
      
IMPORTING
        
value lv_wda_component ).

**********************************************************************
*STEP2. INSTANTIATE DYNAMIC COMPONENT .
**********************************************************************
    
DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
    lo_cmp_usage 
=   wd_this->wd_cpuse_dynamic_comp( ).
    
IF lo_cmp_usage->has_active_component( ) IS INITIAL.
      lo_cmp_usage
->create_componentlv_wda_component )"Dynamic wda component name.
    
ELSE.
      lo_cmp_usage
->delete_component( ).
      lo_cmp_usage
->create_componentlv_wda_component )"Dynamic wda component name.
    
ENDIF.

**********************************************************************
*STEP3. PERFORM DYNAMIC NAVIGATION.
**********************************************************************

    wd_this
->wd_get_api( )->do_dynamic_navigation(
      source_window_name 
'ZMAIN_COMP' "{this is my window name }
      source_vusage_name 
'MAIN_USAGE_0' "{this one is MAIN--"}
      source_plug_name 
'OUT_PLUG1' "{this plug name can be generated dynamically }
      target_component_name 
'ZINF_TEST'
      target_component_usage 
'DYNAMIC_COMP'
      target_view_name 
'COMMON_WINDOW' "{the view i want to embed}
      target_plug_name 
'DEFAULT'
      target_embedding_position 
'MAIN/VCO' ).
  
ENDIF.  

13.  Now right click on the component and create application to run.  

14.  Output is given below:

15.  If user selects the component 1 then Window and views of first component will be displayed.  

16.  If user selects the component 2 then Window and views of second component will be displayed.  

 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image