Technical Articles
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:
"-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:
"-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:
With only 53 lines code you can implement the Windows MediaPlayer ActiveX control inside a selection screen.
Cheers
Stefan
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
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
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 .
Hello Ashish,
thanks for your reply and your addition. It is interesting to see how programmers come to similar solutions independently.
Cheers
Stefan
Hi Stefan, once again interesting how easy to implement controls in SAPGUI…
But also how hard it is…
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... 😉
Hello Enno,
thanks for your reply.
Another way to find it is to enter the CLSID into the search of regedit.
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
Hi Stefan
Why do i always get sy-subrc 2 whenever i want to create mscomm object?
Thanks
Hello Sam,
I don't know mscomm. sy-subrc 2 means: Error in function call in SAP GUI.
Best regards
Stefan