Skip to Content

Introduction

This document helps how to close web dynpro application browser window automatically after specified event/time.

Here I will explain a simple Scenario: After displaying success message the browser has to close automatically in 5 seconds.

Step by Step Process

Step 1: Create a Web Dynpro Component.

   Go to the SE80 transaction and create a Web Dynpro Component.

/wp-content/uploads/2013/06/1_233351.jpg

Enter Description and click on ok.

/wp-content/uploads/2013/06/2_233352.jpg

Save and Activate the component.

/wp-content/uploads/2013/06/3_233353.jpg

Step 2: Create EXIT plug

Go to the Outbound Plugs tab of the window and create an EXIT plug with the parameter CLOSE_WINDOW of type WDY_BOOLEAN.

/wp-content/uploads/2013/06/4_233354.jpg

Step 3: Data Binding

Go to the Context tab of Main View and create and create attributes : EMPID of type STRING and ENABLE of type WDY_BOOLEAN.

Right click on the Context and click on create attribute.

/wp-content/uploads/2013/06/5_233356.jpg

Create attribute EMPID of type STRING.

/wp-content/uploads/2013/06/6_233447.jpg

Similarly create an attribute ENABLE of type WDY_BOOLEAN.

/wp-content/uploads/2013/06/7_233551.jpg

Step 4: Layout Design.

   Now Go to Layout tab:

  1. Create label UI with text ‘Enter employee ID’.

     Right click on ROOTUIELEMENTCONTAINER and click on Insert Element

/wp-content/uploads/2013/06/8_233567.jpg

   Enter ID and select UI ‘Label’.

/wp-content/uploads/2013/06/9_233568.jpg

Similarly create Input filed EMPID and bind the value to EMPID attribute.

/wp-content/uploads/2013/06/10_233569.jpg

Now create a button UI element.

/wp-content/uploads/2013/06/11_233579.jpg

Enter button Text and click on create button to create an Action for button.

/wp-content/uploads/2013/06/12_233580.jpg

Enter Action name, description and click on OK.

/wp-content/uploads/2013/06/13_233581.jpg

Now create a message area UI element to display messages.

/wp-content/uploads/2013/06/14_233585.jpg

Create a Timed Trigger UI element.

/wp-content/uploads/2013/06/15_233586.jpg

Bind the enable property of the timed trigger UI to the attribute ENABLE.

/wp-content/uploads/2013/06/17_233587.jpg

Set the delay time of timed trigger UI element.

/wp-content/uploads/2013/06/23_233645.jpg

Create an Action for timed trigger UI.

/wp-content/uploads/2013/06/20_233598.jpg

Step 5: Create Component Usage

Now go to Properties tab and click on create button to create controller usage.

/wp-content/uploads/2013/06/18_233599.jpg

Select the controller by double clicking on it. We have to add the controller to make EXIT plug method of window in View Controller.

/wp-content/uploads/2013/06/19_233627.jpg

Now go to Methods tab of MAIN view and write the below code ONACTIONREGISTER method.

ONACTIONREGISTER
METHOD onactionregister .

   DATA lo_el_context             TYPE REF TO if_wd_context_element.
   DATA ls_context                 TYPE wd_this->element_context.
   DATA lv_empid                    TYPE wd_this->element_contextempid.
   DATA lo_api_controller         TYPE REF TO if_wd_controller.
   DATA lo_message_manager TYPE REF TO if_wd_message_manager.

*  get element via lead selection
   lo_el_context = wd_context->get_element( ).

*  get single attribute
   lo_el_context->get_attribute(
     EXPORTING
       name `EMPID`
     IMPORTING
       value = lv_empid ).

* Register the employee for event
*  CALL FUNCTION ‘ZEMP_REGISTER’
*    EXPORTING
*      emp_id = lv_empid.

   IF sysubrc = 0.
*  get message manager
      lo_api_controller ?= wd_this->wd_get_api( ).

      CALL METHOD lo_api_controller->get_message_manager
        RECEIVING
          message_manager = lo_message_manager.

*  report message
      CALL METHOD lo_message_manager->report_success
        EXPORTING
          message_text = ‘Employee Registered Successfully!’.

*   Enable Self destruction
       lo_el_context->set_attribute(
         name `ENABLE`
         value abap_true ).

   ENDIF.

ENDMETHOD.

And Enter the below code in ONACTIONCLOSE_BROWSER method

