'-Begin-----------------------------------------------------------------
'-
'- Example to show how to select a specific session to do SAP GUI
'- Scripting activities inside it. It scans all connections with all
'- sessions to find the correct one.
'-
'- Author: Stefan Schnell
'-
'-----------------------------------------------------------------------
'-Directives------------------------------------------------------------
Option Explicit
'-Sub Action------------------------------------------------------------
'-
'- Get the selected session and do the action inside it
'-
'-----------------------------------------------------------------------
Sub Action(session)
'Insert your SAP GUI Scripting code from recorder here
MsgBox session.findById("wnd[0]/titl").text
End Sub
'-Function GetSession---------------------------------------------------
'-
'- Detects the session
'-
'-----------------------------------------------------------------------
Function GetSession(SID, TAC)
Dim SapGuiAuto, application, connections, connection, sessions
Dim session, sessionInfo, j, i
Set SapGuiAuto = GetObject("SAPGUI")
If Not IsObject(SapGuiAuto) Then
Exit Function
End If
Set application = SapGuiAuto.GetScriptingEngine
If Not IsObject(application) Then
Set SapGuiAuto = Nothing
Exit Function
End If
Set connections = application.Connections()
If Not IsObject(connections) Then
Set SapGuiAuto = Nothing
Set application = Nothing
Exit Function
End If
'-Loop over connections-----------------------------------------------
For Each connection In connections
Set sessions = connection.Sessions()
'-Loop over sessions------------------------------------------------
For Each session In sessions
If session.Busy() = vbFalse Then
'---------------------------------------------------------------
'-
'- With the session info object is it possible to select a
'- specific session which executes the activities. In our
'- example it is the system name and the transaction code, but
'- you can use all properties of the session info object.
'-
'---------------------------------------------------------------
Set sessionInfo = session.Info()
If sessionInfo.SystemName() = SID And _
sessionInfo.Transaction() = TAC Then
Set GetSession = session
End If
End If
Next
Next
End Function
'-Sub Main--------------------------------------------------------------
'-
'- Main procedure to select the session
'-
'-----------------------------------------------------------------------
Sub Main()
Dim session
Set session = GetSession("NSP", "SE80")
Action session
End Sub
'-Main------------------------------------------------------------------
Main()
'-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |