Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
Webdynpro ABAP

Closing a Browser through action



There may be a requirement where you may display certain data’s in the pop up and by performing some action in the pop up the action has to be completed and the web browser has to be closed automatically.

In the following post we are going to see how to close the web browser by the action on the window.

Take any component which was previously developed by you and we will proceed from there.

Step 1: In order to close the browser the application parameter close_window of the Webdynpro application has to be set to ‘X’. Go to the application created for your component and in parameters tab include the parameter close_window.

clip_image002

When the value of this parameter close_window is set to X the system will close the browser.

Step 2: Go to the layout tab of the view controller and insert a UI element.

clip_image004

Provide the text and create an action for the UI element.

clip_image006


Step 3: Go to the window controller and created an outbound plug of type exit plug.

clip_image008

Step 4: In the event handler for the method do the following.

1.      Get the reference of the view controller
2.      Get the reference of the window in which the view is contained.
3.      Set the parameter of the close_window as x and specify the outbound plug to be triggered.

Getting the reference variable of the view controller.

Using code wizard generate the code for getting the getting the reference of the view controller.

Call the wd_get_api method of the current controller to get the reference of the current controller.

clip_image010

Code will be generated as below.

clip_image012

Now the reference of the view V_MAIN will be in the variable lo_api_v_main.

In the interface type of the reference variable there is a method called GET_EMBEDDING_WINDOW_CTLR which will return the reference of the window in which the current view has been embedded.

clip_image013


Call this method using pattern to generate the codes.

clip_image015


Code will be generated as below.

clip_image017

Modify the code as below.

clip_image019


Now using the reference of the window controllers set the application parameter and pass the plug to be triggered as shown below.

Using the method fire_plug of the interface for window pass the application parameter value and the plug to be triggerd.

clip_image021


Check the parameters of the method for better understanding of below code. This method contains two importing parameters.

clip_image022

If you check the table type wdr_event_parameter_list the value of the parameters is passed as the data reference variable. Hence format the data to be passed to the importing parameters “PARAMETERS” and pass it to the method.

Populating an internal table to be passed to import parameter “PARAMETER”.

clip_image024


Pass the data to the method as below.

clip_image026

Code will be generated as below.

clip_image028

Modify the code as below.

clip_image030


Code in the method:

  DATA LO_API_V_MAIN TYPE REF TO IF_WD_VIEW_CONTROLLER.

  LO_API_V_MAIN = WD_THIS->WD_GET_API( ).

 
DATA : LO_WINDOW TYPE REF TO
IF_WD_WINDOW_CONTROLLER.

 
CALL METHOD
LO_API_V_MAIN->GET_EMBEDDING_WINDOW_CTLR
    RECEIVING
      RESULT = LO_WINDOW.


 
DATA : IT_PARAMETERS TYPE
wdr_event_parameter_list,
         WA_PARAMETERS
TYPE
wdr_event_parameter,
         LV_DATA      
TYPE REF TO DATA
.
 
FIELD-SYMBOLS : <FS_PARA> TYPE ANY
.

 
CREATE DATA LV_DATA TYPE C
.
 
ASSIGN LV_DATA->* TO
<FS_PARA>.
  <FS_PARA> =
'X'
.

  WA_PARAMETERS-NAME =
'CLOSE_WINDOW'
.
  WA_PARAMETERS-
VALUE
= LV_DATA.
 
INSERT WA_PARAMETERS INTO TABLE
IT_PARAMETERS.
 
CLEAR
WA_PARAMETERS.

CALL METHOD
LO_WINDOW->IF_WD_VIEW_CONTROLLER~FIRE_PLUG
 
EXPORTING

   
PARAMETERS = IT_PARAMETERS
    PLUG_NAME  =
'EXIT_PLUG'
    .


Save and activate the whole component test the application.

Output:

clip_image032

Click on the close link your browser will be closed.


About Arun

0 Comments:

Post a Comment

Powered by Blogger.