Skip to Content
Technical Articles
Author's profile photo Stefan Schnell

ScriptX – Library To Use Any Script Language Inside ABAP

Important hint: This content is outdated.

ScriptX is a COM library to control scripting languages. Therefor it offers a set of different functions which supports the pre and post activities to use any scripting language, and also the communication to the running script. ScriptX contains FBSL, a powerful scripting language which extends the possibilities of ScriptX to a maximum.


Lord of the Julia Rings 2 inside ABAP in eclipse

ScriptX builds a bridge to integrate your presentation server environment on Windows platform in the SAP application server environment. You can communicate between these two worlds on the application server side with ABAP and on the presentation server side with FBSL. FBSL offers phantastic possibilities to be the base on the presentation server side.



UFO inside ABAP in eclipse

Python inside ABAP

With ScriptX you can use e.g. Python inside ABAP. Here an example how to use a simple Python 3.4.1 script inside ABAP.

  Program ZSCRIPTX.

    Constants SW_SHOWNORMAL Type i Value 1.

      oScriptX Type OLE2_OBJECT,
      Buffer Type String,
      WorkDir Type String,
      PathName Type String,
      FileName Type String,
      rc Type i,
      hFileMap Type i,
      RetCode Type String

      Define _.
        Concatenate Buffer &1 cl_abap_char_utilities=>cr_lf Into Buffer.

      Define Flush.
        Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.

      Create Object oScriptX 'ScriptX'.
      If sy-subrc <> 0 Or  oScriptX-Handle = 0 Or oScriptX-Type <> 'OLE2'.
        Call Function 'ZSCRIPTXDLL'.
        Create Object oScriptX 'ScriptX'.

      If sy-subrc = 0 And oScriptX-Handle > 0 And oScriptX-Type = 'OLE2'.

        "-Show messages in system debugger, e.g. DebugView--------------
          Set Property Of oScriptX 'DebugOutput' = 1.

        "-Get SAP GUIs work directory-----------------------------------
          Call Method cl_gui_frontend_services=>get_sapgui_workdir
            Changing SAPWORKDIR = WorkDir Exceptions Others = 1.
          Set Property Of oScriptX 'CurrentDirectory' = WorkDir.

        Call Method Of oScriptX 'About'.

        "-Create archive file-------------------------------------------
          Call Function 'ZPYTHONRAR'.

        "-Unpack archive------------------------------------------------
          Call Method Of oScriptX 'Unrar' Exporting
            #1 = 'Python.rar' #2 = ''.

        "-Delete archive file-------------------------------------------
          Call Method Of oScriptX 'DeleteFileA' Exporting
            #1 = 'Python.rar'.

        Call Method Of oScriptX 'FileMapCreate' = hFileMap
          Exporting #1 = 'SAP001' #2 = 64.

        If hFileMap <> 0.

"-Python Script begin---------------------------------------------------

_ '# -*- coding: iso-8859-15 -*-'.

_ 'import ctypes'.
_ 'import sys'.


_ 'print("Python version ", sys.version)'.
_ 'print("Hello World from Python")'.
_ 'var_inp = input("Enter something: ")'.
_ 'print("You entered: ", var_inp)'.

  "-Transfer the input to the memory map file---------------------------
_ 'hMMF = ctypes.windll.kernel32.OpenFileMappingW(FILE_MAP_ALL_ACCESS, \'.
_ '  0, "SAP001")'.
_ 'if hMMF != 0:'.
_ '  buffer = ctypes.windll.kernel32.MapViewOfFile(hMMF, \'.
_ '    FILE_MAP_ALL_ACCESS, 0, 0, 0)'.
_ '  if buffer != 0:'.
_ '    ctypes.cdll.msvcrt.strcpy(buffer, var_inp.encode("ascii"))'.
_ '    rc = ctypes.windll.kernel32.UnmapViewOfFile(buffer)'.
_ '  rc = ctypes.windll.kernel32.CloseHandle(hMMF)'.
_ 'input("Press any key...")'.

"-Python Script end-----------------------------------------------------

          "-Create Python script file-----------------------------------
            Concatenate WorkDir '\' Into FileName.
            Call Method Of oScriptX 'WriteFile' Exporting #1 = FileName
              #2 = Buffer.

          "-Add Python path---------------------------------------------
            Concatenate WorkDir '\Python' Into PathName.
            Call Method Of oScriptX 'AddPath' Exporting #1 = PathName.

          "-Execute Python script---------------------------------------
            Call Method Of oScriptX 'Shell' = rc
              Exporting #1 = 'python.exe' #2 = ''
              #3 = SW_SHOWNORMAL #4 = 1.

          "-Read the input from the memory map file---------------------
            Call Method Of oScriptX 'FileMapRead' = RetCode
              Exporting #1 = 'SAP001' #2 = 64.

          "-Destroy memory map file-------------------------------------
            Call Method Of oScriptX 'FileMapClose' = rc
              Exporting #1 = hFileMap.

          "-Delete Python script file-----------------------------------
            Call Method Of oScriptX 'DeleteFileA'
              Exporting #1 = FileName.

          "-Delete Python environment-----------------------------------
            Call Method Of oScriptX 'DeleteDirectory'
              Exporting #1 = 'Python'.

          "-Write the content of the memory map file--------------------
            Write: / RetCode.


        Free Object oScriptX.






2020/05/14 – Content is outdated

2015/11/21 – New version 1.6 available

  • Checked library with Microsoft Windows 10 x64.
  • Minor changes.
  • Actualized unrar library implemented.

2015/01/01 – New version 1.5 available

  • Actualized unrar library implemented.

2014/11/19 – New version 1.4 available.

  • New interprocess communication methods (IPC) to synchronize different processes
  • New unzip file method to unpack a specific file from an archive
  • Add Python examples
  • Add new sections to the help

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Ramana SBLSV
      Ramana SBLSV

      Hi Stefan,


      Where can we find the used function modules in the above ZScriptX program.

      Could you please mention more clear steps on how to directly use Python Script code within ABAP program.


      Thanks in advance.




      Author's profile photo Stefan Schnell
      Stefan Schnell

      Ramana SBLSV

      Hello Ramana,

      unfortunately surrendered the owner of FBSL. For this reason, I have also given up the ScriptX library too. As alternative way I suggest this way to use Python.

      Best regards