Skip to Content

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.

/wp-content/uploads/2012/12/1_168629.png

   Enter Description and click on ok.

/wp-content/uploads/2012/12/2_168630.jpg

Save the Component and Activate it.

/wp-content/uploads/2012/12/3_168631.jpg

Step 2: Data Binding

Go to the Context tab of Main View and create an attribute ERROR of type STRING.

/wp-content/uploads/2012/12/4_168632.jpg

/wp-content/uploads/2012/12/5_168633.jpg

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.

     /wp-content/uploads/2012/12/7_168634.jpg

     Enter ID, select UI Element PageHeader and click on OK.

     /wp-content/uploads/2012/12/8_168635.jpg

     In the properties, enter title.

      /wp-content/uploads/2012/12/9_168636.jpg

2. Create a Group UI element – GROUP.

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

    /wp-content/uploads/2012/12/10_168637.jpg

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.

     /wp-content/uploads/2012/12/11_168638.jpg

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

   /wp-content/uploads/2012/12/12_168639.jpg

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

     Right click on GRP1 and click on Insert Element.

     /wp-content/uploads/2012/12/13_168640.jpg

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

    /wp-content/uploads/2012/12/14_168641.jpg

   In the Properties of BTN_WORD, enter text of Button.

    /wp-content/uploads/2012/12/15_168642.jpg

Create an Action OPEN_WORD for button BTN_WORD.

/wp-content/uploads/2012/12/16_168643.jpg

  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.

     /wp-content/uploads/2012/12/17_168647.jpg

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

  /wp-content/uploads/2012/12/18_168648.jpg

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

    Right click on GRP2 and click on Insert Element.

    /wp-content/uploads/2012/12/19_168649.jpg

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

    /wp-content/uploads/2012/12/20_168653.jpg

   In the Properties of BTN_NOTE, enter text of Button.

   /wp-content/uploads/2012/12/21_168654.jpg

   Create an Action OPEN_NOTE for button BTN_NOTE.

    /wp-content/uploads/2012/12/22_168655.jpg

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.

      /wp-content/uploads/2012/12/23_168656.jpg

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

     /wp-content/uploads/2012/12/24_168657.jpg

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.

    /wp-content/uploads/2012/12/25_168658.jpg

     In the Properties of BTN_SHUT, enter text of Button.

       /wp-content/uploads/2012/12/26_168660.jpg

  Create an Action SHUTDOWN for button BTN_SHUT.

     /wp-content/uploads/2012/12/27_168662.jpg

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.

     /wp-content/uploads/2012/12/28_168664.png

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

   /wp-content/uploads/2012/12/29_168665.jpg

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.

   /wp-content/uploads/2012/12/30_168667.jpg

  In the Properties of BTN_LOG, enter text of Button.

     /wp-content/uploads/2012/12/31_168669.jpg

Create an Action SHOW_LOG for button BTN_LOG.

   /wp-content/uploads/2012/12/32_168671.jpg

11. Create Message Area – MSG_AREA

      Right click on ROOTUIELEMENTCONTAINER, and click on Insert Element.

      /wp-content/uploads/2012/12/33_168674.jpg

      Enter ID, select MessageArea UI and click on OK.

       /wp-content/uploads/2012/12/34_168676.jpg

Now our final Layout Looks like this:

   /wp-content/uploads/2012/12/35_168677.jpg

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.

/wp-content/uploads/2012/12/36_168679.jpg


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.

   /wp-content/uploads/2012/12/37_168684.png

Now Double click on CALL_ACF_EXECUTE method and create parameters: APPLICATION and ARGUMENTLIST of type string.

/wp-content/uploads/2012/12/38_168686.png

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.

   TRY.

       lo_el_context = wd_context->get_lead_selection( ).

       lo_el_context_struattribute_name = ‘ERROR’.

       lo_el_context_struelement = 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.

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

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.

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_contexterror,

              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.

We have done with our method implementations.

