Fetching attribute of SAP Webdynpro component in new component

You need to do the below steps in order to pass values from one Webdynpro component to another:

  • Create both components
  • In the first component, create a method which will call the second component
  • Create a parameter in the context of the first component which will be passed
  • Call the first component; once the URL has been generated just append the parameter which needs to be passed

Step-by-Step Implementation

Step 1: Creating Context Parameter in First Component

In your first component's context, create a parameter that holds the value to be passed ?

* In Component Controller of First Component
* Create context attribute, for example: EMPLOYEE_ID
DATA: lo_element TYPE REF TO if_wd_context_element,
      lv_employee_id TYPE string.

* Set the value
lv_employee_id = '12345'.
lo_element = wd_context->get_element( ).
lo_element->set_attribute( name = 'EMPLOYEE_ID' value = lv_employee_id ).

Step 2: Creating Method to Call Second Component

Create a method in the first component that generates the URL for the second component and appends the parameter ?

METHOD call_second_component.
  DATA: lv_url TYPE string,
        lv_param TYPE string,
        lo_window_manager TYPE REF TO if_wd_window_manager,
        lo_api_component TYPE REF TO if_wd_component.

  * Get the parameter value from context
  lo_element = wd_context->get_element( ).
  lo_element->get_attribute( EXPORTING name = 'EMPLOYEE_ID' 
                           IMPORTING value = lv_param ).

  * Generate URL for second component
  lo_api_component = wd_comp_controller->wd_get_api( ).
  lo_window_manager = lo_api_component->get_window_manager( ).
  
  lv_url = 'https://server:port/sap/bc/webdynpro/namespace/second_component'.
  
  * Append parameter to URL
  CONCATENATE lv_url '?employee_id=' lv_param INTO lv_url.
  
  * Navigate to second component
  lo_window_manager->create_external_window( url = lv_url ).
ENDMETHOD.

Step 3: Retrieving Parameter in Second Component

In the second component, fetch the passed parameter from the URL ?

METHOD wddoinit.
  DATA: lv_employee_id TYPE string,
        lo_request TYPE REF TO if_http_request.

  * Get the parameter from URL
  lo_request = cl_http_server=>if_http_server~get_request( ).
  lo_request->get_form_field( EXPORTING name = 'employee_id' 
                             CHANGING value = lv_employee_id ).

  * Set the received value in context of second component
  wd_context->get_element( )->set_attribute( 
    name = 'RECEIVED_EMPLOYEE_ID' 
    value = lv_employee_id ).
ENDMETHOD.

Conclusion

This approach enables seamless data transfer between SAP Webdynpro components by using URL parameters and context attributes. The first component passes data through URL parameters, while the second component retrieves and processes these values during initialization.

Updated on: 2026-03-13T18:25:49+05:30

248 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements