Skip to Content
0

Execute an external program (.exe file), from a RFC

Sep 21, 2017 at 07:10 AM

222

avatar image

Hi

I have a requirement to execute an exe file, using ABAP code, kept on a local system of the user.

Well, it is very much possible when the user is logged on to SAP GUI ( module pool or a report ) using ws_execute, but ours is a fiori application and i need to do it using a RFC.

  • The restriction is, we can not put the exe on the application server.

I had found a probable solution on few SCN threads, of using RFC_REMOTE_EXEC, but none states the clear guide lines.

So please help me with another solution or how to use RFC_REMOTE_EXEC as in

  • What exactly is the destination parameter, because the exe can be on different user systems, so i want to excess that particular systems exe. How will the RFC_REMOTE_EXEC find the exe.
  • How dose this command work, i have a clue that it is created using SM69 but not sure how, and how will this command find the exact file.
  • How exactly all this works (SAP note - 77075) !!

Regards, Srijayant

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Stefan Schnell
Sep 29, 2017 at 03:48 AM
0

Hello Srijayant,

over two years ago I wrote here about Background Light, a server application and a replacement for CL_GUI_FRONTEND_SERVICES. I programmed it exactly for this case of requirement which you described. Here an example how to call an executable on the frontend server:

"-Begin-----------------------------------------------------------------
  Program zBLightExample.

  "-Variables-----------------------------------------------------------
    Data:
      BLight Type Ref To zBackgroundLight,
      Result Type Integer,
      Button Type Integer,
      SystemDir Type String,
      ProgName Type String
      .

  "-Main----------------------------------------------------------------
    Create Object BLight.
    Check BLight->BackgroundLightExists( ) = 1.

    SystemDir = BLight->GetSystemDir( ).
    ProgName = SystemDir && 'cmd.exe'.

    Call Method BLight->Execute
      Exporting
        File = ProgName
        Parameters = '/k'
        Directory = 'C:\'
        ShowCmd = BLight->SW_Show
        SynchFlag = 1 "Synchronously
        "SynchFlag = 0 "Asynchronously
      Importing
        Result = Result.

    If Result = 0.
      Call Method BLight->MsgBox
        Exporting
          Text = 'An error occured'
          Caption = 'Hint'
          Style = BLight->MB_OkOnly
        Importing
          Button = Button.
    Else.
      Call Method BLight->MsgBox
        Exporting
          Text = 'ABAP program runs again'
          Caption = 'Hint'
          Style = BLight->MB_OkOnly
        Importing
          Button = Button.
    EndIf.

"-End-------------------------------------------------------------------

As you can see, you can easily run a local executable on this way. In this example only cmd.exe with parameters in a special directory etc. You can start Background Light via batch with different parameters. It offers, for security reasons, a monitor to see each step which an ABAP program proceed on the frontend server detailed. Also you can set Background Light in single step mode, which means you can decide for each operation whether you want to execute it or not.

Here a comparisation between the class CL_FRONTEND_SERVICES and the methods of Background Light:

CL_FRONTEND_SERVICES                    Background Light
CHECK_GUI_SUPPORT                       ---
CLIPBOARD_EXPORT                        SetClipboard
CLIPBOARD_IMPORT                        GetClipboard
                                        ClearClipboard
DIRECTORY_BROWSE                        BrowseDirectory
DIRECTORY_CREATE                        CreateDirectory
DIRECTORY_DELETE                        DeleteDirectory
DIRECTORY_EXISTS                        ExistsDirectory
DIRECTORY_GET_CURRENT                   GetCurrentDir
DIRECTORY_LIST_FILES
DIRECTORY_SET_CURRENT                   SetCurrentDir
DISABLEHISTORYFORFIELD                  ---
ENVIRONMENT_GET_VARIABLE                GetEnvVar
ENVIRONMENT_SET_VARIABLE                SetEnvVar
EXECUTE                                 Execute
FILE_COPY                               CopyFile
FILE_DELETE                             DeleteFile
FILE_EXIST                              ExistsFile
FILE_GET_ATTRIBUTES                     GetFileAttr
FILE_GET_SIZE                           FileSize
FILE_GET_VERSION
FILE_OPEN_DIALOG                        OpenFileDialog
FILE_SAVE_DIALOG                        SaveFileDialog
FILE_SET_ATTRIBUTES                     SetFileAttr
GET_COMPUTER_NAME                       GetComputerName
GET_DESKTOP_DIRECTORY                   GetDesktopDir
GET_DRIVE_FREE_SPACE_MEGABYTES
GET_DRIVE_TYPE
GET_FILE_SEPARATOR
GET_FREE_SPACE_FOR_DRIVE
GET_GUI_PROPERTIES                      ---
GET_GUI_VERSION                         ---
GET_IP_ADDRESS                          GetIPAddress
GET_LF_FOR_DESTINATION_GUI
GET_PLATFORM
GET_SAPGUI_DIRECTORY                    ---
GET_SAPGUI_WORKDIR                      ---
GET_SAPLOGON_ENCODING                   ---
GET_SCREENSHOT
GET_SYSTEM_DIRECTORY                    GetSystemDir
GET_TEMP_DIRECTORY                      GetTempDir
GET_UPLOAD_DOWNLOAD_PATH                ---
GET_USER_NAME                           GetUserName
GET_WINDOWS_DIRECTORY                   GetWindowsDir
                                        GetHomeDir
GUI_DOWNLOAD                            DownloadFile
GUI_UPLOAD                              UploadFile
IS_TERMINAL__SERVER
RAISE_SCRIPTING_EVENT                   ---
REGISTRY_DELETE_KEY
REGISTRY_DELETE_VALUE
REGISTRY_GET_DWORD_VALUE
REGISTRY_GET_VALUE
REGISTRY_SET_DWORD_VALUE
REGISTRY_SET_VALUE
                                        MsgBox
                                        DebugPrint
                                        Ping
                                        IsWOW64
                                        IsX64
                                        Sleep
                                        ExtractResource

For an easily integration offers Background Light an ABAP class which wraps all possible functions.

Enjoy it.

Cheers
Stefan

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hello Stefan,

Thanks for the reply, it was very helpful and explanatory, well since it is a client system, before trying it out i had to clarify if my understanding is correct.

So, BackgroundLight class is not available in general, and if we go ahead and install the server application Background light, this class will be available in ABAP workbench ?

Then we can use the respective methods to trigger an exe, at presentation layer on any system ?

Now, if i put my scenario as a landscape, it would look like below,

so another, clarification i request is how would the RFC & BackgroundLight class executing at application layer, find a particular user system and an executable placed on it.

It is a requirement, that has hanged an entire fiori app,

Your advice will be a big help

Regards, Srijayant

1

Hello Srijayant,

thanks for your reply.

To your questions:

"So, BackgroundLight class is not available in general, and if we go ahead and install the server application Background light, this class will be available in ABAP workbench?" No, you must implement the class explicite on your SAP backend system. The class offers the easy access to the server application from ABAP.

"How would the RFC & BackgroundLight class executing at application layer, find a particular user system and an executable placed on it?" BackgroundLight runs as a server application on the user system, otherwise it isn't possible to execute an application.

BackgroundLight is not designed for mass use, only for single use and special cases.

Best regards
Stefan

0