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

Activate a session via Gui scripting

Former Member
0 Likes
10,105

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

View Entire Topic
Former Member
0 Likes

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