on 08-25-2009 4:36 PM
Hello,
I'm trying to figure out SAP GUI Scripting in VBA (MS Excel) and I compare it to other SAP connection options, e.g. "SAP.Functions".
In SAP GUI scripting, I've seen a couple of connection options such as:
If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("My_SystemName", True)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = MyClient
Session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = MyUserID
Session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = MyPassword
Session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = MyLanguage
Session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus
Session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2
Session.findById("wnd[0]").sendVKey 0
......
For RFC calls with "SAP.Functions", you can start with:
Set LogonControl = CreateObject("SAP.LogonControl.1")
Set FuncControl = CreateObject("SAP.Functions")
Set Conn = LogonControl.NewConnection
Conn.Client = MyClient
Conn.Language = MyLanguage
Conn.user = MyUserID
RetCode = Conn.Logon(0, False)
.....
The instruction Conn.Logon(0, False) start a logon dialog where you can chose your system and once this is done, you're prompted for your logon credentials.
My question is "simple". In SAP GUI Scripting, is there an instruction (or set of instructions) to trigger a dialog similar to Conn.Logon(0, False)?
Thanks!
Hi Jean-Michel,
You start just a link that has been prepared beforehand. There is a suggestion of mine in this forum:
There is also a contribution from me in a German forum::
http://www.dv-treff.de/sap-community/default.aspx?g=posts&t=4427
Regards,
ScriptMan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Scriptman,
Thanks for taking the time to contribute.
I'm afraid I did not make myself clear enough in my initial request.
The links that you provided seem to discuss how to create multiple sessions, how to end them and how to switch between them.
I just want to create one session in a to-be selected system and run a task there.
If you want to perform a task manually in SAP, you start SAP Logon, select the system, click Log On, the SAPgui starts, you maintain your logon info, you run your transaction and you log off.
My objective is to write a VBA macro in MS excel to perform a certain task and I want the user to be able to select the system where he'll want to run that transacton.
The idea is that the user should maintain in the MS Excel spreadsheet the information to support the task and then click a button to start the macro. The macro should present the list of systems as listed in SAP Logon, the user should select the system, the macro should request the logon information (client, User, pwd, language) and perform the task automatically from there.
The third line below brings up a dialog to select the system and follows up with another dialog to get the logon credentials. There is no need to program these dialogs and manage any of that stuff.
Set LogonControl = CreateObject("SAP.LogonControl.1")
Set Conn = LogonControl.NewConnection
RetCode = Conn.Logon(0, False)
Is there something similar that I can use with SAP GUI Scripting?
Or is the obvious answer to run exactly the code I have with the SAP Logon Control to catch all that system and login information and feed it into the standard SAP GUI Scripting code (also part of my original post) ?
Hi experts,
sorry for warming up this old thread, put I´m experiencing some 'strange' behaviour when executing this script for logging on a user.
I see the SAP GUI opens, I can see the logon screen for a 1/10 second and then the GUI disappears. Tests with SAP GUI 7.10 PL 19 and SAP GUI 7.20 PL 5.
I searched the internet for almost 2 days and didn´t find any useful tip concerning this behavior.
Thanks in advance for any help
Kind regards
Matthew
Hi ScriptMan,
basiclly I´m using the script given in this post, but I tried other similar attempts as well. I think I even tried some code provided by you in other posts as well.
If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("Entwicklungssystem", True)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "100"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "user"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "pass"
Session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "DE"
Session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus
Session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2
session.findById("wnd[0]").sendVKey 0
Scripting is enabled on server side. The Scripting API seems to work in general. I´m possible to access the API properties e.g. concerning currently opened SAP modes and so on.
Kind regards
Matthew
Hi Matthew,
the new instance of the GuiApplication created with the scripting component is not part of the SAPlogon process but rather of the process executing the script, so all connections are closed at the end of the script.
You can try it by installing of a MsgBox at the end of your script.
. . .
session.findById("wnd[0]").sendVKey 0
msgbox "When you click OK, the current session ends."
. . .
Regards,
ScriptMan
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.