on 06-18-2013 2:03 AM
I have a need to "walk" my way through the SAP Logon 720 logon pad with VBScript techniques. Is this possible using the same methods used when navigating the SAP GUI during a session? What I'd like to do when the logon pad is visible is select a particular connection, click the Edit button, click the Network tab, and then select either the High Speed or Low Speed options under Network Setttings. I've recorded my steps while performing transactions during a session with the script recorder (I understand and can code this script pretty well) and would like to do the same while in the Logon pad. If the recorder isn't available for recording while in the Logon Pad, where I can I find documentation to understand how to apply VBScript to accomplish what I need?
Hello
I've encountered the same needs than you.
I've solved it by creating 2 entries for the same SAP machine in the SAPLogon, one for the slow connection and one for the fast connection.
My scripts directly call the correct connection.
Indeed, most of my scripts are now developped in fast connection mode.
I find it much more useful when you need to debug your script and interact manually with sap.
Cheers.
Fabrice.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabrice,
That's a solution that may work. I have incorporated two logon scripts into Excel for getting the user to the desired SAP transaction: one for when they're already logged onto the GUI and one for when they're not. I know how to tell the code to open a specific connection, using your suggestion, one for the slow connection and one for the fast, but I don't know how to detect which connection the user logged on with when I use the "already logged on" script.
Here is the code I use:
Sub SAP_Logon()
If bSSO = False Then 'used when the user is already logged on to the SAP GUI
Dim SAPGUIAuto As Object
Set SAPGUIAuto = GetObject("SAPGUI")
Set SapGuiApp = SAPGUIAuto.GetScriptingEngine
Set SapGuiConn = SapGuiApp.Children(0)
Set session = SapGuiConn.Children(0)
Else 'used when the user in NOT already logged on to the SAP GUI
Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
Set SapGuiConn = SapGuiApp.OpenConnection("ECC Production", True)
Set session = SapGuiConn.Children(0)
session.TestToolMode = 1
'added part to deal with sap status (open/close)
Set log_opt = session.FindById("wnd[1]/usr/radMULTI_LOGON_OPT2", False)
If Not log_opt Is Nothing Then
log_opt.Select
session.FindById("wnd[1]/tbar[0]/btn[0]").Press
End If
End If
Exit Sub
Hello
Several solutions
All users should have 'Fast connection set', i set it each time i install a script on a pc.
or
One other solution can be to always open a new SAP even if there is already one open.
Then you can choose to always use the SAP with fast connection option.
In this case you have to manage the screen 'User already logged on'
Here is the code
If session.Children.Count > 1 Then
session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").Select
session.findById("wnd[1]/tbar[0]/btn[0]").press
End If
or
you can browse the 'Opened SAP' and check their names, we work with several SAP at the same time and we have sometimes the case.
Here is the code i use to check if one of the opened SAP is the one i want (sapname variable contains the name if the requested sap)
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
For ind_sap = 0 To (Application.Children.Count - 1)
If (Application.Children(0 + ind_sap).Description = sapname) Then
connection_sap = True
Exit For
End If
Next
Hope it will help.
Thanks, Fabrice,
That was very helpful. Do you know of a way to detect if the logon pad is activated or not? If the logon pad isn't activated, and you try
Set SAPGUIAuto = GetObject("SAPGUI")
you get a -2147221020 Automation Error. I've been having the user select a radio button on a user form to indicate if they're already logged on or not and trapping this error to tell them they must be logged on to use the "I'm already logged on" option if they try to logon using this option when they're really not.
It would be nice to know if the logon pad was already activated or not. Then I wouldn't need the option frame on the user form and could have the script detect if it was activated or not. Once the code knew that the logon pad was activated, then I could use the code you suggested to detect the proper connection. If the logon pad wasn't activated, then I could just have the code start a new logon and connection.
I was able to detect if the logon pad was active using code referencing WMI by querying Task Manager. I don't really like referencing WMI in code because it's (WMI) easily corrupted without the user knowing it. At any rate, here is the revised code that utiliizes your suggestion to detect the connection description. If you know of another way to detect if the logon pad is active, please let me know.
Sub SAP_Logon()
Dim strCheckThis As String 'The variable to hold the saplogon.exe process
Dim strECC As String 'varible to hold ECC Production connection
Dim objWMIcimv2 As Object, objList As Object, SAPGUIAuto As Object
Dim intGUI As Integer
Dim bECC As Boolean
strCheckThis = "saplogon.exe" 'checks to see if Sap logon pad is present in Task Manager
strECC = "ECC Production"
bECC = False
Set objWMIcimv2 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2") 'Connect to CIMV2 Namespace
Set objList = objWMIcimv2.ExecQuery _
("select * from win32_process where name='" & strCheckThis & "'") 'Find the process to terminate
If objList.Count > 0 Then
Set SAPGUIAuto = GetObject("SAPGUI")
Set SapGuiApp = SAPGUIAuto.GetScriptingEngine
If SapGuiApp.Children.Count = 0 Then
MsgBox "You must be logged on to ECC Production when the SAP Logon pad is activated. Please " & _
"logon to ECC Production and try again.", vbInformation, "ECC Production Logon Warning"
bErrSAP = True
Exit Sub
Else
For intGUI = 0 To (SapGuiApp.Children.Count - 1)
If (SapGuiApp.Children(0 + intGUI).Description = strECC) Then
bECC = True
Exit For
Else
MsgBox "You're connected to " & SapGuiApp.Children(0 + intGUI).Description & ". You must be " & _
"connected to ECC Production"
Set objWMIcimv2 = Nothing
Set objList = Nothing
Exit Sub
End If
Next
End If
Set SapGuiConn = SapGuiApp.Children(0)
Set session = SapGuiConn.Children(0)
Set objWMIcimv2 = Nothing
Set objList = Nothing
Else
Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
Set SapGuiConn = SapGuiApp.OpenConnection("ECC Production", True)
Excel.Application.Visible = True
Application.ScreenUpdating = True
Set session = SapGuiConn.Children(0)
session.TestToolMode = 1
'added part to deal with sap status (open/close)
Set log_opt = session.FindById("wnd[1]/usr/radMULTI_LOGON_OPT2", False)
If Not log_opt Is Nothing Then
log_opt.Select
session.FindById("wnd[1]/tbar[0]/btn[0]").Press
End If
Set objWMIcimv2 = Nothing
Set objList = Nothing
End If
Exit Sub
Hello Garry,
Sorry for the late answer. I was on holiday.
Thank you for the information regarding the WMI option.
I made a test with the following code.
If the saplogon is not active, the error is caught and then i launch the saplogon via "sapstart" command.
It works for me.
Hope it will help you.
If Not IsObject(Application) Then
On Error GoTo AutomationErr
Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
GoTo next:
AutomationErr:
Path = "C:\Program Files (x86)\SAP\SapSetup\setup\SapStart.exe " + "/sal=" + Chr(34) + "C:\Program Files (x86)\SAP\SapSetup\setup\SAL\SapLogon.s8l" + Chr(34)
shell Path
next:
End If
Thanks again. I tried your code and found that it works fine if I don't use Option Explicit in my Excel VBA code and also don't DIM the Application object. Since I'm using Excel VBA, I actually can't use the reserved word "Application" so I'm using "SapGuiApp" instead as the variable. I suppose you actually tested your code in VBScript instead of Excel VBA, correct? I'm going to have to experiment a little to see if I can perhaps temporarily set the SapGuiApp object to Nothing before checking to see of the logon pad is open. What are your thoughts?
Here's the complete logon code. If I DIM the SAPGuiApp object at the top, the code doesn't recognize it as Nothing. The reason I'm so hell bent and bound to use Option Explicit and DIM the variable is because I actually need to Public the variable so I can use it with several Modules that use the SAP_Logon procedure.
Sub SAP_Logon()
Dim strECC As String 'varible to hold ECC Production connection
Dim intGUI As Integer
strECC = "ECC Production"
On Error GoTo AutomationErr
If Not IsObject(SapGuiApp) Then
Set SAPGUIAuto = GetObject("SAPGUI")
Set SapGuiApp = SAPGUIAuto.GetScriptingEngine
If SapGuiApp.Children.Count = 0 Then
MsgBox "You must be logged on to ECC Production when the SAP Logon pad is activated. Please " & _
"logon to ECC Production and try again.", vbInformation, "ECC Production Logon Warning"
bErrSAP = True
Exit Sub
Else
For intGUI = 0 To (SapGuiApp.Children.Count - 1)
If (SapGuiApp.Children(0 + intGUI).Description = strECC) Then
Exit For
Else
MsgBox "You're connected to " & SapGuiApp.Children(0 + intGUI).Description & ". You must be " & _
"connected to ECC Production"
Exit Sub
End If
Next
End If
Set SapGuiConn = SapGuiApp.Children(0)
Set session = SapGuiConn.Children(0)
Excel.Application.Visible = True
Application.ScreenUpdating = True
End If
Exit Sub
AutomationErr:
Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
Set SapGuiConn = SapGuiApp.OpenConnection("ECC Production", True)
Excel.Application.Visible = True
Application.ScreenUpdating = True
Set session = SapGuiConn.Children(0)
Excel.Application.Visible = True
Application.ScreenUpdating = True
session.TestToolMode = 1
'added part to deal with sap status (open/close)
Set log_opt = session.FindById("wnd[1]/usr/radMULTI_LOGON_OPT2", False)
If Not log_opt Is Nothing Then
log_opt.Select
session.FindById("wnd[1]/tbar[0]/btn[0]").Press
End If
End Sub
Hello Gary,
as far as I know is SAP Logon not a part of the SAP GUI Scripting API, so it is not possible to manipulate it via SAP GUI Scripting.
But it is very easy possible to use AutoIt scripting to do that. Use the AutoIt recorder, which is part of the installation, and use with priority the keys and key combinations for your activity. So you get an AutoIt script, which you can combine with SAP GUI Scripting if you want, and you can compile it to an executable.
You can do the same with VBScript and the SendKeys method. Here you can use the AutoIt recorder too, to catch the keystrokes. Start your script after choosing a system.
Here as example the AutoIt script recording:
_WinWaitActivate("SAP Logon 730","")
Send("{ALTDOWN}{ENTER}{ALTUP}")
_WinWaitActivate("System Entry Properties","")
Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{RIGHT}{TAB}{TAB}{SPACE}{ENTER}")
Here In VBScript, but not checked:
AppActivate "SAP Logon 730"
SendKeys "%{ENTER}"
WScript.Sleep 250
AppActivate "System Entry Properties"
SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{RIGHT}{TAB}{TAB} {ENTER}"
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,
I actually have Autoit installed on my machine but haven't tried using the recorder. I'm not even sure if it has that feature in it. I have v3.3.8.1. Does the recorder come with all versions? When I do a search in the help file using "recorder" as key word, nothing comes up.
I do have a couple of questions regarding Autoit.
Hello Gary,
you are right, there is no documentation of AutoIt recorder in the help file.
Well, start the program Au3Record.exe and you can use the recorder, it is very easy. As far as I know it is a standard part of AutoIt and shall be available on all versions.
You can integrate AutoIt scripts on several ways into Excel VBA:
Hope it helps, let us know.
Cheers
Stefan
Thanks again, Stefan,
I finally found how to get the recorder going. I had to install the SciTE4AutoIt3 program that works with Autoit.
I ran into a couple of road blocks trying to write a script to manipulate the SAP logon pad; one of which is caused by using a Windows 7 machine.
Do you have any information on the issues?
Regards,
Gary Michalske
Hello Gary,
to your first point:
Sorry, but I don't have the slightest idea. Hope that someone else can help.
To your second point:
Look at http://blog.stschnell.de/, look at Tips for AutoIt and here at Start SAP LogonPad and GUI, Login and start Object Navigator. You find a complete source to start SAP logon, select a system entry, start SAP GUI and open the object navigator. It is from Feb. 2009, so it is necessary to actualize the window title and path to the programs. But it should work.
Let us know the results.
Cheers
Stefan
User | Count |
---|---|
78 | |
9 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.