on 11-10-2015 7:52 PM
All,
I'm working on an application for my company to run SAP Script, using SAP Scripting API. The application is being programmed in VB.NET from Visual Studio 2015.
When I try to open a Gui Application, I can get all the things I need (GuiApplication, ScriptingEngine, Session 0 etc.), but when I try to set the first field (actually, the user name on the logon screen..) I get an error 0x80010105 (RPC_E_SERVERFAULT). This is the VB.NET code I'm using....
Public Sub RunScript()
Dim ConnectionString As String = BuildConnectionString()
Dim app As GuiApplication
Dim mySession As GuiSession
Try
'Create object wrapper
Dim objWrapper = CreateObject("SapROTWr.SapROTWrapper")
'Get sap GUI using wrapper
Dim objRotSAPGUI = objWrapper.GetROTEntry("SAPGUI")
If IsNothing(objRotSAPGUI) Then
'New instance
app = CType(CreateObject("Sapgui.ScriptingCtrl.1"), GuiApplication)
Else
'running instance
app = CType(objRotSAPGUI.GetScriptingEngine(), GuiApplication)
End If
Dim Connection As GuiConnection = app.OpenConnection("ECC6 EHP7 SR2 on HANA", True)
mySession.FindById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-BNAME").text = "USER"
mySession.FindById("/app/con[0]/ses[0]/wnd[0]/usr/pwdRSYST-BCODE").text = "PASSWORD"
mySession.SendCommand("/0")
app = Nothing
Catch ex As Exception
End Try
End Sub
The procedure creates the error when trying to set the user (field txtRSYST-BNAME). Has anybody ever seen that before and solved the issue?
Some parameters from my machine: OS is Windows 10 Enterprise 64bit, dev environment is Visual Studio Enterprise 2015, :Net frame work used is 4.6, the application is compiled for 32 bit. SAP Logon is 7.40, no NWBC installed.
Thanks a lot and best regards,
Werner Buchner
Hello Werner,
I am no VB.NET expert but you don't set the variable mySession, e.g. like
mySession = Connection.Children(0)
So it is Null and the program crashes at the first point you use it.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan,
thanks for the fast reply. You are right, the code to retrieve session 0 from the connection is missing, but I just forgot to copy it to SCN. It's available in the application. This is the complete code:
Public Sub RunScript()
Dim ConnectionString As String = BuildConnectionString()
Dim app As GuiApplication
Dim mySession As GuiSession
Try
'Create object wrapper
Dim objWrapper = CreateObject("SapROTWr.SapROTWrapper")
'Get sap GUI using wrapper
Dim objRotSAPGUI = objWrapper.GetROTEntry("SAPGUI")
If IsNothing(objRotSAPGUI) Then
'New instance
app = CType(CreateObject("Sapgui.ScriptingCtrl.1"), GuiApplication)
Else
'running instance
app = CType(objRotSAPGUI.GetScriptingEngine(), GuiApplication)
End If
Dim Connection As GuiConnection = app.OpenConnection("ECC6 EHP7 SR2 on HANA", True)
mySession = CType(Connection.Sessions(0), GuiSession)
mySession.FindById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-BNAME").text = "USER"
mySession.FindById("/app/con[0]/ses[0]/wnd[0]/usr/pwdRSYST-BCODE").text = "PASSWORD"
mySession.SendCommand("/0")
app = Nothing
Catch ex As Exception
End Try
End Sub
Nevertheless, the issue persist.
Browsing OSS a little bit, I found a note for GUI 7.20, which describes the same issue. The note is http://service.sap.com/sap/support/notes/1525603. Could it be the error is back?
Another observation I has yesterday is that I can get the field (read it's values), but not set the text attribute. Maybe this helps to find the root cause.
Thanks a lot,
Werner
Hello Werner,
I tried it with SAP GUI 7.30 PL14 and Microsoft Visual Basic Compiler Version 11.0.50938.18408 as console application, your program works perfect.
'-Begin---------------------------------------------------------------
Imports System
Imports Interop.SAPFEWSELib
Module MyTestApp
Sub RunScript()
Dim app As GuiApplication
Dim mySession As GuiSession
Try
Dim objWrapper = CreateObject("SapROTWr.SapROTWrapper")
Dim objRotSAPGUI = objWrapper.GetROTEntry("SAPGUI")
If IsNothing(objRotSAPGUI) Then
app = CType(CreateObject("Sapgui.ScriptingCtrl.1"), GuiApplication)
Else
app = CType(objRotSAPGUI.GetScriptingEngine(), GuiApplication)
End If
Dim Connection As GuiConnection = app.OpenConnection("NSP", True)
mySession = CType(Connection.Sessions(0), GuiSession)
mySession.FindById("wnd[0]/usr/txtRSYST-BNAME").text = "BCUSER"
mySession.FindById("wnd[0]/usr/pwdRSYST-BCODE").text = "minisap"
mySession.SendCommand("/0")
app = Nothing
Catch ex As Exception
Console.WriteLine("Exception")
End Try
End Sub
Sub Main()
RunScript()
End Sub
End Module
'-End-----------------------------------------------------------------
I compiled it with
C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe /target:exe /out:Test.exe Test.vb /link:Interop.SAPFEWSELib.dll /platform:x86
on Microsoft .NET Framework 4.5.1.
Unfortunately I have no 7.40 SAP GUI available at the moment, but I will check it this evening and reply again.
Cheers
Stefan
Hi Stefan,
I tried with the same GUI/patch level yesterday, and on my environment it didn't work.
Being frustrated, I did a new recording of a script from SAPGUI, and got a big surprise.... even recording scripts on Windows 10 didn't work with GUI 7.40 PL5.... and executing a script I recorded earlier on a Windows 8.1 environment didn't work either. The GUI scripting engine failed giving me a message from Windows scripting host.
Summary: I think that SAP GUI scripting with Windows 1o has a massive issue...
Cheers,
Werner
Hello Werner,
based on your post I installed Windows 10 with SAP GUI 7.40 PL4 to try some tests. First of all I compiled your VB.NET program and it works absolut fine and perfect.
Also I test some script creations and I transfer the scripts to a Windows 7 environment with SAP GUI 7.40 PL5. I execute the scripts in the Windows 7 environment and all works fine without any problems.
I can not confirm your statement that the combination of Windows 10 and SAP GUI Scripting has massive problems. In my case I hava absolut no problems, all works well and as expected.
Cheers
Stefan
Hi Stefan,
some very good news over the weekend. I now can also confirm that GUI Scripting API works with Windows 10 (Enterprise 64bit, even with latest Microsoft patches to version 1511). Also the latest GUI (7.40 compilation 2) works on that OS.
Thanks a lot for your tremendous support the last week.
All the best,
Werner Buchner
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.