cancel
Showing results for 
Search instead for 
Did you mean: 

vbs enter tcode in 2 sessions

Former Member
0 Kudos

Hi, I know pretty much nothing about scripts, but hopefully you guys can help me. I got this code: If Not IsObject(application) Then    Set SapGuiAuto  = GetObject("SAPGUI")    Set application = SapGuiAuto.GetScriptingEngine End If 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 session.findById("wnd[0]").maximize session.findById("wnd[0]/tbar[0]/okcd").text = "se16n" session.findById("wnd[0]").sendVKey 0 session.createSession What I want to do now is do the same thing in the new session I created at the end.

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor
0 Kudos

Hello Isac,

welcome in the Scripting Languag forum.

You can try this:

'-Begin-----------------------------------------------------------------

  If Not IsObject(application) Then

    Set SapGuiAuto = GetObject("SAPGUI")

    Set application = SapGuiAuto.GetScriptingEngine

  End If

  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

  session.findById("wnd[0]/tbar[0]/okcd").text = "/ose16n"

  session.findById("wnd[0]").sendVKey 0

'-End-------------------------------------------------------------------

All you have to do is to set a /o in front of your transaction code. With this prefix you create a new mode. As far as I know it is not possible to set the session number of a new mode, the SAP GUI for Windows allocates the next free number automatically.

If you want to know your session number you can try the following snippet:

    For cntSession = 0 To connection.Children.count - 1

      Set mySession = connection.Children(CInt(cntSession))

      If mySession.Info.Transaction = "SE16N" Then

        mySessionNo = mySession.Info.SessionNumber

        Exit For

      End If

    Next

    MsgBox mySessionNo

It scans all open sessions and find the first session with the transaction code SE16N.

If you want to know definitely your new session number, scan all sessions before you start your transaction code, do the same after and compare the results.

Let us know your results.

Cheers

Stefan

Answers (0)