Upload
kalyan-chakravarthi
View
181
Download
2
Embed Size (px)
DESCRIPTION
How to Run Executable Files From Web Dynpro ABAP - Part 1
Citation preview
Generated by Jive on 2013-02-20+01:001
How to Run Executable files from WebDynpro ABAP - Part 1
Introduction
This document explains how to run executable files form Web Dynpro ABAP application.
Here I am going to show a small demo on how to run executable files such as .exe files - MSWord, Notepad, Calculator and also .bat files using AcfExecute.
Prerequisites
SAP Netweaver 700 Ehp1.
Step by Step Process
Step 1: Create a Web Dynpro Component.
Go to the SE80 transaction and create a Web Dynpro Component.
Enter Description and click on ok.
Save the Component and Activate it.
Step 2: Data Binding
Go to the Context tab of Main View and create an attribute ERROR of type STRING.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:002
Step 3: Layout Design.
Now Go to Layout tab:
1. Create page header with title ‘ACF Execute Demo’.
Right click on ROOTUIELEMENTCONTAINER, and click on Insert Element.
Enter ID, select UI Element PageHeader and click on OK.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:003
In the properties, enter title.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:004
2. Create a Group UI element - GROUP.
Right click on ROOTUIELEMENTCONTAINER, click on Insert Element and create agroup UI element.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:005
3. Create a Group UI element - GRP1 inside GROUP.
Right click on GROUP UI element and click on Insert Element and create a group UIelement - GRP1.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:006
In the properties, enter text for caption of GRP1 UI element.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:007
4. Create a button UI element - BTN_WORD inside group GRP1.
Right click on GRP1 and click on Insert Element.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:008
Enter ID, select UI element Button and click on OK.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:009
In the Properties of BTN_WORD, enter text of Button.
Create an Action OPEN_WORD for button BTN_WORD.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0010
Similarly create 2 more buttons inside GRP1.
I). BTN_EXCEL with Text "Open MS Excel" and Action OPEN_EXCEL.
II). BTN_PAINT with Text "Open MS Paint" and Action OPEN_PAINT.
5. Create a Group UI element - GRP2 inside GROUP.
Right click on GROUP UI element and click on Insert Element and create a group UIelement - GRP2.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0011
In the properties, enter text for caption of GRP2 UI element.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0012
6. Create a button UI element - BTN_NOTE inside group GRP2.
Right click on GRP2 and click on Insert Element.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0013
Enter ID, select UI element Button and click on OK.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0014
In the Properties of BTN_NOTE, enter text of Button.
Create an Action OPEN_NOTE for button BTN_NOTE.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0015
Similarly create 1 more button inside GRP2.
I). BTN_CALC with Text "Open Calculator" and Action OPEN_CALC.
7. Create a Group UI element - GRP3 inside GROUP.
Right click on GROUP UI element and click on Insert Element and create a group UIelement - GRP3.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0016
In the properties, enter text for caption of GRP3 UI element.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0017
8. Create a button UI element - BTN_SHUT inside group GRP3.
Right click on GRP3, click on Insert Element -> Enter ID, select UI element Button andclick on OK.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0018
In the Properties of BTN_SHUT, enter text of Button.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0019
Create an Action SHUTDOWN for button BTN_SHUT.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0020
Similarly create 1 more button inside GRP3.
I). BTN_CANCEL with Text "Cancel Shutdown" and Action CANCEL_SHUTDOWN.
9. Create a Group UI element - GRP4 inside GROUP.
Right click on GROUP UI element and click on Insert Element and create a group UIelement - GRP4.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0021
In the properties, enter text for caption of GRP4 UI element.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0022
10. Create a button UI element - BTN_LOG inside group GRP4.
Right click on GRP4, click on Insert Element -> Enter ID, select UI element Button andclick on OK.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0023
In the Properties of BTN_LOG, enter text of Button.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0024
Create an Action SHOW_LOG for button BTN_LOG.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0025
11. Create Message Area - MSG_AREA
Right click on ROOTUIELEMENTCONTAINER, and click on Insert Element.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0026
Enter ID, select MessageArea UI and click on OK.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0027
Now our final Layout Looks like this:
Step 4: Attributes Declaration.
Now go to Attributes of MAIN view and create the attributes:
• ACF_METHOD_HANDLER of type ref to CL_WDR_ACFEXECUTE_HNDL and• M_CONTROL of type ref to CL_WD_ACF_EXECUTE.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0028
Step 5: Method Implementation.
Now go to Methods tab and write the below code in WDDOMODIFYVIEW method.
WDDOMODIFYVIEW
METHOD WDDOMODIFYVIEW .
DATA: root_element TYPE REF TO if_wd_view_element,
root_container TYPE REF TO cl_wd_transparent_container.
IF first_time = 'X'.
root_element = view->get_root_element( ).
root_container ?= root_element.
* init GAC control
wd_this->m_control = cl_wd_acf_execute=>new_acf_execute( ).
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0029
wd_this->m_control->set_enabled( abap_true ).
wd_this->acf_method_handler ?= wd_this->m_control->_method_handler.
* Create AcfExecute UI
cl_wd_matrix_data=>new_matrix_data( element = wd_this->m_control ).
root_container->add_child( wd_this->m_control ).
ENDIF.
ENDMETHOD.
Now create method a method CALL_ACF_EXECUTE.
Now Double click on CALL_ACF_EXECUTE method and create parameters: APPLICATION and
ARGUMENTLIST of type string.
Write the below code in CALL_ACF_EXECUTE method:
CALL_ACF_EXECUTE
METHOD CALL_ACF_EXECUTE .
DATA: lo_el_context TYPE REF TO if_wd_context_element,
lo_el_context_stru TYPE wdr_ext_attribute_pointer,
lr_acf_exp TYPE REF TO cx_wd_acf_exception,
lv_msg_text TYPE string.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0030
TRY.
lo_el_context = wd_context->get_lead_selection( ).
lo_el_context_stru-attribute_name = 'ERROR'.
lo_el_context_stru-element = lo_el_context.
wd_this->acf_method_handler->if_wd_acfexecute~execute( application = application
argumentlist = argumentlist
errorinformation =lo_el_context_stru ).
CATCH cx_wd_acf_exception INTO lr_acf_exp.
lv_msg_text = lr_acf_exp->if_message~get_text( ).
* 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.
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0031
* report message
CALL METHOD lo_message_manager->REPORT_SUCCESS
EXPORTING
MESSAGE_TEXT = lv_msg_text.
ENDTRY.
ENDMETHOD.
Note: The Application paths which I am specifying in the following methods is inWindows 7 OS which may vary from other Operation Systems. Please use the actualapplication path according to your Operation System.
Double click on ONACTIONOPEN_WORD and write the below code:
ONACTIONOPEN_WORD
METHOD ONACTIONOPEN_WORD.
DATA lv_application TYPE string.
* Set MS WORD application absolute path
lv_application = 'C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE'.
* Call Execute method
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0032
wd_this->call_acf_execute( application = lv_application ).
ENDMETHOD.
Double click on ONACTIONOPEN_EXCEL and write the below code:
ONACTIONOPEN_EXCEL
method ONACTIONOPEN_EXCEL .
DATA lv_application TYPE string.
* Set MS EXCEL application absolute path
lv_application = 'C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE'.
* Call Execute method
wd_this->call_acf_execute( application = lv_application ).
endmethod.
Double click on ONACTIONOPEN_PAINT and write the below code:
ONACTIONOPEN_PAINT
method ONACTIONOPEN_PAINT .
DATA lv_application TYPE string.
* Set MS PAINT application absolute path
lv_application = 'C:\Windows\System32\mspaint.exe'.
* Call Execute method
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0033
wd_this->call_acf_execute( application = lv_application ).
endmethod.
Double click on ONACTIONOPEN_NOTEPAD and write the below code:
ONACTIONOPEN_NOTEPAD
method ONACTIONOPEN_NOTEPAD .
DATA lv_application TYPE string.
* Set notepad absolute path
lv_application = 'C:\Windows\System32\notepad.exe'.
* Call Execute method
wd_this->call_acf_execute( application = lv_application ).
endmethod.
Now double click on ONACTIONOPEN_CALC and write the below code:
ONACTIONOPEN_CALC
method ONACTIONOPEN_CALC .
DATA lv_application TYPE string.
* Set Calculator application absolute path
lv_application = 'C:\Windows\System32\calc.exe'.
* Call Execute method
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0034
wd_this->call_acf_execute( application = lv_application ).
endmethod.
To Shut Down the system, I have created a batch file. I will run this batch file from WebDynpro ABAP using AcfExecute.
Copy the below code to notepad and save to your local machine with .bat extension ( let sayshutdown.bat ).
SHUTDOWN.BAT
shutdown -s -t 200 -c "Please dont leave me.. I have no one but You.. Bye Kiran.. Will Miss U...Please save YourWork!!"
To Cancel the shutdown, copy the below code to notepad and save to your local machinewith .bat extension ( let say abort_shutdown.bat ).
ABORT_SHUTDOWN.BAT
shutdown -a
Note: I have saved the shutdown and abort_shutdown batch files in my local machineat path - "C:\Kiran\Shutdown".
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0035
You have to use the path at which you have saved the batch files in the followingmethods.
Now double click on ONACTIONSHUTDOWN method and write the below code:
ONACTIONSHUTDOWN
METHOD ONACTIONSHUTDOWN.
DATA lv_application TYPE string.
* Set shutdown batch file absolute path
lv_application = 'C:\Kiran\Shutdown\shutdown.bat'.
* Call Execute method
wd_this->call_acf_execute( application = lv_application ).
ENDMETHOD.
Double click on ONACTIONCANCEL_SHUTDOWN method and write the below code:
ONACTIONCANCEL_SHUTDOWN
METHOD ONACTIONCANCEL_SHUTDOWN.
DATA lv_application TYPE string.
* Set abort shutdown batch file absolute path
lv_application = 'C:\Kiran\Shutdown\abort_shutdown.bat'.
* Call Execute method
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0036
wd_this->call_acf_execute( application = lv_application ).
ENDMETHOD.
Double click on ONACTIONSHOW_LOG method and write the below code:
ONACTIONSHOW_LOG
METHOD ONACTIONSHOW_LOG.
DATA: lo_el_context TYPE REF TO if_wd_context_element,
ls_context TYPE wd_this->Element_context,
lv_error TYPE wd_this->Element_context-error,
lo_api_controller TYPE REF TO if_wd_controller,
lo_message_manager TYPE REF TO if_wd_message_manager.
* get element via lead selection
lo_el_context = wd_context->get_element( ).
* get error log
lo_el_context->get_attribute(
EXPORTING
name = `ERROR`
IMPORTING
value = lv_error ).
How to Run Executable files from Web Dynpro ABAP - Part 1
Generated by Jive on 2013-02-20+01:0037
* 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 = lv_error.
ENDMETHOD.
We have done with our method implementations.
We will see Creating and Executing the Web Dynpro Application in the second part How toRun Executable files from Web Dynpro ABAP - Part 2