We will see Creating and Executing the Web Dynpro Application in the second part  How to Run Executable files from Web Dynpro ABAP – Part 2

To report this post you need to login first.

34 Comments

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

  1. Former Member

    Hi Kiran,

         Great work. I juest wanted to know can we do something with which we need not to specify the path of executable files. See because people will be running it from Linux as well, or people might have some other office solution. As its web-dynpro it can be accessed anywhere.

    Or is it possible to identify what OS is installed. So that we can use case statements.

    (0) 
    1. Kiran Kumar Valluru Post author

      Hi,

      You need to specify the application path to tell the system to run that application.

      Is it possible to identify what OS is installed. So that we can use case statements.

      As far I knew there is no provision to get the OS version from Web Dynpro ABAP. but you can get it from ABAP program using class  CL_GUI_FRONTEND_SERVICES  of GET_PLATFORM method.  SAP Help here.

      As you cannot use GUI classes in Web Dynpro ABAP, I would suggest you a work around.( Call Web Dynpro application from ABAP report)

      Create a ABAP Program as like below.,

      Report TEST.

      1. call GET_PLATFORM method of CL_GUI_FRONTEND_SERVICES class

      2. store the result (OS version) in temporary data base table.

      3. Call Web Dynpro Application

      Now in Web Dynpro Application, read the OS version from temporary DB and use case statements to specify the application paths ๐Ÿ™‚

      Hope this helps..

      Regards,

      Kiran



      (0) 
  2. Former Member

    Hey i am new to sap and i am getting error at Step 4

    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.

    ERROR says type CL_WDR_ACFEXECUTE_HNDL does not exist

    Can you please help on this

    (0) 
  3. Martin Falk

    Hello Kiran,

    when I run the program I always get an error: LayoutData-Typ “MATRIX_DATA” not allowed in child _08

    Do you have a tip?

    Regards,

    Martin

    (0) 
    1. Former Member

      Hi Martin ,

            Check the Layout.If the Parent UI layout is flow layout and the child layout is Matrix in these cases we will get that error.

      Regards,

      Aditya.

      (0) 
  4. Former Member

    Hi Kiran ,

           Very nice document , I tried it but i am not able to get the output .

          After executing the component i was redirecting to the Java website asking to  download latest version ๐Ÿ˜›

            If commented the line

                              root_container->add_child( wd_this->m_control ). 

               in WDDOMODIFYVIEW then it was not redirecting still after selecting the buttons      nothing happening.

      

    (0) 
    1. Kiran Kumar Valluru Post author

      Hi,

         root_container->add_child( wd_this->m_control ).

      This statement only creates the AcfExecute UI element at run time. If you comment this nothing will work out.

      Seems you are on a lower version of Netweaver. You need to have Netweaver 7.0 Ehp1 to use AcfExecute.  Please upgrade to the relevant service pack.

      Regards,

      Kiran

      (0) 
      1. Former Member

        Hi Kiran,

                 No i was using Netweaver 7.0 Ehp1 only, I checked the prerequisites before trying this.

                  As i said , the output is coming but in a flash of time it was redirecting to java website.

        Regards,

        Aditya.

        (0) 
        1. Kiran Kumar Valluru Post author

          Hi,

          Which latest version it’s asking to download after redirecting to Java page? Is it asking to update JRE or any other updates? If so, update it.

          Try to execute it in other system as well and check.

          Regards,

          Kiran

          (0) 
  5. Former Member

    Hi Kiran,

    i test the WD “WD_TEST_APPL_ACFEXECUTE” of SAP. It is in principle the same application you describe. But when i want to open notepad for example i can see in the log following error message: 

    Error:-1 access denied (“java.io.FilePermission” “C:\Windows\System32\notepad.exe” “read”).

    I have created a whitelist and installed the certficate.

    i connot find any solution to solve my problem. Maybe you have an idea?

    Regards

    Alexander

    (0) 
    1. Kiran Kumar Valluru Post author

      Hi,

      It’s a security issue. To solve this, in your local machine, go to -> Program files -> Java -> jre7 ( your version) -> lib -> security

      change the java.policy file

      grant

      {

           permission java.security.AllPermission;

      };

      to grant all permissions.

      Cheers,

      Kiran

      (0) 
      1. Former Member

        Hi Kiran,

        thank you for Reply. I changed the policy file and now it works. I have one mor question. When i make an entry in the whitelist like:

        C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe

        I can see in the log following error:

        Error:244 application not cleared by whitelist: C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe

        I also tried to set the path as following

        $Programm Files$\\Adobe\Reader 11.0\Reader\AcroRd32.exe

        but i get the same error message.

        Whats wrong? Maybe you have an idea?

        Regards

        Alexander

        (0) 
        1. Kiran Kumar Valluru Post author

          Hi,

          After maintaining the white list, have you regenerated the xml file? You have to activate it again to overwrite the security white list xml file.  Please maintain the same and activate it. See part 2 for reference.

          Regards,

          Kiran

          (0) 
          1. Former Member

            Hi Kiran,

            thank you for your reply. I have no activation button. I Just can save the whitelist and download the xml file. When i open this xml wit IE i can see the entrys i set in whitelist.

            I also have to work with certifcates.

            this is my xml file:

            <?xml version=”1.0″ encoding=”UTF-8″?>

            -<SAP><type>SAP object rules</type><version>1.0</version>

            <timestamp>23.10.2013 15:34:01</timestamp>-

            <configuration>

            <rule_set_priority>0</rule_set_priority>

            </configuration>

            -<rules>

            -<rule id=”2″>

            -<file>

            <name>$Program Files$\Adobe\Reader 11.0\Reader\AcroRd32.exe</name>-<parameter type=”STRING” position=”03″>

            <legalValue>*.pdf</legalValue>

            </parameter>

            </file>

            -<file>

            <name>C:\Program Files (x86)\CoCreate\OSD_Drafting_11.60\me10.exe</name>-<parameter type=”STRING” position=”02″>

            <legalValue>*.mi</legalValue>

            </parameter></file>

            -<file>

            <name>C:\WINDOWS\system32\mspaint.exe</name>

            </file>

            -<file>

            <name>C:\WINDOWS\system32\notepad.exe</name>

            -<parameter type=”STRING” position=”01″>

            <legalValue>*.txt</legalValue>

            </parameter></file>

            <enabled>1</enabled>

            <action>0</action>

            </rule>

            </rules>

            </SAP>

            (0) 
  6. Chandra Shekhar Agarwal

    Hello Kiran,

    Is there any Fm for the same without using concept of bat file.

    I want to open the login screen of some system. Like if we are running  sapgui <server_name> 00  in run command it will open some login screen of given server. Can we do the same thing using some FM or Bat file in ABAP.

    (0) 
    1. Kiran Kumar Valluru Post author

      Hi Chandra,

      You can create a .bat file for the same, write the below code in Notepad and save it as *.bat.

      START “Title” sapgui <server_name> <instance>

      Regards,

      Kiran

      (0) 
        1. Kiran Kumar Valluru Post author

          looks like some infinite process is going ..

          Check, if you got some security popup in the background like below:

          /wp-content/uploads/2014/04/sec_432949.png

          Also,First simply create a Bat file and check if it is working.

          GUI.png

          And did the whitelist configured properly..!

          Regards,

          Kiran

          (0) 
            1. Kiran Kumar Valluru Post author

              ok.. still not working..? Is it working when u test bat file seperately and not from WDA..? or is it not working at all..?

              I am able to open the SAP log on when I test it.

              (0) 
                1. Kiran Kumar Valluru Post author

                  hmm.. I thought you were not able to open only SAP Logon. If everything is not working then fine.. ๐Ÿ˜›  

                  Check if the whitelist activated properly( xml file generated..? ) Try restarting and re-generating the xml. If not check with your basis team for any certificates to install.

                  Regards,

                  Kiran

                  (0) 

Leave a Reply