You are on page 1of 15

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.

com
2011 SAP AG 1
Step by Step Guide for using
SUBSCRIBE_to_button_Event
Method of a pop-up Window in
WebDynpro ABAP
Applies to:
This document applies to SAP ECC 6.0, SAP NetWeaver 2004s. For more information, visit the Web Dynpro
ABAP homepage.

Summary
This article provides a step by step guide for using the subscribe_to_button_event method of a pop-up
window in WebDynpro ABAP with a simple example.
Author: Aisurya Kumar Puhan
Company: Incture Technologies Pvt Ltd.
Created on: 20 July, 2011

Author Bio
Aisurya Kumar Puhan is working as SAP NetWeaver Consultant in Incture Technologies Pvt Ltd. He
has around 3 years of experience in SAP ABAP, including 1 year in WebDynpro ABAP
development.


Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 2
Table of Contents
Introduction ......................................................................................................................................................... 3
Scenario .............................................................................................................................................................. 3
Step by Step Guide ............................................................................................................................................. 3
Step 1: Create webdynpro component ........................................................................................................... 3
Step 2: Add the standard ALV component..................................................................................................... 3
Step 3: Use the standard component to the component controller ................................................................ 4
Step 4: Node Creation in Component controller ............................................................................................. 4
Step 5: View Creation ..................................................................................................................................... 5
Step 6: Context mapping................................................................................................................................. 5
Step 7: Interface controller mapping ............................................................................................................... 5
Step 8: Business Logic.................................................................................................................................... 6
Step 9: Embed View ........................................................................................................................................ 6
Step 10: Embed the standard table ................................................................................................................ 6
Step 11: Create a webdynpro application ....................................................................................................... 7
Step 12: Window creation ............................................................................................................................... 7
Step 13: View Creation ................................................................................................................................... 8
Step 14: Embed View ...................................................................................................................................... 8
Step 15: Mapping ............................................................................................................................................ 8
Step 16: UI designing ...................................................................................................................................... 8
Step 17: Attribute creation .............................................................................................................................. 9
Step 18: Coding inside the button. .................................................................................................................. 9
Step 19: Creation of action. .......................................................................................................................... 10
Step 20: Coding in WDDOMODIFYVIEW ..................................................................................................... 10
Step 21: Method for message handling. ....................................................................................................... 11
Step 22: Coding inside the Action of button of pop-up . ............................................................................... 12
Step 23 : Test application.............................................................................................................................. 12
Related Content ................................................................................................................................................ 14
Disclaimer and Liability Notice .......................................................................................................................... 15

Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 3
Introduction
This article provides a step by step guide for creating an ALV report using standard WD component and
subscribing to the action for a standard button of a Pop-up Window .
When we create an external pop-up window, we also assign somes standard buttons like YesNo ,OkCancel
etc . In most cases, end user requirement is to perform some action when the standard button is clicked in
the external window .
Scenario
Deleting a record from an ALV using the pop-up window standard button.
Step by Step Guide
Step 1: Create webdynpro component
First create a webdynpro component ZPOP_UP_BUTTON.
Step 2: Add the standard ALV component
Add the standard ALV component i.e SALV_WD_TABLE and the name it like TEST_ALV.


Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 4
Step 3: Use the standard component to the component controller
Step 4: Node Creation in Component controller
Now create a node in the Component controller, make sure about cardinality.
Ex: ZDETAILS is a node having cardinality 1:n and having attributes NAME , AGE , PLACE from a DB table
i.e ZTEST_DEMO .




Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 5
Step 5: View Creation
Then create a view ALV_VIEW . Add a VIEWUIELEMENTCONTAINER and BUTTON to it.
Step 6: Context mapping
Now mapping is done to the context of View controller from Component controller .
Step 7: Interface controller mapping
Now mapping is done to the node (DATA) of the Interface controller from Component controller .
The data present in the ZDETAILS node will be shown in the ALV table .
Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 6

Step 8: Business Logic
Write the business logic inside the WDDOINT method of view ( ALV_VIEW).
method WDDOINIT .
DATA lo_nd_zdetails TYPE REF TO if_wd_context_node.
DATA lo_el_zdetails TYPE REF TO if_wd_context_element.
DATA ls_zdetails TYPE wd_this->element_zdetails. " structure
DATA lt_zdetails TYPE wd_this->elements_zdetails. " internal table
* navigate from <CONTEXT> to <ZDETAILS> via lead selection
lo_nd_zdetails = wd_context->get_child_node( name = wd_this->wdctx_zdetails ).
* get element via lead selection
lo_el_zdetails = lo_nd_zdetails->get_element( ).

* Business logic for fetching the records from DB
select name
age
place from ztest_demo into table lt_zdetails .

* Binding the internal table to the node..

CALL METHOD LO_ND_ZDETAILS->BIND_TABLE
EXPORTING
NEW_ITEMS = lt_zdetails
.
Endmethod.
Step 9: Embed View
Now embed the view (ALV_VIEW) in the window by drag and drop or Rt click->embed.
Step 10: Embed the standard table
Embed the standard ALV table in the VIEWUIELEMENT CONTAINER(VIEW_CONT) which is present
inside the view (ALV_VIEW).
















Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 7

