Skip to Content

Hello community,

the overview of this forum offers a lot of connection technologies from and to ABAP, e.g. HTTP, XML and SOAP, RFC/BAPI etc. etc. etc. I am the opinion, that the COM interface (Component Object Model) is also a connection technology of ABAP. Sure, it works only with dialog processes with the SAP GUI for Windows, on this point it is limited in comparison with other connectivity methods. Last but not least combines the ABAP COM interface an easy coding with powerful possibilities.

Here now an example of process synchronisation between ABAP and the Microsoft Office suite, e.g. Excel with VBA (Visual Basic for Applications), via a COM library. For the process synchronization and communication offers Windows the IPC interface (Interprocess Communication).

There are different technics to synchronize and to communicate between processes on Windows, like

  • Events,
  • Semaphores,
  • FileMaps and
  • the ClipBoard
  • etc.

To use this possibilities I programmed a COM library which offers this technics. You find it here.

At first the ABAP program which creates an event, with the name TestEvent, and then it waits until the event is set.

“-Begin—————————————————————–

  Report  zCOMIPC.

  “-Includes————————————————————

    Include OLE2INCL.

  “-Constants———————————————————–

    Constants Infinite Type i Value -1.

  “-Variables———————————————————–

    Data oIPC Type Ole2_Object.

    Data rc Type i.

    Data hEvent Type i.

  “-Main—————————————————————-

    Create Object oIPC ‘COMIPC’.

    If sy-subrc = 0 And oIPC-HANDLE <> 0 And oIPC-TYPE = ‘OLE2’.

      “-Event———————————————————–

        Call Method Of oIPC ‘EventCreate’ = hEvent

          Exporting #1 = ‘TestEvent’ #2 = 1 #3 = 0.

        Call Function ‘AC_SYSTEM_FLUSH’ Exceptions Others = 1.

       

        If hEvent <> 0.

          Call Method Of oIPC ‘EventWait’ = rc

            Exporting #1 = ‘TestEvent’ #2 = Infinite.

          “————————————————————-

          “-

          “- At this point the ABAP program waits until the VBA routine

          “- was executed

          “-

          “————————————————————-

          Call Function ‘AC_SYSTEM_FLUSH’ Exceptions Others = 1.

          Call Method Of oIPC ‘EventClose’ = rc

            Exporting #1 = hEvent.

          Call Function ‘AC_SYSTEM_FLUSH’ Exceptions Others = 1.

         

        EndIf.

      Free Object oIPC.

    EndIf.

“-End——————————————————————-

Here now the VBA routine, to set the event.

‘-Begin—————————————————————–

  Public oIPC As COMIPC.COMIPC

  ‘-Sub TestEvent——————————————————-

    Sub TestEvent()

   

      Set oIPC = CreateObject(“COMIPC”)

     

      oIPC.EVENTSET “TestEvent”

     

      Set oIPC = Nothing

     

    End Sub

‘-End——————————————————————-

After the event is set, the ABAP program continues running and closes the event.

This simple example should demonstrate, on the one hand, that with little effort very interesting solutions can be created and, on the other hand, how powerful these solutions can be. On this way you can synchronize now different processes on the application and presentation server, in a context of dialog processes. The example above could be used to get data from ABAP to the Office suite, the data could be processed, in a longer running process, and after this the data comes back to the same ABAP process, which continues its work. Certainly there are many ways to realize this, and this is one of them.

The COM library itself is nothing more than an easy wrapper around the Windows API functions of IPC. Here as example the EventSet method:

‘-EventSet————————————————————–

‘-

‘- Sets the specified event object to the signaled state

‘-

‘- Param: EventName As String

‘- Return: Zero if fails

‘-

‘———————————————————————–

  Method EventSet(ByVal EventName As String) As Long

    ‘-Variables———————————————————

      Local NameOfEvent As AsciiZ * %Max_Path

      Local hEvent As Dword

      Local resSet As Long

      Local resClose As Long

    NameOfEvent = ACode$(EventName)

    hEvent = OpenEvent(%EVENT_ALL_ACCESS, 0, NameOfEvent)

    If hEvent Then

      ‘-Set event——————————————————-

        resSet = SetEvent(hEvent)

      ‘-Close handle—————————————————-

        resClose = CloseHandle(hEvent)

      ‘-Return———————————————————-

        If resSet And resClose Then

          Method = resSet

        Else

          Method = 0

        End If

    Else

      Method = 0

    End If

  End Method

You can realize it in any programming language which supports COM library creation.

Hope you enjoy the perspective.

Cheers

Stefan

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply