Skip to Content
Author's profile photo Former Member

Recorded Script in SAP to open more than the first session.

Hi I am totally new to SAP. So please bear with me and my missing skills. I have tried to record a session to log into SAP. And open the first session i need.

It works good. But i normally work with more than one session. I tried to record this but it only create 2 new sessions. Below is my recorded script.

I need to open 2 more with the name fbl5n and udm_bp. My script below open the first session and then it just create 2 blank sessions.

Please try help with this. I have of course in below script removed my password.

Sincerely

Abjac

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]/usr/txtRSYST-BNAME”).text = “Y99DEW838”

session.findById(“wnd[0]/usr/pwdRSYST-BCODE”).text = “***********”

session.findById(“wnd[0]/usr/pwdRSYST-BCODE”).setFocus

session.findById(“wnd[0]/usr/pwdRSYST-BCODE”).caretPosition = 11

session.findById(“wnd[0]”).sendVKey 0

session.findById(“wnd[0]/tbar[0]/okcd”).text = “/n/hoag/akon “

session.findById(“wnd[0]/tbar[0]/btn[0]”).press

session.findById(“wnd[0]/tbar[1]/btn[17]”).press

session.findById(“wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell”).selectedRows = “0”

session.findById(“wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell”).doubleClickCurrentCell

session.findById(“wnd[0]/tbar[1]/btn[8]”).press

session.createSession

session.createSession

