cancel
Showing results for 
Search instead for 
Did you mean: 

Logon to SAP System using SAPGUI Scripting

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (5)

Answers (5)

former_member709020
Participant
0 Kudos

I've been pretty successful doing this with an Excel macro to run various transactions.  Is this what you had in mind?

Former Member
0 Kudos

Hi Christian,

Your code works very well with Visual Basic 6. Do you know how it should looks like for VB.NET? VB.NET doesn’t accept fourth line:

Set Session = connection.children(0)

Former Member
0 Kudos

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_Cohrs
Product and Topic Expert
Product and Topic Expert
0 Kudos

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 Kudos

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_Cohrs
Product and Topic Expert
Product and Topic Expert
0 Kudos

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 Kudos

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 Kudos

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 Kudos

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

Former Member
0 Kudos

The openConnection() method of the GuiApplication object will start a system "from scratch". You pass the name of an entry from your SAP Logon to it.

Former Member
0 Kudos

I do not think it is possible to use eCATT SAPGUI to actually open the SAP logon pad and launch a new session, however, if you want to test roles and security you can use RFCs to logon to a specified system with a username and password. There are other ways to test the login process but it really depends on what aspect of the system you are trying to test.