Step 11: Create a webdynpro application
Create a WD application and test it.
Below is the output according to data in DB.



Note : Our main work starts from here. Requirement is to delete the selected record with pop up , when DELETE button
is clicked.
Step 12: Window creation
Create a another window ZDELETE_POP_UP.


Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 8
Step 13: View Creation
Now create a another view i.e POP_UP_VIEW for showing the data which will be deleted.
Step 14: Embed View
Embed the view POP_UP_VIEW to window ZDELETE_POP_UP.

Step 15: Mapping
Refer Step 4 for mapping in the viewcontroller of POP_UP_VIEW from the component controller.
Step 16: UI designing
In the POP_UP_VIEW layout, insert an TRANSPARENT UI element , and create container form in it
from the context . Insert a TEXTVIEW UI element add the text Are you Sure to delete following record!!!
Design according to your need.
Functionality : Here only the selected record from the ALV will be shown in the view POP_UP_VIEW which
is embeded to the window ZDELETE_POP_UP.
Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 9
Step 17: Attribute creation
Create an attribute in the Attributes section of the component controller.

Step 18: Coding inside the button.
Now write the coding inside the DELETE button of the view ( ALV_VIEW ).
method ONACTIONDELETE .
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 = 'ZDELETE_POP_UP'
* title =
* close_in_any_case = abap_true
message_display_mode = if_wd_window=>co_msg_display_mode_selected
* close_button = abap_true
button_kind = if_wd_window=>CO_BUTTONS_YESNO
message_type = if_wd_window=>co_msg_type_none
* default_button = if_wd_window=>co_button_ok
).
wd_comp_controller->go_window = lo_window.
lo_window->open( ).
endmethod.
Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 10
Functionality : When delete button is clicked the window ZDELETE_POP_UP is opened .
Now the Output is like this :

Note : Here we have to subscribe the button event for YES and also create an action for this.
Step 19: Creation of action.
Now create an action i.e ACT_YES in POP_UP_VIEW .
Step 20: Coding in WDDOMODIFYVIEW
Write the coding in WDDOMODIFYVIEW for subscribing the button event . It is subscribed only once when
the view is loaded first time.
method WDDOMODIFYVIEW .
if first_time = abap_true.
CALL METHOD wd_comp_controller->go_window->SUBSCRIBE_TO_BUTTON_EVENT
EXPORTING
BUTTON = if_wd_window=>CO_BUTTON_YES
* BUTTON_TEXT =
* TOOLTIP =
ACTION_NAME = 'ACT_YES'
ACTION_VIEW = view
* IS_DEFAULT_BUTTON = ABAP_FALSE
.
endif.
endmethod.

Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 11
Step 21: Method for message handling.
Now create a method for message handling and write the code .

method GENERATE_MSG .

* 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
.

* report message
CALL METHOD lo_message_manager->REPORT_T100_MESSAGE
EXPORTING
MSGID = 'ZTEST_POP_UP'
MSGNO = '000'
MSGTY = 'S' .


endmethod.

Hint : ZTEST_POP_UP is the message class.
Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 12
Step 22: Coding inside the Action of button of pop-up .
Coding inside the Action of button i.e ACT_YES.

method ONACTIONACT_YES .
DATA lo_nd_zdetails TYPE REF TO if_wd_context_node.
DATA lo_el_zdetails TYPE REF TO if_wd_context_element.
DATA ls_zdetails TYPE wd_this->element_zdetails.
DATA lt_zdetails TYPE wd_this->elements_zdetails.
* navigate from <CONTEXT> to <ZDETAILS> via lead selection
lo_nd_zdetails = wd_context->get_child_node( name = wd_this->wdctx_zdetails ).

* get element via lead selection
lo_el_zdetails = lo_nd_zdetails->get_element( ).

* get all declared attributes
lo_el_zdetails->get_static_attributes(
IMPORTING
static_attributes = ls_zdetails ).

* get all attributes from the node
CALL METHOD LO_ND_ZDETAILS->GET_STATIC_ATTRIBUTES_TABLE
IMPORTING
TABLE = lt_zdetails
.
*bussiness logic for deletion
delete lt_zdetails where name = ls_zdetails-name.


CALL METHOD LO_ND_ZDETAILS->BIND_TABLE
EXPORTING
NEW_ITEMS = lt_zdetails
* SET_INITIAL_ELEMENTS = ABAP_TRUE
* INDEX =
.

wd_this->GENERATE_MSG( ).

endmethod.
Step 23 : Test application
>>>>>>>>>> OUTPUT <<<<<<<<<

Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 13
Select any record and click Delete.

Now when you click Yes the selected record is deleted with success message.




Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 14
Related Content
Window Manager
Closing the main window from Pop-up window
Editable ALV Fields
For more information Visit Web Dynpro ABAP homepage.

Step by Step Guide for using subscribe_to_button_Event Method of a pop-up Window in WebDynpro ABAP
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 15
Disclaimer and Liability Notice
This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not
supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,
and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or
code sample, including any liability resulting from incompatibility between the content within this document and the materials and
services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this
document.