cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Logon to SAP System using SAPGUI Scripting

Former Member
0 Likes
8,881

I am able to record, run and understand the SAPGUI Script when I am already loggedon the SAP System. Could anyone help me or provide me an example where I can code the script to open a session and logon to SAP system (Using SAP Logon) and than execute the recorded transaction.

Thanks in advance.

_M

View Entire Topic
Former Member
0 Likes

Thanks Ben and Jonathan for responding. I am still struggling with the openConnection method. Any example would help. If you happen to open SAPR/3 Session from scratch using this method and logon also, please provide some more information.

So far, thanks for the help.

_Manoj

Christian_Cohrs1
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Manojy,

below is a sample script. The first parameter is a description text from the SAPLogon dialog, the second sets the syncronous mode for OpenConnection. This means that the call will only return when a connection has been successfully made or the attempt has failed.

The last three line set username and password, which you only need to do if you do not have Single Sign On.

This example assumes that you already have saplogon.exe running. If this is not the case, than you can create a SAP GUI instance by calling

Set application = CreateObject("Sapgui.ScriptingCtrl.1")

Best regards,

Christian

Set SapGui = GetObject("SAPGUI")

Set application = SapGui.GetScriptingEngine

Set connection = application.OpenConnection("XYZ [PUBLIC]", True)

Set Session = connection.children(0)

session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "MyUsername"

session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "MyPassword"

session.findById("wnd[0]").sendVKey 0

Former Member
0 Likes

Hi Christian,

I try to launch SAPGUI with a script. However the script block on below code lines

<<Set SapGui = GetObject("SAPGUI")>>

<<Set application = SapGui.GetScriptingEngine>>

and display the error message <<The enumerator of collection cannot find an element with the specified index.>>

Do you know what is the issue and how to by-pass it? I have written several scripts and I always get the same message.

Thanks & Best Regards

Francois,

Christian_Cohrs1
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Francois,

this sounds like the scripting profile parameter is not set. You can check this in transaction rz11, if you check the value of sapgui/user_scripting. This must be set to TRUE.

Best regards,

Christian

Former Member
0 Likes

Hi,

I am searching for a way to login through SAP GUI. This post seemed like an answer to my question.

I noticed you are using a session object to enter a username and password.

I was attempting a similar way of logging in with the difference being that I open a connection using the SAP GUI. My understanding is that opening a connection using SAP GUI is the same as OpenConnection call in the script. Then I attempt to enumerate sessions using scripting.

The problem I am facing is that I get zero sessions. Since there does not appear to be a way to get to user controls without a session, how can I enter username and password? Why is there zero sessions?

Thank you,

Michael.

Former Member
0 Likes

I've tried using a VB script and even after logging in I get an error when trying to access sessions.

connection.Children(0) displays and error saying that is cannot find the index in the collection.

Former Member
0 Likes

The reason there were no sessions was because scripting was disabled on the server.