on ‎2009 Feb 06 2:14 PM
Hi,
how to activate an active SAP-session via Gui Scripting or maybe a workaround?
There are some SAP sessions running and I want to activate a certain one of them.
I tried to activate a session with:
AppActivate session.findById("wnd[0]").Text
but, as we know, if there are the same task names in Task Manager, the function will start any one of them.
Any idea?
Edited by: Stefan Benkö on Feb 9, 2009 7:07 AM
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
You could count the SAP connectionsans sessions, then select one to activate using a form.
I have had sucess populating an array with the connections and sessions, then using that array to build a form for the user to select the connection and session. Then use the user's selection to set the connection and session objects.
Or you could display all connections and sessions and a dialog box, and have the user specify the connection and session.
You will need to subtract 1 from the result to convert to base 0. For example, if this shows that you have 1 connection, then subtract 1, and set your connection to 0. Example: "Set connection = application.Children(0)"
Here is an example in VBS, similar to a recorded script. I use Excel VBA to build the form rather than VBS.
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
'
iConnections = application.Connections.Count
msgbox iConnections & " Connections"
'
iSessions = application.Connections.Item(0).Sessions.Count
msgbox isessions & " Sessions"
'
sSAP_Session = Application.Connections.Item(0).Sessions.Item(0).Info.Transaction
'
msgbox sSAP_Session & " 1st session"
'
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.