cancel
Showing results for 
Search instead for 
Did you mean: 

Closing a window on click of a button

Former Member
0 Kudos

Hi,

I have to close a window on click of a button.

Plz suggest...

Regards

Reeha

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

data lr_window type ref to if_wd_window

Store the instance (lr_window) of window as one of the attribute of componentcontroller or viewcontroller and on the click of button call the close method.

lr_window->close( ).

Thanks,

Rahul

uday_gubbala2
Active Contributor
0 Kudos

Hi Reeha,

Go through this [excellent blog by Anzy|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6707] [original link is broken] [original link is broken] [original link is broken]; where he explains how you can close popup windows. (The blog is titled as external windows but it does actually refer to popup windows.) Below is another workaround for the same. You must be callinng a popup by using the code wizard. Within this code at 1 place you would have something like lo_window_manager->create_window( ) which would be returning the reference to this popup window. You can create an attribute of type ref to IF_WD_WINDOW & ave this reference into it. So map this context node even to your popups view. When you want to close this popup just read the context attribute value in your view and call the close( ) method on this reference variable. Just go through the code snippets below:

Regards,

Uday

To call the popup and save the window reference into a component controller level attribute:

METHOD onactiondisplay_popup . 
DATA: lv_node TYPE REF TO if_wd_context_node, l
      lv_kunnr TYPE ig_componentcontroller=>element_kna1-kunnr,
      lt_vbak TYPE ig_componentcontroller=>elements_vbak. 

* get message manager 

DATA lo_api_controller TYPE REF TO if_wd_controller. 
DATA lo_message_manager TYPE REF TO if_wd_message_manager. 

lo_api_controller ?= wd_this->wd_get_api( ). 

CALL METHOD lo_api_controller->get_message_manager RECEIVING message_manager = lo_message_manager.
lv_node = wd_context->get_child_node( name = 'KNA1' ). 

CALL METHOD lv_node->get_attribute EXPORTING name = 'KUNNR' 
				   IMPORTING value = lv_kunnr. 

SELECT * FROM vbak INTO TABLE lt_vbak WHERE kunnr = lv_kunnr. 

" If no sales orders exist for the customer then display an error message quoting the same 
IF sy-subrc NE 0. 
* report message
  CALL METHOD lo_message_manager->report_error_message
    EXPORTING message_text = 'No sales orders exist for this customer!'.

" If sales orders exist for the customer then display the orders within a popup
ELSE. 
  lv_node = wd_context->get_child_node( name = 'VBAK' ). 
  lv_node->bind_table( new_items = lt_vbak ). 
  
  DATA lo_window_manager TYPE REF TO if_wd_window_manager.
  DATA lo_api_component TYPE REF TO if_wd_component.
  DATA lo_window TYPE REF TO if_wd_window. 
  
  lo_api_component = wd_comp_controller->wd_get_api( ).
  lo_window_manager = lo_api_component->get_window_manager( ).
  lo_window = lo_window_manager->create_window( window_name = 'POPUP_WINDOW' 
						title = 'Working with modal windows' 						CLOSE_IN_ANY_CASE = ABAP_TRUE ). 

  lv_node = wd_context->get_child_node( name = 'WINDOW_REFERENCE' ).
  CALL METHOD lv_node->set_attribute EXPORTING value = lo_window name = 'REFERENCE'.
  lo_window->open( ).
ENDIF.
ENDMETHOD.

To close the popup window:

lv_node = wd_context->get_child_node( name = 'WINDOW_REFERENCE' ).
CALL METHOD lv_node->get_attribute EXPORTING name = 'REFERENCE' 
				   IMPORTING value = lv_pop_window_ref.
lv_pop_window_ref->close( ).

Former Member
0 Kudos

Hi,

Get the instance of window and close it.

lr_api_comp_controller = wd_comp_controller->wd_get_api( ).

lr_window_manager = lr_api_comp_controller->get_window_manager( ).

lr_popup = lr_window_manager->

GET window and

Do this thing on button event

lr_popup->close().

best regards,

Rohit

Former Member
0 Kudos

You can write the following code in the action of your button to close the popup window,

data:
            l_api         type ref to if_wd_view_controller,
            l_window_ctlr type ref to if_wd_window_controller,
            l_popup       type ref to if_wd_window.

            l_api         = wd_this->wd_get_api( ).
            l_window_ctlr = l_api->get_embedding_window_ctlr( ).
            if l_window_ctlr is bound.
            l_popup       = l_window_ctlr->get_window( ).
            l_popup->close( 'l_popup' ). 
            endif.

OR,

Create a global attribute lo_window TYPE REF TO if_wd_window.

Now when calling your popup,

lo_window->open( ). save this instance in the global attribute

wd_comp_controller->lo_window = lo_wondow.

Now when you want to the close the window, just write this one line in your action method

wd_comp_controller->lo_window->close( ).

I hope it helps,

Radhika.

Edited by: Radhika Vadher on May 26, 2009 12:05 PM