cancel
Showing results for 
Search instead for 
Did you mean: 

Easy Logon dialog/process in SAP GUI Scripting with VBA?

Former Member
0 Kudos

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!

Accepted Solutions (0)

Answers (1)

Answers (1)

script_man
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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) ?

Former Member
0 Kudos

FYI,

I just checked the instruction Conn.Logon(0, False).

It's almost perfect. It would allow me to get all the information, except the password that is apparently crypted. I don't think that asking the user for his/her password twice will be acceptable.

script_man
Active Contributor
0 Kudos

Hi Jean-Michel,

I don't know of another opportunity in the SAP GUI Scripting. Why don't you use the RFC functionality within SAP GUI scripting?

Regards,

ScriptMan

Edited by: ScriptMan on Aug 30, 2009 9:41 AM

Former Member
0 Kudos

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

script_man
Active Contributor
0 Kudos

Hi Matthew,

what is the script that you use?

Regards,

ScriptMan

Former Member
0 Kudos

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

script_man
Active Contributor
0 Kudos

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

Former Member
0 Kudos

This message was moderated.