Code Snippet Series: Pass Parameters to Web Dynpro from SAPgui
This post is part of a series on code snippets. The complete list of posts in the series is available in the document Code Snippets: A Blog Series.
Two steps are needed to pass parameters into a Web Dynpro ABAP application from the SAPgui. First, the SAPgui must construct the URL of the Web Dynpro application and open the URL in a web browser. This step may be done in any ABAP routine.
DATA lv_absolute_url TYPE string. DATA lv_url TYPE char255. DATA ls_parameter TYPE ihttpnvp. DATA lt_parameters TYPE tihttpnvp. * Assemble the parameter name/value pairs as needed ls_parameter-name = 'param1_name'. ls_parameter-value = 'param1_value'. APPEND ls_parameter TO lt_parameters. ls_parameter-name = 'param2_name'. ls_parameter-value = 'param2_value'. APPEND ls_parameter TO lt_parameters. * Construct the URL with parameters cl_wd_utilities=>construct_wd_url( EXPORTING application_name = 'WEB_DYNPRO_APPLICATION_NAME' in_parameters = lt_parameters IMPORTING out_absolute_ur l = lv_absolute_url ). lv_url = lv_absolute_url. " cast data type CALL FUNCTION 'CALL_BROWSER' EXPORTING url = lv_url window_name = 'Example: Passing Parameters' new_window = abap_true EXCEPTIONS OTHERS = 0.
Second, the Web Dynpro application must read the parameters from its URL query string. This is accomplished in one of two ways. Dynamic parameters must be handled by programmatically reading the parameter name/value pairs from the URL query string in the HANDLEDEFAULT event handler method of the Web Dynpro application’s interface view, i.e., its window.
DATA lt_parameters TYPE tihttpnvp. * Read URL parameters from the query string wdevent->get_data( EXPORTING name = if_wd_application=>all_url_parameters IMPORTING value = lt_parameters ).
Internal table LT_PARAMETERS may now be read and the parameter name/value pairs processed as needed by the application. Static parameters may also be handled in this way or may be defined at design time as importing parameters in the HANDLEDEFAULT method signature.
Alternatively, you can also define the URL parameters in the signature of the default plug-handler of your webdynpro window.
You can define parameters there as if they were regular method import parameters (you 'll want to make them optional in most cases)
As long as the name of the URL parameter is the same as the handler parameter, the WDA framework will automatically assign the value of the URL parameter to the method parameter.
Of course, this is only a nice shortcut if your parameters are static.
For dynamic parameters, reading the wdevent is much more versatile.
True! I've updated the post to reflect this option. Thanks for commenting Tom.
Good to know this concept.
Can we pass multiple single values to select option field through URL
You can pass values through the URL query string and use them however they are needed by your application. For setting default values in a select-option, please see Thomas Jung's eLearning video, Web Dynpro ABAP: Defaulting Select-Option Values.
Thanks for the information.
Ok I am a little bit late with the comment, but better late than never 🙂
For the first part it is easier to use function module: WDY_EXECUTE_IN_BROWSER
You can even execute Web Dynpro inside the SAP Gui with FM: WDY_EXECUTE_IN_PLACE
Or create your own transaction and forward it to transaction: WDYID
For the second part you can also use class method: CL_WD_RUNTIME_SERVICES=>GET_URL_PARAMETER for reading the parameters.
Thanks for suggesting an alternative approach. Function wdy_execute_in_browser encapsulates calls to method cl_wd_utilities=>construct_wd_url and to function call_browser and is another valid solution for launching a WD application from the SAPgui.
The solution provided above does have the benefit of giving access to the parameters of function call_browser such as window_name and new_window. 😉
While I have yet to find a way to completely avoid calling unreleased SAP functions since often it is the only reasonable solution to a requirement, they come with the usual caveat. Function wdy_execute_in_browser is unreleased and was last changed by SAP in 2012 so its use comes with a small risk of SAP changing its interface or implementation in some future release. That doesn't disqualify it as a valid solution, but does impose the rule of caveat emptor.
Thanks for showing there is always more than one solution to any problem.
IS It possible to pass Select -Options as URL parameters to a standard T-CODE View. My requirement is to call T-COde FB03 and pass the Parmaters. I have written the code below, But i was unable to populate the Select-options fields.
';RF05L-BUKRS =' gc_bukrs
';BR_BELNR-low =' gc_control