Skip to Content
Technical Articles
Author's profile photo Amy King

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
           application_name = 'WEB_DYNPRO_APPLICATION_NAME'
           in_parameters      = lt_parameters
           out_absolute_ur l = lv_absolute_url

   lv_url = lv_absolute_url. " cast data type

           url                    = lv_url
           window_name = 'Example: Passing Parameters'
           new_window   = abap_true
           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
           name =  if_wd_application=>all_url_parameters
           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.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Tom Van Doorslaer
      Tom Van Doorslaer

      Hi Amy,

      Good example.

      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.

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      True! I've updated the post to reflect this option. Thanks for commenting Tom.

      Author's profile photo Priyaranjan Gupta
      Priyaranjan Gupta

      Nice one.

      Good to know this concept.

      Author's profile photo Modadugu Hemanth Kumar
      Modadugu Hemanth Kumar

      Useful topic.

      Author's profile photo Former Member
      Former Member

      Hi Amy,

      Can we pass multiple single values to select option field through URL

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      Hi Poddaturi,

      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.



      Author's profile photo Robin Vleeschhouwer
      Robin Vleeschhouwer

      Hi Amy,

      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.

      Best regards,

      Robin Vleeschhouwer

      Author's profile photo Amy King
      Amy King
      Blog Post Author

      Hi Robin,

      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.



      Author's profile photo Former Member
      Former Member

      Hi Amy,

                   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.


         '%20RF05L-BELNR=' gc_control

      ';RF05L-BUKRS =' gc_bukrs

      ';RF05L-GJAHR=' gc_fiscal

      ';BR_BELNR-low =' gc_control

      INTO URL.