Assigned tags

      34 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Ab,

      welcome in the Scripting Language forum.

      You can try this to add more sessions with your transaction codes:

      ...
      session.findById("wnd[0]/tbar[1]/btn[8]").press
      session.createSession 'Session 2
      session.createSession 'Session 3
      'add the following code to your script
      session.createSession 'Session 4
      WScript.Sleep 1000
      Set session4 = connection.Children(3)
      session4.findById("wnd[0]/tbar[0]/okcd").text = "/nfbl5n"
      session4.findById("wnd[0]").sendVKey 0
      session.createSession 'Session 5
      WScript.Sleep 1000
      Set session5 = connection.Children(4)
      session5.findById("wnd[0]/tbar[0]/okcd").text = "/nudm_bp"
      session5.findById("wnd[0]").sendVKey 0
      


      Let us know your results.


      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan and thanks for your answer. I tried your code but it always give me a cannot be found by id and the code stop. I have tried allot to change the id. But it seems not be working.

      If i run the codes separately it works . Below you can see the 3 codes.

      code for fbl5n.

      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]/usr/txtRSYST-BNAME").text = "Y99DEW838"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "***********"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").setFocus

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 11

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

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

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

      session.findById("wnd[0]/usr/chkX_SHBV").selected = true

      session.findById("wnd[0]/usr/chkX_MERK").selected = true

      session.findById("wnd[0]/usr/chkX_PARK").selected = true

      session.findById("wnd[0]/usr/ctxtPA_STIDA").text = ""

      session.findById("wnd[0]/usr/chkX_PARK").setFocus

      Code for udm_bp

      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]/usr/txtRSYST-BNAME").text = "Y99DEW838"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "***********"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").setFocus

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 11

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

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

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

      Code for /n/hoag/akon

      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]/usr/txtRSYST-BNAME").text = "Y99DEW838"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "***********"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").setFocus

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 11

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

      session.findById("wnd[0]/tbar[0]/okcd").text = "/n/hoag/akon "

      session.findById("wnd[0]/tbar[0]/btn[0]").press

      session.findById("wnd[0]/tbar[1]/btn[17]").press

      session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "0"

      session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell

      session.findById("wnd[0]/tbar[1]/btn[8]").press

      session.createSession

      session.createSession

      The all run and work if i do them individual but to open them in one,. I cant make that work.

      I go BH.

      ScreenHunter_121 Oct. 23 13.10.jpg

      And then i come double click YPE.

      ScreenHunter_122 Oct. 23 13.10.jpg

      And i come to this screen from where i run my script.

      ScreenHunter_123 Oct. 23 13.10.jpg

      The menu for this screen looks like this but of course with the script i dont touch that but i guess it show the names for the ids.

      ScreenHunter_124 Oct. 23 13.11.jpg

      I would actually love to be able to run a script from scratch so it find the screen and log me in in the 3 sessions. Also that i have tried but reading here. But in this case i cant get me from the YPE. Again it cant find that id.

      But please have a look if it possible to put these 3 codes together.

      Thanks

      Abjac

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Ab,

      please try this to solve your requirement:

      '-Begin-----------------------------------------------------------------
      
        '-Directives----------------------------------------------------------
          Option Explicit
      
        '-Global Variables----------------------------------------------------
          Dim SapGuiAuto, application, connection, Waiting
          Dim session1, session2, session3
      
        '-Sub CreateSession---------------------------------------------------
          Sub onCreateSession(ByVal Session)
            Waiting = 0
          End Sub
      
        '-Main----------------------------------------------------------------
          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(session1) Then
            Set session1 = connection.Children(0)
          End If
      
          If IsObject(WScript) Then
            WScript.ConnectObject application, "on"
          End If
      
          session.findById("wnd[0]").maximize
          session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "Y99DEW838"
          session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "***********"
          session.findById("wnd[0]").sendVKey 0
      
          Waiting = 1
          session1.createSession
          Do While (Waiting = 1)
            WScript.Sleep 100
          Loop 
      
          If Not IsObject(session2) Then
            Set session2 = connection.Children(1)
          End If
      
          Waiting = 1
          session1.createSession
          Do While (Waiting = 1)
            WScript.Sleep 100
          Loop 
      
          If Not IsObject(session3) Then
            Set session3 = connection.Children(2)
          End If
      
          session1.findById("wnd[0]/tbar[0]/okcd").text = "/n/hoag/akon"
          session1.findById("wnd[0]").sendVKey 0
          session2.findById("wnd[0]/tbar[0]/okcd").text = "/nfbl5n"
          session2.findById("wnd[0]").sendVKey 0
          session3.findById("wnd[0]/tbar[0]/okcd").text = "/nudm_bp"
          session3.findById("wnd[0]").sendVKey 0
      
      '-End-------------------------------------------------------------------

      Let us know your results.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Stefan and thanks for your answer.

      I get below boxes pop up and also below error in the end.

      ScreenHunter_125 Oct. 23 17.04.jpg

      Which means a script is trying to join SAP gui.

      Of course would be nice it pop up 2 times so not to have it.

      And finally i get this error. 

      ScreenHunter_126 Oct. 23 17.04.jpg

      Which i think its weird its the same as when i run one by one.,

      Have a look please .

      Sincerely

      Abjac

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Ab,

      disable the notify checkboxes in your SAP Logon:

      /wp-content/uploads/2015/10/001_816731.jpg

      Start the script with a double click on the script in your Windows Explorer, neither drag and drop it to your session nor start it via Record and Playback.

      Let us know your result.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Stefan and thanks . I disabled the boxes and that was fine, But i still got this error and have of course tried play around with it, I dont really understand why you put /n infront of the 2 other sessions. But i guess there is a logic answer on that. But the error i get now is this one.,

      Have a look.

      sincerely

      Abjac

      ScreenHunter_126 Oct. 23 17.04.jpg

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      you get the WScript error because you don't execute the script in the context of the Windows Scripting Host. Start the script like this

      001.JPG

      and all should be run well - on a 64-bit Windows. If you use 32-bit Windows do the same from the System32 directory.

      Let us know your results.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Stefan. Could you be so kind to put this in a copy paste format. I was trying to read about it, And i created a bat file. Some say that is working ok.

      My full path to my vbs file is.

      C:\Users\IBM_ADMIN\Desktop\SAP\Sap Scripts\Script7login.vbs"

      And i created a bat file like below.

      start "" "C:\Users\IBM_ADMIN\Desktop\SAP\Sap Scripts\Script7login.vbs"

      Saved this as a bat file,  When i run this it give me another error, The wscript error is gone but i get this below instead, But please confirm if this metode is ok to run, And if with your way please put in copy paste format,

      Here is the error i get now,

      Have a look thanks

      ScreenHunter_126 Oct. 24 11.18.jpg

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Ab,

      in your script you have set Option Explicit, delete the line and you get no error message Variable is undefined.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan and thanks i removed the line.

      Option Explicit

      and back in my script is this.

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

        '-Directives----------------------------------------------------------

       

        '-Global Variables----------------------------------------------------

          Dim SapGuiAuto, application, connection, Waiting

          Dim session1, session2, session3

        '-Sub CreateSession---------------------------------------------------

          Sub onCreateSession(ByVal Session)

            Waiting = 0

          End Sub

        '-Main----------------------------------------------------------------

          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(session1) Then

            Set session1 = connection.Children(0)

          End If

          If IsObject(WScript) Then

            WScript.ConnectObject application, "on"

          End If

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

          session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "Y99DEW838"

          session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "***********"

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

          Waiting = 1

          session1.createSession

          Do While (Waiting = 1)

            WScript.Sleep 100

          Loop

          If Not IsObject(session2) Then

            Set session2 = connection.Children(1)

          End If

          Waiting = 1

          session1.createSession

          Do While (Waiting = 1)

            WScript.Sleep 100

          Loop

          If Not IsObject(session3) Then

            Set session3 = connection.Children(2)

          End If

          session1.findById("wnd[0]/tbar[0]/okcd").text = "/n/hoag/akon"

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

          session2.findById("wnd[0]/tbar[0]/okcd").text = "/nfbl5n"

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

          session3.findById("wnd[0]/tbar[0]/okcd").text = "/nudm_bp"

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

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

      But it give me exactly the same error.

      ScreenHunter_115 Nov. 01 11.22.jpg

      So it did not solve it. Please have a look at the hole script and see if some little thing is wrong., But the error is the same.

      Sincerely

      Abjac

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      I corrected your script a little bit and it works:

      '-Begin-----------------------------------------------------------------
      
        '-Directives----------------------------------------------------------
          Option Explicit
      
        '-Global Variables----------------------------------------------------
          Dim SapGuiAuto, application, connection, Waiting
          Dim session1, session2, session3
      
        '-Sub CreateSession---------------------------------------------------
          Sub onCreateSession(ByVal Session)
            Waiting = 0
          End Sub
      
        '-Main----------------------------------------------------------------
          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(session1) Then
            Set session1 = connection.Children(0)
          End If
      
          If IsObject(WScript) Then
            WScript.ConnectObject application, "on"
          End If
      
          session1.findById("wnd[0]").maximize
          session1.findById("wnd[0]/usr/txtRSYST-BNAME").text = "Y4711"
          session1.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "snoopy"
          session1.findById("wnd[0]").sendVKey 0
      
          Waiting = 1
          session1.createSession
          Do While (Waiting = 1)
            WScript.Sleep 100
          Loop
      
          If Not IsObject(session2) Then
            Set session2 = connection.Children(1)
          End If
      
          Waiting = 1
          session1.createSession
          Do While (Waiting = 1)
            WScript.Sleep 100
          Loop
      
          If Not IsObject(session3) Then
            Set session3 = connection.Children(2)
          End If
      
          session1.findById("wnd[0]/tbar[0]/okcd").text = "/n/hoag/akon"
          session1.findById("wnd[0]").sendVKey 0
          session2.findById("wnd[0]/tbar[0]/okcd").text = "/nfbl5n"
          session2.findById("wnd[0]").sendVKey 0
          session3.findById("wnd[0]/tbar[0]/okcd").text = "/nudm_bp"
          session3.findById("wnd[0]").sendVKey 0
      
      '-End-------------------------------------------------------------------

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan it works great really, thanks allot. I added some to one of the sessions and put it to the end. So this is really great. Could you please delete my password i have changed now. But please do i forgot not to include. If this should be a totally automated process i should be able to login with the same script. Before i used this script but i cant find the window YPE.

      Which is the one i open before i run your script-

      So if i could make this work with your script it will just be perfect. Then i would have a complete automatic solution to open and login to the sessions i work with.

      Please have a look.  Thanks great you will help. Sincerely Abjac

      Here is what i tried. but not working.

      set WshShell = CreateObject("WScript.Shell")

      Set proc = WshShell.Exec("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe")

                  Do While proc.Status = 0

                  WScript.Sleep 100

            Loop

         Set SapGui = GetObject("SAPGUI")

      Set Appl = SapGui.GetScriptingEngine

      Set Connection = Appl.Openconnection("BH/YPE", True)

      Set session = Connection.Children(0)

      session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "Y99DEW838"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "***********"

      session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

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

      Below is the finish script from your great help and its working not perfect

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

        '-Directives----------------------------------------------------------

          Option Explicit

        '-Global Variables----------------------------------------------------

          Dim SapGuiAuto, application, connection, Waiting

          Dim session1, session2, session3

        '-Sub CreateSession---------------------------------------------------

          Sub onCreateSession(ByVal Session)

            Waiting = 0

          End Sub

        '-Main----------------------------------------------------------------

          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(session1) Then

            Set session1 = connection.Children(0)

          End If

          If IsObject(WScript) Then

            WScript.ConnectObject application, "on"

          End If

          session1.findById("wnd[0]").maximize

          session1.findById("wnd[0]/usr/txtRSYST-BNAME").text = "Y99DEW838"

          session1.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "***********"

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

          Waiting = 1

          session1.createSession

          Do While (Waiting = 1)

            WScript.Sleep 100

          Loop

          If Not IsObject(session2) Then

            Set session2 = connection.Children(1)

          End If

          Waiting = 1

          session1.createSession

          Do While (Waiting = 1)

            WScript.Sleep 100

          Loop

          If Not IsObject(session3) Then

            Set session3 = connection.Children(2)

          End If

         

          session1.findById("wnd[0]/tbar[0]/okcd").text = "/nfbl5n"

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

          session2.findById("wnd[0]/tbar[0]/okcd").text = "/nudm_bp"

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

          session3.findById("wnd[0]/tbar[0]/okcd").text = "/n/hoag/akon"

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

          session3.findById("wnd[0]/tbar[1]/btn[17]").press

          session3.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "0"

          session3.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell

          session3.findById("wnd[0]/tbar[1]/btn[8]").press

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

      This is the session i open before i login with you last script.

      I open SAP exe and double click on YPE in the BH menu.

      ScreenHunter_116 Nov. 02 13.34.jpg

           Then i come to this page and i run your scrip from here.

      ScreenHunter_117 Nov. 02 13.34.jpg

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      try this and let us know your results.

      Cheers

      Stefan

      Set WshShell = CreateObject("WScript.Shell")
      WshShell.Run """C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"""
      
      Do While WshShell.AppActivate("SAP Logon ") = False
        WScript.Sleep 100
      Loop
      
      Set SapGui = GetObject("SAPGUI")
      Set Appl = SapGui.GetScriptingEngine
      
      Set Connection = Appl.Openconnection("TriTraTrullala", True)
      Set session = Connection.Children(0)
      
      session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "YourName"
      session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "Bambi"
      session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
      session.findById("wnd[0]").sendVKey 0
      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan and thanks i tried but it give me an error i think its the name of folder i want to open. I have tried different options but no luck.

      Please see below. I go in BH and press the YPE and then the login screen will come up, where i use your other script.

      Please have a look

      Sincerely

      Abjac

      Set WshShell = CreateObject("WScript.Shell")

      WshShell.Run """C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"""

      Do While WshShell.AppActivate("SAP Logon ") = False

      WScript.Sleep 100

      Loop

      Set SapGui = GetObject("SAPGUI")

      Set Appl = SapGui.GetScriptingEngine

      Set Connection = Appl.Openconnection("YPE", True)

      Set session = Connection.Children(0)

      session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "Username"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "Password"

      session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

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

      ScreenHunter_120 Nov. 03 13.18.jpg

      ScreenHunter_121 Nov. 03 13.19.jpg

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      you must use the description of the system.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan. It called description del systema. But there is nothing written there so i dont really know what to write. this is the info i have for the string i press YPE.

      But in the middle there is nothing written, tried to change view please have a look below on pics .

      Abjac

      ScreenHunter_126 Nov. 03 14.30.jpg

      ScreenHunter_125 Nov. 03 14.29.jpg

      ScreenHunter_122 Nov. 03 14.22.jpg

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Steffan

      I added a picture from your program tracker. When i open the page YPE. I dont know if that is a help. But i have tried again different combinations without any luck. Please see the picture below. And if you can find this session so it works in the script would be really great.

      Sincerely

      Abjac/wp-content/uploads/2015/11/tracker_824998.jpg

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      you can find the description in the SAP logon.

      Cheers

      Stefan

      001.JPG

      002.JPG

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan. I will soon get my last hair off 🙁 . I have tried so many combinations. I found the site with the description but when i paste this in you script it give the same error.

      Pasted it in like this. I really are little lost now.- Cant figure out why i cant make this work. Please see the picture also. I am quite lost cant really figure out why i cant find that session,.

      Sincerley

      Abjac

      YPE-PROD    -ERP -ECC EHP4       -[ECCPROD]

      ScreenHunter_128 Nov. 05 14.54.jpg

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      look in your SAP Logon where the SAPLogon.ini file is stored.

      /wp-content/uploads/2015/11/003_825994.jpg

      Open the file and search the section [Description], here you can find all descriptions. Search in the section [MSSysName] for the SID to find the item. Look at the same item in the section [Description] to find the correct description.

      Hope it works.

      Let us know your results.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan i did find the file and below you can see the screen shots. I pasted the line in directly but still give the same error. I pasted it like this with all spaces from the file.

      I think i did it correctly but still the error.

      Please see below'

      Sincerely

      Abjac

      YPE-PROD    -ERP -ECC EHP4       -[ECCPROD]

      ScreenHunter_129 Nov. 06 12.59.jpg

      The other i checked also and it look like below.

      Item21=YPE

      ScreenHunter_128 Nov. 06 12.58.jpg

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      I tried it on my local test system and it works perfect. I don't know why it doesn't work in your case.

      😕

      Cheers

      Stefan

      /wp-content/uploads/2015/11/001_826362.jpg

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Stefan i dont know if i mistunderstand some. But how do you put this in to the code so it open this session with the logon screen?

      I put it in like below

      Abjac

      Set WshShell = CreateObject("WScript.Shell")

      WshShell.Run """C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"""

      Do While WshShell.AppActivate("SAP Logon ") = False

      WScript.Sleep 100

      Loop

      Set SapGui = GetObject("SAPGUI")

      Set Appl = SapGui.GetScriptingEngine

      Set Connection = Appl.Openconnection("YPE-PROD    -ERP -ECC EHP4       -[ECCPROD]", True)

      Set session = Connection.Children(0)

      session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "Y99DEW838"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "***********"

      session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

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

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      my script is exactly the same as yours, no difference.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan and thanks for all your effort i am really lost cant see why i cant enter this session if the code are correct. Below error is it sure it is this problem to find the session.

      Please have a look at the error pic.

      Can it be some in the setup or because the session is on a server.?

      Sincerely

      Abjac

      /wp-content/uploads/2015/11/error_828403.jpg

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      if I try it with a wrong description I get the same error as you.

      Try instead method OpenConnection the method OpenConnectionByConnectionString like this:

      Set Connection = Appl.OpenConnectionByConnectionString("/H/10.100.222.333/S/3263", True)

      Use the IP-Address of the host /H/IPAddressOfYourHost and the instance number /S/32InstanceNumberOfYourHost.

      Let us know your results.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan and thanks for you answer. I am a little confused what and how to set it up. example the instance number. Could you have a look at below scree shots. They show i think all info for the screen i need to find.

      Please have a look and see how it has to be in the script.

      Sincerely

      ABjac

      Info.jpg

      /wp-content/uploads/2015/11/info1_830216.jpg

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      you find the instance number in the SAP logon:

      /wp-content/uploads/2015/11/997_830255.jpg

      The command should look like this:

      Set Connection = Appl.OpenConnectionByConnectionString("/H/9.63.240.106/S/3200", True)

      Let us know your results.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan it simply worked just perfect. It start and login the screen YPE.

      I tried to make this totally automated to put the 2 files i have together but no succes. If i can i can do all with one bat file.

      I use your last script to get to the screen. I removed the login . But it open up the login screen. If i run the script files separately it works. But how to put it together?

      First script find the login screen. Second find the sessions and log me in.

      Please have a look how to put these 2 together. Then all target are done.

      Thanks in advance for your great help-

      Abjac

      Script 1

      Set WshShell = CreateObject("WScript.Shell")

      WshShell.Run """C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"""

      Do While WshShell.AppActivate("SAP Logon ") = False

      WScript.Sleep 100

      Loop

      Set SapGui = GetObject("SAPGUI")

      Set Appl = SapGui.GetScriptingEngine

      Set Connection = Appl.OpenConnectionByConnectionString("/H/9.63.240.106/S/3200", True)

      Set session = Connection.Children(0)

      Second script to find the sessions and login.

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

        '-Directives----------------------------------------------------------

          Option Explicit

        '-Global Variables----------------------------------------------------

          Dim SapGuiAuto, application, connection, Waiting

          Dim session1, session2, session3

        '-Sub CreateSession---------------------------------------------------

          Sub onCreateSession(ByVal Session)

            Waiting = 0

          End Sub

        '-Main----------------------------------------------------------------

          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(session1) Then

            Set session1 = connection.Children(0)

          End If

          If IsObject(WScript) Then

            WScript.ConnectObject application, "on"

          End If

          session1.findById("wnd[0]").maximize

          session1.findById("wnd[0]/usr/txtRSYST-BNAME").text = "*********"

          session1.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "***********"

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

          Waiting = 1

          session1.createSession

          Do While (Waiting = 1)

            WScript.Sleep 100

          Loop

          If Not IsObject(session2) Then

            Set session2 = connection.Children(1)

          End If

          Waiting = 1

          session1.createSession

          Do While (Waiting = 1)

            WScript.Sleep 100

          Loop

          If Not IsObject(session3) Then

            Set session3 = connection.Children(2)

          End If

         

          session1.findById("wnd[0]/tbar[0]/okcd").text = "/nfbl5n"

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

          session2.findById("wnd[0]/tbar[0]/okcd").text = "/nudm_bp"

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

          session3.findById("wnd[0]/tbar[0]/okcd").text = "/n/hoag/akon"

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

          session3.findById("wnd[0]/tbar[1]/btn[17]").press

          session3.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "0"

          session3.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell

          session3.findById("wnd[0]/tbar[1]/btn[8]").press

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

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      hmm, the combination of the scripts would be a good exercise for you to check your knowledge. Here the complete script:

      '-Begin-----------------------------------------------------------------
      
        '-Directives----------------------------------------------------------
          Option Explicit
      
        '-Global Variables----------------------------------------------------
          Dim WshShell
          Dim SapGuiAuto, application, connection, Waiting
          Dim session1, session2, session3
      
        '-Sub CreateSession---------------------------------------------------
          Sub onCreateSession(ByVal Session)
            Waiting = 0
          End Sub
      
        '-Main----------------------------------------------------------------
          Set WshShell = CreateObject("WScript.Shell")
          WshShell.Run """C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"""
      
          Do While WshShell.AppActivate("SAP Logon ") = False
            WScript.Sleep 100
          Loop
      
          If Not IsObject(application) Then
            Set SapGuiAuto = GetObject("SAPGUI")
            Set application = SapGuiAuto.GetScriptingEngine
          End If
      
          If Not IsObject(connection) Then
            Set connection = Appl.OpenConnectionByConnectionString("/H/9.63.240.106/S/3200", True)
          End If
      
          If Not IsObject(session1) Then
            Set session1 = connection.Children(0)
          End If
      
          If IsObject(WScript) Then
            WScript.ConnectObject application, "on"
          End If
      
          session1.findById("wnd[0]").maximize
          session1.findById("wnd[0]/usr/txtRSYST-BNAME").text = "*********"
          session1.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "***********"
          session1.findById("wnd[0]").sendVKey 0
      
          Waiting = 1
          session1.createSession
          Do While (Waiting = 1)
            WScript.Sleep 100
          Loop
      
          If Not IsObject(session2) Then
            Set session2 = connection.Children(1)
          End If
      
          Waiting = 1
          session1.createSession
          Do While (Waiting = 1)
            WScript.Sleep 100
          Loop
      
          If Not IsObject(session3) Then
            Set session3 = connection.Children(2)
          End If
        
          session1.findById("wnd[0]/tbar[0]/okcd").text = "/nfbl5n"
          session1.findById("wnd[0]").sendVKey 0
          session2.findById("wnd[0]/tbar[0]/okcd").text = "/nudm_bp"
          session2.findById("wnd[0]").sendVKey 0
          session3.findById("wnd[0]/tbar[0]/okcd").text = "/n/hoag/akon"
          session3.findById("wnd[0]").sendVKey 0
          session3.findById("wnd[0]/tbar[1]/btn[17]").press
          session3.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "0"
          session3.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell
          session3.findById("wnd[0]/tbar[1]/btn[8]").press
      
      '-End-------------------------------------------------------------------

      As you can see it isn't difficult.

      Cheers

      Stefan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan and thanks allot for your efford. I am totally new in scripts. Have done much macroes but not scripts-.  If i run the scripts now one by one its working.

      But when i run the last one you made i get this error.

      Sincerely

      Abjac

      /wp-content/uploads/2015/11/finish_830880.jpg

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      HI Stefan i just found out how to make it work . I changed

      Set Connection = Appl.OpenConnectionByConnectionString("/H/9.63.240.106/S/3200", True)

      to

      Set connection = Application.OpenConnectionByConnectionString("/H/9.63.240.106/S/3200", True)

      Amazing so little could do it but its working now. I can now with one shortcut log in to all the screens i work with.,

      I am really happy for this and all your help.- Its very hard to find many who have so much knowledge about sap and scripts. So your knowledge is really allot.

      Thanks allot i know i am a beginner in this. But happy you want to share your experience and knowledge. So great with all your help.

      Have a nice day Stefan

      A happy Abjac hehe 🙂

      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Abjac,

      sorry, my fault, but you have found it. 😉

      As you said, small cause, big effect...

      Good luck for your further development.

      Cheers

      Stefan

      Author's profile photo Rapha BV
      Rapha BV

       

      Hello,

      I used the same code and appaer the below error. Would you know what is the problem?

       

       

      Dim WshShell
          Dim SapGuiAuto, application, connection, Waiting
          Dim session1
      
      
      
          Sub onCreateSession(ByVal Session)
            Waiting = 0
          End Sub
      
       
      
      
          Set WshShell = CreateObject("WScript.Shell")
          WshShell.Run """C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"""
       
           Do While WshShell.AppActivate("SAP Logon") = False
            WScript.Sleep 100
          Loop
      
          If Not IsObject(application) Then
            Set SapGuiAuto = GetObject("SAPGUI")
            Set application = SapGuiAuto.GetScriptingEngine
          End If
      
          If Not IsObject(connection) Then
            Set connection = Application.OpenConnectionByConnectionString("/h/10.38.74.148/S/3200", True)
          End If
      
          If Not IsObject(session1) Then
            Set session1 = connection.Children(0)
          End If
      
          If IsObject(WScript) Then
            WScript.ConnectObject application, "on"
      
      
      
      
          End If
      
          session1.findById("wnd[0]").maximize
          session1.findById("wnd[0]/usr/txtRSYST-BNAME").text = "username"
          session1.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "password$"
          session1.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
      
          session1.findById("wnd[0]").sendVKey 0
      
          
      
          Waiting = 1
          session1.createSession
          Do While (Waiting = 1)
            WScript.Sleep 100
          Loop
      
          
        
          session1.findById("wnd[0]/tbar[0]/okcd").text = "/nfbl3n"
          session1.findById("wnd[0]").sendVKey 0