Technical Articles
Tip: How to use ActiveX RFC Controls without SAP GUI for Windows
Since a long time SAP offers the ActiveX RFC Controls – wrapper around the classic RFC library (LibRFC [ANSI] and LibRFCU [Unicode]).
You can use this ActiveX Controls without SAP GUI for Windows installation very easily.
Copy for ANSI the files:
- wdobapi.ocx – from directory SAP\FrontEnd\SAPgui
- wdtaocx.ocx – from directory SAP\FrontEnd\SAPgui
- wdtfuncs.ocx – from directory SAP\FrontEnd\SAPgui
- wdtlog.ocx – from directory Common Files\SAP Shared
- librfc32.dll – from directory system32 on 32-bit and from syswow64 on 64-bit Windows environment
- convlib.dll – from directory Common Files\SAP Shared with SAP GUI 7.40
- sapfewut.dll – from directory Common Files\SAP Shared with SAP GUI 7.40
- sapfilecache.dll – from directory Common Files\SAP Shared with SAP GUI 7.40
- saplgmgr2.dll – from directory Common Files\SAP Shared with SAP GUI 7.40
- sapmime.dll – from directory Common Files\SAP Shared with SAP GUI 7.40
Copy for Unicode the files:
- wdobapiU.ocx – from directory SAP\FrontEnd\SAPgui
- wdtaocxU.ocx – from directory SAP\FrontEnd\SAPgui
- wdtfuncU.ocx – from directory SAP\FrontEnd\SAPgui
- wdtlogU.ocx – from directory SAP\FrontEnd\SAPgui, with SAP GUI 7.40 from directory SAP\FrontEnd\SAPgui\Unicode
- librfc32u.dll – from directory system32 on 32-bit and from syswow64 on 64-bit Windows environment
- icudt34.dll – from directory system32 on 32-bit and from syswow64 on 64-bit Windows environment with SAP GUI 7.30
- icudt50.dll – from directory system32 on 32-bit and from syswow64 on 64-bit Windows environment with SAP GUI 7.40
- icuin34.dll – from directory system32 on 32-bit and from syswow64 on 64-bit Windows environment with SAP GUI 7.30
- icuin50.dll – from directory system32 on 32-bit and from syswow64 on 64-bit Windows environment with SAP GUI 7.40
- icuuc34.dll – from directory system32 on 32-bit and from syswow64 on 64-bit Windows environment with SAP GUI 7.30
- icuuc50.dll – from directory system32 on 32-bit and from syswow64 on 64-bit Windows environment with SAP GUI 7.40
- convlib.dll – from directory SAP\FrontEnd\SAPgui\Unicode Shared with SAP GUI 7.40
- sapfewut.dll – from directory SAP\FrontEnd\SAPgui\Unicode Shared with SAP GUI 7.40
- sapfilecache.dll – from directory SAP\FrontEnd\SAPgui\Unicode Shared with SAP GUI 7.40
- saplgmgr2.dll – from directory SAP\FrontEnd\SAPgui\Unicode Shared with SAP GUI 7.40
- sapmime.dll – from directory SAP\FrontEnd\SAPgui\Unicode Shared with SAP GUI 7.40
Also you need the Microsoft VC runtime libraries VC2012, this means VC 11, e.g. from here.
Store this libraries in different sub directories, e.g. ANSI and Unicode, and register the ocx libraries. Now you can use the SAP ActiveX RFC Controls e.g. in VBA or VBScript, without an installed SAP GUI for Windows.
Here a VBScript example:
'-Begin-----------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Explicit
'-Sub Main------------------------------------------------------------
Sub Main()
'-Variables-------------------------------------------------------
Dim SAPFunc, Connection, SAPConnection, PingFunc, retPing
Dim exceptPing
'-Get SAP.Functions-----------------------------------------------
Set SAPFunc = CreateObject("SAP.Functions.Unicode")
If Not IsObject(SAPFunc) Then
MsgBox "CreateObject(SAP.Functions.Unicode) failed", _
vbOkOnly, "Error"
Exit Sub
End If
'-Get SAP.LogonControl connection---------------------------------
Set Connection = SAPFunc.Connection()
If Not IsObject(Connection) Then
MsgBox "SAPFunc.Connection failed", vbOkOnly, "Error"
Exit Sub
End If
'-Set connection parameters---------------------------------------
Connection.Client = "001"
Connection.User = "BCUSER"
Connection.Password = "minisap"
Connection.Language = "EN"
Connection.System = "NSP"
Connection.HostName = "ABAP"
Connection.SystemNumber = 0
'-Connect SAP system----------------------------------------------
SAPConnection = Connection.Logon(0, vbFalse)
If SAPConnection <> 0 Then
'-Call ABAP function module RFC_PING----------------------------
Set PingFunc = SAPFunc.Add("RFC_PING")
If IsObject(PingFunc) Then
retPing = PingFunc.Call()
If retPing = False Then
exceptPing = PingFunc.Exception()
MsgBox CStr(exceptPing), vbOkOnly, "Result"
Else
MsgBox CStr(retPing), vbOkOnly, "Result"
End If
End If
'-Logoff--------------------------------------------------------
Connection.Logoff()
Else
MsgBox "Connection.Logon failed", vbOkOnly, "Error"
End If
End Sub
'-Main----------------------------------------------------------------
Main()
'-End-------------------------------------------------------------------
Addendum 2017/05/20:
With the SAP GUI for Windows 7.50 offers SAP new ActiveX libraries which bases on SAP NetWeaver RFC Library. Here the necessary files from an x64 Windows installation:
- wdobapiU.ocx – from directory SAP\FrontEnd\SAPgui\Unicode
- wdtaocxU.ocx – from directory SAP\FrontEnd\SAPgui\Unicode
- wdtfuncU.ocx – from directory SAP\FrontEnd\SAPgui\Unicode
- wdtlogU.ocx – from directory SAP\FrontEnd\SAPgui\Unicode
- SAPRfcWrapperU.dll – from directory Program Files (x86)\Common Files\SAP Shared
- sapnwrfc.dll – from c:\Windows\SysWOW64
- icudt50.dll – from c:\Windows\SysWOW64
- icuin50.dll – from c:\Windows\SysWOW64
- icuuc50.dll – from c:\Windows\SysWOW64
- convlib.dll – from directory SAP\FrontEnd\SAPgui\Unicode
- sapfewut.dll – from directory SAP\FrontEnd\SAPgui\Unicode
- sapfilecache.dll – from directory SAP\FrontEnd\SAPgui\Unicode
- saplgmgr2.dll – from directory SAP\FrontEnd\SAPgui\Unicode
- sapmime.dll – from directory SAP\FrontEnd\SAPgui\Unicode
Also you need the Microsoft VC runtime libraries VC2013, this means VC 12. Register the ocx libraries and the SAPRfcWrapper.dll library.
Hi Stefan,
How does one convert this same script to python and from python reference the OCX and DLL files?
Thanks,
Mason
Hello Mason,
thanks for your reply. I don't know if someone converted this script to Python. ActiveX interface and Classic RFC Library are deprecated components, so it is not advised to use it now.
Cheers
Stefan
Hello Stefan,
we have the same solution running on an old Windows2003 server. It's time to move it to an Windows 2012R2.
I try to follow your recommendations, but I cannot register dll and ocx files. Do I have to get all the files from a SAPGUI 7.50 for X64 as the server is X64?
Thank you for your reply.
Vincent
Hello Vincent,
thanks for your reply.
It is possible to run the described configuration on an x64 system, I do it by myself. All you must do is to open an x86 console window - C:\Windows\SysWOW64\cmd.exe - as administrator, this is very important. Register now the libraries and all should work well.
Let us know your result.
Cheers
Stefan
Do you recommend adopting SAPRfcWrapperU.dll for my VB.NET application rather than SAP Connector for MS .NET (NCO) ? I have the implementation of SAP Connector for MS .NET (NCO) working, but am unsure whether I should have chosen to use the 7.50 OCX. It appears that SAP Connector for MS .NET (NCO) works with just 2 DLL, does not require COM registration, and my application is now independent of any installed SAP GUI version, which I like very much.
Hello Paul,
in my opinion is in your case a good solution to use NCo. You name good reasons. I think the OCX libaries are interesting to adopt existing projects or if you work in restrictives environments, where only SAP GUI for Windows is available and the programmer don't have any chance to use other possibilities.
Best regards
Stefan
Hi Stefan!
Thanks for the post, it is very useful!
I am trying to learn more about Automatic Logon. (on SAP GUI 740)
I implemented your code for RFC_READ_TABLE (as a Python script) and it works. I run the code, I get the SAP Logon pop-up filled with Client, User, Password and Language. I only have to press 'OK ' and my query runs.
As I understand setting Connection.Logon(0, vbFalse) to vbTrue does not pop-up the SAP Logon window and I assumed that it means the script would log in automatically, but in our case the later query fails with error: 1001, 'No connection to SAP system available.'. I am guessing the login simply does not occur, since I am not clicking on any 'OK' button.
On the 'Advanced' tab of the SAP Logon window I noticed the 'Automatic Logon' option. I have it checked, but still the script cannot automatically log in on the next try. I am assuming something like Connection.AutoLogon must also be set to True, which I have tried without any effect.
I am trying to figure out if I am looking in the wrong place or whether my colleague is right, who mentioned that a few releases ago the Auto Logon was disabled (not sure if in the SAP GUI or server, I don't know where this can be configured by our IT).
If you could share a few ideas regarding Auto Logon that would be great!
Have a schönes Tag!
Fred
Hello Fred,
thanks for your reply.
The flag at Connection.Logon is a silent flag, vbFalse = 0 means a dialog is shown and vbTrue = -1 (this is a little bit tricky) means a dialog is not shown. With a silent logon is equal to vbTrue you can connect a system without any dialog. I checked this with SAP GUI for Windows 7.50 SP 1, where Badari Nath and his colleagues set the ActiveX components on a new platform, and it works without any problems on a back end system with SAP_BASIS 7.02 Level 006.
I don't know an option on the back end to disable auto logon, but I assume it is not correct, because in this case no RFC connection could connect an SAP system without dialog.
Best regards
Stefan
Hi Stefan
Thanks for the information, I find it very useful. Could you please help me with this issue? I cannot figure out a solution.
I’m new to SAP and I’m doing my very first scripts to work in SAP trough VBA. I’ve done some scripts wich I execute from Excel. Those scripts get into SAP, perform some actions and download information into an Excel file. Everything is done via SAP GUI for Windows and I’m constantly getting errors due to the Active Window ID. If the user is working in any other application like Outlook the script likely will throw an error like “ID not found”. Surfing the web looking for solutions I came to this article and I have a couple of questions given my few knowledge of SAP.
In other piece of code I have the following:
I have to repeat the code from above several times to get all the possible popups (not always displayed) and I know is bad coding but I have not been able to get a better solution. Most of errors the user gets while running the script is precisely in this sentence:
popup = session.ActiveWindow.GuiFocus.ID
or in this other one:
session.findById(“wnd[2]”).Close
getting the “Control could not be found by ID” error.
I think this is due to the several Windows the user has opened, as Outlook, Skype or a Web Browser. I cannot tell the user to stop working on its computer and if the user has already open many Windows of SAP GUI the script will likely collapse in any time.
I hope you can help me whit this, I’ve been breaking my head for weeks whit this issue. Thank you so much.
PS. Please forgive my bad English
Hello Osvaldo,
thanks for your reply and welcome in the SAP Community.
First of all: Do not be discouraged, the beginning is always troublesome. In a week you are good, in two weeks you are better, in four weeks you are even better, but in hundred weeks you will realize that there are always things you do not know.
It seems that something needs to be clarified. An RFC connection with an SAP backend and a connection via SAP GUI Scripting are independently. The ActiveX libraries are wrapper around the SAP NetWeaver RFC library sapnwrfc.dll which offers the possibility ot connect an SAP backend via RFC. This has nothing to do with SAP GUI Scripting. For the communication with an SAP system via RFC you need remote function call ready enabled function modules (RFM) on the backend. So your question one can be answered:
Is it possible to use activeX RFC Controls to work with SAP even if the user has a session already opened in SAP GUI? Yes
I mean, to use this features and get all the job done on the backstage and avoid all those errors which occur while interacting with SAP GUI. These are totally different ways to work with an SAP system. SAP GUI Scripting simulates user activities on UI during ActiveX controls communicate via RFC.
To your second question: As far as I understand you correct you want to close a dialog window, which exists in a context of SAP GUI. You can find different solutions to do that for VBA here. All you need is the title of the window.
Let us know your results.
Cheers
Stefan
P.S. American is also not my native toungue, and I believe also from the most users here. Your American is pretty good.
Hi Stefan, thanks so much for your explanation and good wishes.
I tried the solutions provided in the link you posted and they work perfectly, though I'm still getting the error due to the users activity while running the macro. I surfed the web looking for answers and came to this thread. I'm interested in the same subject than the author of the question because I think it would be great to get a well defined library to work with the SAP GUI. I tried the SAPFEWSELib as the author did and got exactly the same error that he mentions. That's a pity, because SAPFEWSELib actually includes a lot of procedures and objects that seem to be so useful and I suspect that library might be the solution to my main issue: being able to run the macro without telling the user to stop working.
On the other hand I'm afraid I won't be able to implement the ActiveX libraries because I don't really understand the way they work, I have a lot to study in the meantime.
Thanks again for your help, I really find your articles and answers very instructive.
Hello Osvaldo,
thanks for your reply.
I am not really sure that I understand your problem correctly. SAP GUI Scripting works for a lot of use cases very very good. I use it since years with success with many different scripting and compiler languages.
One of the questions of the thread you linked trough is:
"I don't like the SapGuiAuto As Object as it doesn't really say what it is..."
SapGuiAuto offers ISapGuiAuto interface of the module saplogon.exe, but it seems not possible to get the type library of it. So it is one way to accept that SapGuiAuto is an untyped object.
Don't be afraid, ActiveX is a systemwide interface to libraries. The interface includes a description of the parameters of the methods and attributes. It is a great idea and very easy to use. All you need is practice. Try it, try it, try it. Each of us has begun like you.
In Germany we say: "Es ist noch kein Meister vom Himmel gefallen." In American: "It is not yet a master fallen from heaven." Which means everybody needs practice and for that you need time.
Cheers
Stefan
Hi Stefan,
Thanks for your answer.
My problem is that I have to get some text from a field in the UDM_Specialist. I can only access to that field after typing the costumer ID, pressing some buttons and closing a variable number of warning/message windows. Perhaps I should try to change my programming approach. I have worked with Scripts from VBA to SAP and they have worked perfectly, this is my first problem with scripts. Here is my full code:
I don't really like that code because I feel that I don't have under control anything that's happening on the background. Perhaps I have to change my programming approach.
thanks again for your good wishes, they mean a lot! specially in these days of frustration
I like that idiom (phrase? expression?) of you. Here in México we have a similar one in meaning: "Más sabe el diablo por ser viejo que por ser diablo" which in American would be something like this: "The Devil knows more because he is old than because he is the Devil" and that means that the more old you get or the more you practice something, the more experienced you are.
Have a nice day.
Hello Osvaldo,
thank you very much for your reply and for your sageness.
Sorry, I can’t try your code, I don’t have any data.
Here a suggestion, try instead this
this
As far as I can see looks your code good.
Best regards
Stefan
Hi Stefan,
Sorry for the delay, I've been busy and couldn't reply
Thanks for the suggestion, it works perfectly!
I hope you have a nice day, thank you so much for your time and for sharing your knowledge, that means a lot. I'll keep an eye on your posts, I'm learning a lot.
Hello Stefan,
can you give any help on how to pass a table when calling a BAPI?
I know how to pass one parameter, but I aim to pass a Structure and Table as well.
Thanks in advance!
Hi Guys,
i've recently change my laptop for a 64bits machine.
I've SapGUI 7.5 and i've regsitered unicode ocx but unfortunately, i encountered always the same issue when i try to connect from Excel or Access. "ActiveX can"t create object" at this lign
Set SapConn = CreateObject("SAP.Functions.Unicode"), it works with my old laptop 🙁
thanks for your help
Hello Demarest,
do you use the x64 version of Microsoft Office? If yes, you can't use the ActiveX libraries in this context, these libraries are x86.
Best regards
Stefan
Hi Stefan,
Thanks for your quick reply
i have found a workaround with some new registry entries (DllSurrogate). i can now connect and retrieve data but i'm facing a new issue during an upload. I try to upload idoc.
i've a message "Bad variant type" at his line, it works before with 32bits version. D you have an idea ?
Public Function CreateR3Structure(objConn As Object, strRefStruct As String, strParmName As String) As Object
Dim objTable As Object
Dim lngResult As Long
'Initialize bdctable
Set objTable = CreateObject("SAP.TableFactory.Unicode.1")
Set CreateR3Structure = objTable.NewStructure
'For export bdctable
lngResult = CreateR3Structure.CreateFromR3Repository(objConn.Connection, strRefStruct, strParmName)
Set objTable = Nothing
End Function
Hello Demarest,
thanks for your reply.
I know the DllSurrogate solution, nearly four years ago I presented it here.
I assume that the R3Connection parameter of the CreateFromR3Repository method expects an x86 IDispatch (Long - 4 Bytes), but you send an x64 IDispatch (LongPtr - 8 Bytes). You can find more information about different types here. It seems better to don't use the unspecified Object type and to use SAPLogonCtrl.Connection type instead.
Let us know your results.
Best regards
Stefan
Hi all, hoping for some quick help. I'm using ActiveX RFC connection to my SAP ECC5 to return characters in English, Spanish, French, Italian, Portuguese and Czech. I haven't touched the code in a couple of years, but now some of the Czech characters are not coming out correctly. I'm using SAPFunctionsOCX, and codepage 4110, as I always have.
The SAP system has had very little changes in the last 2 years. What has changed is that I'm working on a Windows7 machine, but I also tried on an old XP machine and the Czech characters are still not coming out right.
Any ideas here? I'm thinking there's a dll or ocx that has changed, but I don't even know where to start looking.....
Thank you Stefan for this information.
Do you think it would be possible to use this Tip to use ActiveX Controls Classic RFC from a SAP GUI 7.40 on a computer with SAP GUI 7.60?
Thank you very much
Christian Taconet
Hi Stefan:
your article is very for me awesome every time.
Now , I have a decoder problem on below here.
SAPConnection = Connection.Logon(0, True)
If we use front situation , let user keyin login info in chinese environment.
but the pop gui windows , we look error code in every word. how can solve it? thanks.
Hi Stefan,
could you describe how to do it with the latest version of sap gui (7.70)?
Many thanks