ONACTIONCLOSE_BROWSER
METHOD onactionclose_browser .

   DATA lo_zwd_auto_close_demo TYPE REF TO ig_zwd_auto_close_demo .

    lo_zwd_auto_close_demo =   wd_this->get_zwd_auto_close_demo_ctr( ).

*  Exit Application and Close Browser
     lo_zwd_auto_close_demo->fire_exit_plg(
      close_window = abap_true
      ).

ENDMETHOD.

Step 6: Create Application.

Save and Activate the Web Dynpro Component.  Create the Web Dynpro Application and Save it.

/wp-content/uploads/2013/06/21_233629.jpg

Enter description and save it.

/wp-content/uploads/2013/06/22_233639.jpg

Test Application

Now Right click on Web Dynpro Application and click on Test.

/wp-content/uploads/2013/06/24_233641.jpg

The application will open in the browser. Enter the employee ID and click on Register button.

/wp-content/uploads/2013/06/25_233646.jpg

Now we will get success message upon successful registration of the employee.

/wp-content/uploads/2013/06/26_233647.jpg

After displaying the message the browser will close automatically after 5 seconds (delay time of timed trigger).

In chrome and IE7 the browser window will close automatically. In higher versions of IE the browser will prompt to confirm closing of the browser.

/wp-content/uploads/2013/06/27_233658.jpg

Conclusion

Here I demonstrated a simple Web Dynpro Application. We can use this according to our Requirements.

To report this post you need to login first.

15 Comments

You must be Logged on to comment or reply to a post.

  1. Prathamesh Gandhi

    Hi Kiran,

     

    It is really helpful document, but when it POPUP for asking confirmation about closing window, gives two options Yes & No.

     

    on Yes it working perfectly fine, but on No your browse page turned into white.

    Can we somehow handle this ? like by only giving option of Yes or on close action instead of this POPUP can we directly close ?

     

    Thanks In Advance,

    P$G.

    (0) 
    1. Kiran Kumar Valluru Post author

      Hi,

       

      As mentioned already in the document

       

      In chrome and IE7 the browser window will close automatically. In higher versions of IE the browser will prompt to confirm closing of the browser.

       

      If you run your WDA application in Chrome or IE7 the browser window will close automatically. In higher versions of IE say IE 8 or IE9, you will get a popup to confirm the closing of browser.

       

      You cannot handle it in WDA as it is purely browser dependent. May be you have to change some settings in your browser. I have checked in IE9 and there is no provision to disable the prompt to close the browser.

       

       

      Regards,

      Kiran

      (0) 
  2. NAVEEN MANDA

    after displaying popup message as  YES NO  … can we handle yes action through webdynrpo abap ?

     

    ..my requriement in popup  is yes action is clicked by default.  how can i do that ?

     

    I need to close  the browser without user interaction. without user interaction yes action is triggered ? ,.. can we do it through webdynpro coding ?

    (0) 
  3. Jim Hawthorne

    Hi there

    While not wishing to decry your efforts – this seems a lot of unnecessary work  just to get a message “Browser is trying to close Window” (or similar).

     

    With the later versions of IE just set to tabbed / caret  browsing (in Windows) – any new application will throw up a new browser page. Just close the tab(s) you don’t need.

     

    If your solution needs you to click an OK button to close the window – there’s NO advantage over just closing the tab in Windows explorer. Since each web application (or web dynpro or whatever) opens a new browser window there’s no advantage in your method.

     

    So have I missed something here

     

    Cheers

    (0) 
    1. Kiran Kumar Valluru Post author

      Hi Jim,

       

      Thanks for the feedback. The popup is browser dependent. Please read the previous comments aswell. It has nothing to do from WDA side.

       

      If you run this application in other browsers/ on lower versions of IE it closes the browser.

       

      Regards,

      Kiran

      (0) 
      1. NAVEEN MANDA

        Hi Kiran,

                         as you said ,

        In IE9 it not closing directly . It giving same  popup to close option in IE9.

        (0) 
  4. Sundar Krishna

    It doesn’t like the WDY_BOOLEAN. I get an error that EXIT plugs do not have the right type for the parameter. If I try to correct it to STRING, it expects a URL string.

     

    500 SAP Internal Server Error

    ERROR: Parameters of exit plugs and suspend plugs must be of type STRING or TIHTTPNV (termination: RABAX_STATE)

    (0) 

Comments are closed.