on 11-01-2013 7:26 PM
Hi Community,
I noticed from this forum that there are several methods of calling the SAP objects in scripts e.g. SAP.Functions, SAP.ScriptingCtrl.1, GetScriptingEngine etc.
Is there any reference document on the differences between these methods e.g. when we should use it, which one is better for what purpose etc?
Just curious...
Thanks,
Sayuti
Hello Sayuti,
SAP.ScriptingCtrl.1 is the program ID (ProgID) of the SAP GUI Scripting API.
If you create an instance like this
Set application = CreateObject("SAP.ScriptingCtrl.1")
you can use the SAP GUI Scripting API inside your program.
SAP.Function is the ProgID of the SAP Remote Function Call Control library. This has nothing to do with the SAP GUI Scripting API. This is a part of the ActiveX libraries to connect SAP via COM.
GetScriptingEngine is a method of the class GuiApplication from the SAP GUI Scripting API. It delivers an IDispatch interface to an instance of a running SAP GUI process.
Hope my explanations help to understand the difference.
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Stefan for the explanation.
If I get this right:
The SAP.ScriptingCtrl.1 is when we want to create and connect while GetScriptingEngine is a method to point and connect.
Are both from the same SAPFEWSELib?
For SAP.ScriptingCtrl.1
- Does not require saplogon to be running 1st for the script to run..
- Is it faster?
- Does the session created using it destroyed once script finish executing?
- If there is already a running session, can we connect to the same session?
BTW, since SAP.Function is for RFC and not for SAPGUI, not applicable to me at the moment.
Thanks,
Sayuti
Hello Sayuti,
you can use this way for a new connection:
'-Variables--------------------------------------------------------
Dim App As SAPFEWSELib.GuiApplication
Dim Con As SAPFEWSELib.GuiConnection
'-For a new connect-----------------------------------------------
Set App = CreateObject("Sapgui.ScriptingCtrl.1")
'----------------------------------------------------------------
'-
'- Connection parameter
'- /H/ and the IP address of the target system
'- /S/ 32 + the system number, in this case 00
'-
'----------------------------------------------------------------
Set Con = App.OpenConnectionByConnectionString( _
"/H/10.100.100.100/S/3200", True, False)
or this way for an existing connection:
'-Variables--------------------------------------------------------
Dim Obj As Object
Dim App As SAPFEWSELib.GuiApplication
Dim Con As SAPFEWSELib.GuiConnection
'-For an existing connect------------------------------------------
Set Obj = GetObject("SAPGUI")
Set App = Obj.GetScriptingEngine
Set Con = App.Children(0)
You see, both are part of the SAPFEWSELib.
To your questions:
Good luck and let us know your results.
Cheers
Stefan
Hello Sayuti,
as far as I know it is not necessary to have a running process of saplogon.exe, if you use OpenConnectionByConnectionString as the example above (or OpenConnection). But I am not really sure, because I have used this procedure only once for error Analysis.
Let us know the results, it is very interesting.
Thanks and cheers
Stefan
Dear Stefan,
I've tested both methods using the following:
Option Explicit
Const sapServer As String = "sap.msg.server.address"
Const sapID As String = "mySAPID"
Const sapPassword As String = "******"
Dim sap As SAPFEWSELib.GuiApplication
Dim sapCon As SAPFEWSELib.GuiConnection
Dim sapSession As SAPFEWSELib.GuiSession
Sub testMethod1()
Set sap = CreateObject("SAPGUI.Scriptingctrl.1")
Set sapCon = sap.OpenConnectionByConnectionString(sapServer, True)
Call loginInfo
End Sub
Sub testMethod2()
Set sap = GetObject("SAPGUI").GetScriptingEngine
Set sapCon = sap.OpenConnectionByConnectionString(sapServer, True)
Call loginInfo
End Sub
Sub loginInfo()
Set sapSession = sapCon.Children(0)
With sapSession
.FindById("wnd[0]/usr/txtRSYST-MANDT").Text = "200"
.FindById("wnd[0]/usr/txtRSYST-BNAME").Text = sapID
.FindById("wnd[0]/usr/pwdRSYST-BCODE").Text = sapPassword
.FindById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
.FindById("wnd[0]").SendVKey 0
End With
End Sub
Sub killSAP()
Set sapSession = Nothing
Set sapCon = Nothing
Set sap = Nothing
End Sub
----------------------------------------
My findings are:
For Method1:
While typing the killSAP procedure, I mistakenly put the order of object variables from sap to sapSession instead of the other way around as per above. This caused the script and Excel to be 'hanging' until I have to force-close it in Task Manager. Ctrl + Break didn't seem to work in the VBE and Task Manager shows Excel is running (not actually 'not responding').
For Method2:
Based on the above, I'm sticking with Method2 with a Shell command to execute saplogon if it is not already running.
Thanks,
Sayuti
Dear Sayuti, Stefan,
I just reading your post and your testmethode2, i'm quite intrusting to get the new version.
I try it and unfortunately, i getting an error into excel. the saplon is lauched but the application is in idle mode, until i get an error.
Is it possible to share how you do this type of connection with more details ?
Many thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Samir,
What is the error did you get from Excel?
I'm not sure how to be more detailed than I already have. The procedure is pretty straightforward.
First you need to do 'early-binding' to sapfewse.ocx. has written how to do it here: http://scn.sap.com/thread/2102571
If this does not solve the issue, perhaps, the version of software is different. I used Excel 2010 running on Windows 7 and saplogon 720.
Also, is scripting support enabled by your server?
Thanks,
Sayuti
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.