36
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 - MS Word, 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.

Calling Windows Application Using Webdynpro ABAP

  • Upload
    -

  • View
    204

  • Download
    10

Embed Size (px)

DESCRIPTION

Calling Windows Application Using Webdynpro ABAP

Citation preview

Page 1: Calling Windows Application Using Webdynpro ABAP

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 - MS Word, 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.

Page 2: Calling Windows Application Using Webdynpro ABAP

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.

Page 3: Calling Windows Application Using Webdynpro ABAP

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.

Page 4: Calling Windows Application Using Webdynpro ABAP

In the properties, enter title.

2. Create a Group UI element - GROUP.

Right click on ROOTUIELEMENTCONTAINER, click on Insert Element and create a group UI element.

Page 5: Calling Windows Application Using Webdynpro ABAP

3. Create a Group UI element - GRP1 inside GROUP.

Right click on GROUP UI element and click on Insert Element and create a group UI element - GRP1.

In the properties, enter text for caption of GRP1 UI element.

Page 6: Calling Windows Application Using Webdynpro ABAP

4. Create a button UI element - BTN_WORD inside group GRP1.

Right click on GRP1 and click on Insert Element.

Enter ID, select UI element Button and click on OK.

Page 7: Calling Windows Application Using Webdynpro ABAP

In the Properties of BTN_WORD, enter text of Button.

Create an Action OPEN_WORD for button BTN_WORD.

Page 8: Calling Windows Application Using Webdynpro ABAP

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 UI element - GRP2.

In the properties, enter text for caption of GRP2 UI element.

Page 9: Calling Windows Application Using Webdynpro ABAP

6. Create a button UI element - BTN_NOTE inside group GRP2.

Right click on GRP2 and click on Insert Element.

Enter ID, select UI element Button and click on OK.

Page 10: Calling Windows Application Using Webdynpro ABAP

In the Properties of BTN_NOTE, enter text of Button.

Create an Action OPEN_NOTE for button BTN_NOTE.

Page 11: Calling Windows Application Using Webdynpro ABAP

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 UI element - GRP3.

In the properties, enter text for caption of GRP3 UI element.

Page 12: Calling Windows Application Using Webdynpro ABAP

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 and click on OK.

In the Properties of BTN_SHUT, enter text of Button.

Page 14: Calling Windows Application Using Webdynpro ABAP

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 UI element - GRP4.

In the properties, enter text for caption of GRP4 UI element.

Page 15: Calling Windows Application Using Webdynpro ABAP

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 and click on OK.

In the Properties of BTN_LOG, enter text of Button.

Create an Action SHOW_LOG for button BTN_LOG.

Page 16: Calling Windows Application Using Webdynpro ABAP

11. Create Message Area - MSG_AREA

Right click on ROOTUIELEMENTCONTAINER, and click on Insert Element.

Enter ID, select MessageArea UI and click on OK.

Page 17: Calling Windows Application Using Webdynpro ABAP

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.

Page 18: Calling Windows Application Using Webdynpro ABAP

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( ).

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.

Page 19: Calling Windows Application Using Webdynpro ABAP

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,

Page 20: Calling Windows Application Using Webdynpro ABAP

CALL_ACF_EXECUTE

lr_acf_exp TYPE REF TO cx_wd_acf_exception,

lv_msg_text TYPE string.

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.

* 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 in Windows 7 OS which may vary from

other Operation Systems. Please use the actual application 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.

Page 21: Calling Windows Application Using Webdynpro ABAP

ONACTIONOPEN_WORD

* Set MS WORD application absolute path

lv_application = 'C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE'.

* Call Execute method

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

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:

Page 22: Calling Windows Application Using Webdynpro ABAP

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

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 Web Dynpro ABAP using

AcfExecute.

Copy the below code to notepad and save to your local machine with .bat extension ( let say shutdown.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 Your Work!!"

To Cancel the shutdown, copy the below code to notepad and save to your local machine with .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 machine at path - "C:\Kiran\Shutdown".

You have to use the path at which you have saved the batch files in the following methods.

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.

Page 23: Calling Windows Application Using Webdynpro ABAP

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

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

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

Page 24: Calling Windows Application Using Webdynpro ABAP

We have done with our method implementations.

We have created Web Dynpro Components and implemented the methods in first part How to Run Executable files

from Web Dynpro ABAP - Part 1

Now we will see creating and executing the Web Dynpro Application.

Step 5: Creating Web Dynpro Application.

Right click on Web Dynpro Component and click on Create Web Dynpro Application

Enter description, click on OK and save the Web Dynpro Application.

Page 25: Calling Windows Application Using Webdynpro ABAP

Result

Right click on Web Dynpro Application and click on Test.

You can see the created application in browser.

Page 26: Calling Windows Application Using Webdynpro ABAP

Now Click on any button to see the result ( say Open MS word ).

Oops!! Nothing opened. Click on Show Log to see the message log.

Page 27: Calling Windows Application Using Webdynpro ABAP

You can see the message that "application was not cleared by whitelist" .

Due to security reasons, only authorized executables on client PC are triggered by AcfExecute. The authorized

servers and directories are listed in WhiteList.

So, we need to create a white list now. This is the main part of this Demo.

Creating Whitelist

Execute transaction WDR_ACF_WLIST and click on edit button (F6).

Page 28: Calling Windows Application Using Webdynpro ABAP

Click on New Entries to create entries.

Enter Whitelist name and description. Click on Save.

Page 29: Calling Windows Application Using Webdynpro ABAP

Now select the created entry and click on Applikation folder.

Click on New Entries to create entries.

Page 30: Calling Windows Application Using Webdynpro ABAP

Select the created whitelist from F4 help and maintain the Application Paths.

Note: The Application paths which I maintained in the above customizing is the application paths in Windows 7 OS which

may vary from other Operation Systems. Please use the actual application path according to your Operation System.

Click on Save and click on back button. Now in the initial screen of the transaction WDR_ACF_WLIST, you can see

the created whitelist.

Click on Activate button.

Page 31: Calling Windows Application Using Webdynpro ABAP

It will prompt to overwrite the xml file. click on transfer button.

You can see a success message that "Security list created".

Page 32: Calling Windows Application Using Webdynpro ABAP

We have successfully created security whitelist. Now we will test our application.

Run the Web Dynpro Application. Click on 'Open MS Word' button.

Aww.. MS Word document opened .

Click on 'Open MS Excel' button.

Page 35: Calling Windows Application Using Webdynpro ABAP

Click on "Shutdown System" button.

After seeing this message( I will not leave you dear), I cancelled System Shutdown.

Click on "Cancel Shutdown" button.

Page 36: Calling Windows Application Using Webdynpro ABAP

Conclusion Here I demonstrated a simple Application on how to run executable files from Web Dynpro ABAP using powerful

AcfExecute. You can use this according to your Requirements.

References

AcfExecute SAP Help content