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

Tip: Easy Way of ABAP ActiveX Connectivity

A long time ago Thomas Jung published his very good blog about “Using Classic ActiveX Controls in the ABAP Control Framework” here.

I asked myself, is there an easier way to realize a connectivity between an ActiveX control and an ABAP program, e.g. for prototyping.

Here now my result: I use a selection screen with a docking container, and the docking container is linked to the ActiveX control. That’s all 🙂

 

At first the program:

/wp-content/uploads/2014/08/001_514276.jpg

"-Begin-----------------------------------------------------------------
  Program Z_TEST.

    "-Variables---------------------------------------------------------
      Data Ref_Dock Type Ref To CL_GUI_DOCKING_CONTAINER.
      Data Ref_Media Type Ref To Z_CL_MEDIA.

    "-GUI---------------------------------------------------------------
      Selection-Screen Begin Of Block Media.
        Parameters pa_Dummy(1).
      Selection-Screen End Of Block Media.

    "-Main--------------------------------------------------------------
      At Selection-Screen.

        Create Object Ref_Dock
          Exporting
            REPID = sy-repid
            DYNNR = sy-dynnr
            SIDE = CL_GUI_DOCKING_CONTAINER=>dock_at_right
            RATIO = 50
          Exceptions
            Others = 1.

        Create Object Ref_Media
          Exporting
            PARENT = Ref_Dock
          Exceptions
            Others = 1.

        Call Method Ref_Media->setdatasource
          Exporting
            FileName = 'MyMovie.mp4'.

        Call Screen 1000.

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

 

As you can see, only a selection screen with a dummy parameter, the docking container, the media class and a method call to set the file name property.

 

Now the class for the ActiveX control, in my case the Windows Media Player:

002.JPG

"-Begin-----------------------------------------------------------------

  Class Z_CL_MEDIA Definition Public Inheriting From CL_GUI_CONTROL
    Final Create Public .

    Public Section.
      Type-Pools CNTL .

      Methods Constructor Importing Parent Type Ref To CL_GUI_CONTAINER.
      Methods Dispatch Redefinition.
      Methods SetDataSource Importing FileName Type String.

  EndClass.

  Class Z_CL_MEDIA Implementation.

    Method Constructor.

      Call Method Super->constructor
        Exporting
          CLSID = 'MediaPlayer.MediaPlayer'
          PARENT = Parent
          LIFETIME = 2
        Exceptions
          Others = 1.
    EndMethod.

    Method Dispatch.
      Call Method CL_GUI_CFW=>Flush.
    EndMethod.

    Method SetDataSource.
      Call Method Set_Property
        Exporting
          PROPERTY = 'FileName'
          VALUE = FileName.
      Call Method CL_GUI_CFW=>FLUSH.
    EndMethod.

  EndClass.

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

 

As you can see, also nothing special. In the constructor method is the name of the ActiveX control (ClassID) defined and the method SetDataSource sets the property FileName of the control.

 

Here now an example result:

003.JPG

With only 53 lines code you can implement the Windows MediaPlayer ActiveX control inside a selection screen.

Cheers
Stefan

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Naimesh Patel
      Naimesh Patel

      Hello Stefan,

      Thanks for sharing the article.

      I wonder many times about the existing ActiveX controls. I can view the existing methods using the ActiveXplorer but don't know if I can get the full coding of the controls. Is COMView able to show that?

      Thanks,
      Naimesh Patel

      Author's profile photo Stefan Schnell
      Stefan Schnell
      Blog Post Author

      Hello Naimesh,

      thanks for your reply.

      No, COMView works like ActiveXplorer, it shows the interface of the library - the methods and attributes, not more and not less. How to use the control is normally part of the technical documentation of the manufacturer.

      Cheers

      Stefan

      Author's profile photo Ashish Ahire
      Ashish Ahire

      Hi Stefan ,

                         Good same kind of document I've also posted , for access webcam and media player , comport ......

      http://scn.sap.com/docs/DOC-54323

      Naimesh Patel-

      I used ole viewer but yes we can't see the code only method signature we can see .

      Author's profile photo Stefan Schnell
      Stefan Schnell
      Blog Post Author

      Hello Ashish,

      thanks for your reply and your addition. It is interesting to see how programmers come to similar solutions independently.

      Cheers

      Stefan

      Author's profile photo Enno Wulff
      Enno Wulff

      Hi Stefan, once again interesting how easy to implement controls in SAPGUI…

      But also how hard it is… ?

      1. How do you know that you can use “Mediaplayer.Mediaplayer”? When analyzing Mediaplayer entry in COM/OLEview I didn’t find a hint about this word.
      2. Why does your solution does not work when directly using the CLSID of Mediaplayer?
        22D6F304-B0F6-11D0-94AB-0080C74C7E95 

      Regards

      Enno

      /Edit: Just found the entry in /Object Classes/All Objects/Windows Mediayplayer 1.0

      I searched in /Type Libraries...

      Question 2. still remains... 😉

      Author's profile photo Stefan Schnell
      Stefan Schnell
      Blog Post Author

      Hello Enno,

      thanks for your reply.

      1. A programmatic identifier (ProgID) is a registry entry that is associated with a CLSID.
        Another way to find it is to enter the CLSID into the search of regedit.

         

      2. Try this one, it runs in my case perfect:
        Method Constructor.
        
          Call Method Super->constructor
            Exporting
              CLSID = '{22D6F312-B0F6-11D0-94AB-0080C74C7E95}'
              "CLSID = 'MediaPlayer.MediaPlayer'
              PARENT = Parent
              LIFETIME = 2
            Exceptions
              Others = 1.
        
        EndMethod.​

        It seems to be important to use the brackets. So it makes no difference what do you use, the ProgID or the ClassID.


        Here my result with Big Buck Bunny.

      Cheers
      Stefan

      Author's profile photo Sam Indra
      Sam Indra

      Hi Stefan

      Why do i always get sy-subrc 2 whenever i want to create mscomm object?

       

      Thanks

      Author's profile photo Stefan Schnell
      Stefan Schnell
      Blog Post Author

      Hello Sam,

      I don't know mscomm. sy-subrc 2 means: Error in function call in SAP GUI.

      Best regards
      Stefan