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

Another Integration Scenario – COM Meets ABAP

I posted in the last time different Eclipse integration scenarios:

  1. FreeBASIC meets ABAP – how to use FreeBASIC (representative for other languages) via RFC library with ABAP
  2. Java meets ABAP – how to use Java code via JNI and a Java COM bridge inside ABAP


Here now a new integration scenario: COM library development and the using of this COM library with ABAP in the ABAP in Eclipse IDE.


To develop COM libraries I use PowerBASIC. PowerBASIC is a very powerful compiler to create 32-bit applications or libraries. also COM libraries. You can find more information about PowerBASIC here. To use PowerBASIC inside from ABAP in Eclipse I use the Wordfile Editor plugin too, which I presented here.


The first step which I made, was to integrate the compiler inside ABAP in Eclipse.



Now is it possible to code and to compile the COM library with ABAP in Eclipse.



  '-Resource section----------------------------------------------------
    #Resource TypeLib 1, "COMMsgBox.tlb"

    #Compile DLL
    #Dim All

    $LIBID = Guid$("{D1AA85A8-F8AD-4A0E-9DE8-942543A3741F}")
    $CLSID = Guid$("{084BDEC8-ACA0-4068-A6B7-778785D64521}")
    $IID = Guid$("{A5EBE762-82A4-44A9-9A2E-2BE6CF102564}")

  '-COM directives------------------------------------------------------
    #Com Doc  "COMMsgBox"
    #Com Name "COMMsgBox", 1.0
    #Com Guid $LIBID
    #Com TLib On

    Class COMMsgBox $CLSID As Com

      Interface ICOMMsgBox $IID : Inherit IDispatch

        '-Method BoxMsg-------------------------------------------------
          Method BoxMsg()
            MsgBox("This is a Test")
          End Method

      End Interface

    End Class



After the compiling I registered the COM library with regsvr32 in the Wicked Shell – look here.


Now we can use this COM library inside ABAP.



  Program Z_TEST.

      Type-Pools OLE2.

      Data MsgBox Type OLE2_Object.

      Create Object MsgBox 'COMMSGBOX'.
      If sy-subrc = 0 And MsgBox-handle <> 0 And MsgBox-type = 'OLE2'.

        Call Method Of MsgBox 'BoxMsg'.

        Free Object MsgBox.





Another point of view in the hemisphere of polyglot programming with ABAP in Eclipse.



But one salt crumb:

After the using of the COM library with ABAP, the process SapGuiServer.exe blocks the COM library and it is e.g. not possible to compile the library again. You got the following message:


So I developed a small program to terminate SapGuiServer.exe and place it also in the tools of Eclipse.


; Begin-----------------------------------------------------------------

  ; Directives----------------------------------------------------------

  ; Function Terminate Processes----------------------------------------
    Procedure TerminateProcesses(Name.s, ExitCode = 0)

      ; Variables-------------------------------------------------------
        Protected result
        Protected processID
        Protected hProcess
        Protected Process.PROCESSENTRY32
        Protected ProcSnap = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0)

      If ProcSnap <> #ERROR_INVALID_HANDLE
        Process\dwsize = SizeOf(PROCESSENTRY32)
        If Process32First_(ProcSnap, Process) = #True
          While Process32Next_(ProcSnap, Process) <> #False
            If Trim(PeekS(@Process\szExeFile,#MAX_PATH)) = Name.s
              processID = Process\th32ProcessID
              If processID
                hProcess  = OpenProcess_(#PROCESS_TERMINATE, #False, processID)
                If hProcess
                  If TerminateProcess_(hProcess, ExitCode)
                    result = #True

      ProcedureReturn result


  ; Main----------------------------------------------------------------
    If Not TerminateProcesses(ProgramParameter(0))
        "Failed to terminate " + ProgramParameter(0) + " processes")

; End-------------------------------------------------------------------


As you can see, nothing special, only process termination of any process with the name from the arguments of the command line – SapGuiServer.exe.

You can the source and the compiled version of TerminateProcess here.

After calling this program I get the following message:


Mhmm, not nice, but it works. On this way it is not necessary to restart the complete IDE to compile the library again.

This could be a small improvement for a future release – a defined exit of the SapGuiServer process, for this case of development.


I like ABAP in Eclipse very much, it gives us new horizons of development integration.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.