<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: SAP VBA Scripting two ECC systems in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sap-vba-scripting-two-ecc-systems/qaa-p/619615#M151107</link>
    <description>&lt;P&gt;Hello Stacy,&lt;/P&gt;
  &lt;P&gt;you can exactly use the approach from the referenced post. E.g. like this (it is in VBScript but it should not be very difficult to transfer it to VBA):&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;  Function GetSystem(SID)
   
      Set SapGuiAuto = GetObject("SAPGUI")
      If Not IsObject(SapGuiAuto) Then
        Exit Function
      End If

      Set SapAppl = SapGuiAuto.GetScriptingEngine
      If Not IsObject(SapAppl) Then
        Exit Function
      End If

      Set CollCon = SapAppl.Connections()
      If Not IsObject(CollCon) Then
        Exit Sub
      End If
     
      '-Loop over connections-------------------------------------------
        For i = 0 To CollCon.Count() - 1

          Set oCon = SapAppl.Children(CLng(i))
          If Not IsObject(oCon) Then
            Exit Sub
          End If 

          Set CollSes = oCon.Sessions()
          If Not IsObject(CollSes) Then
            Exit Sub
          End If 
       
          '-Loop over sessions------------------------------------------
            For j = 0 To CollSes.Count() - 1
       
              Set oSes = oCon.Children(CLng(j))
              If Not IsObject(oSes) Then
                Exit Sub
              End If 

              If oSes.Busy() = vbFalse Then
         
                Set oSesInf = oSes.Info()
                If IsObject(oSesInf) Then

                    SID = oSesInf.SystemName()

                    If SID = "BAP" Then

                      GetSystem = oSes

                    End If

                End If
             
              End If

            Next

        Next

    End Function&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;All you have to do now is to call&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;Session = GetSytem("BAP") 'Here you must insert the SID of your B-SAP
If Not IsObject(Session) Then
  "Here you must insert your code to open a new session of your B-SAP
End If&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Cheers&lt;BR /&gt;Stefan&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 04:31:39 GMT</pubDate>
    <dc:creator>Stefan-Schnell</dc:creator>
    <dc:date>2018-02-01T04:31:39Z</dc:date>
    <item>
      <title>SAP VBA Scripting two ECC systems</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-vba-scripting-two-ecc-systems/qaq-p/619612</link>
      <description>&lt;P&gt;We recently went through an acquisition and are running 2 ECC systems one client is HBP and the other is SP3. &lt;/P&gt;
  &lt;P&gt;We are currently using &lt;/P&gt;
  &lt;P&gt;' RUNS SAP&lt;BR /&gt;'If Not IsObject(Application) Then&lt;BR /&gt; Set SapGuiAuto = GetObject("SAPGUI")&lt;BR /&gt; Set Application1 = SapGuiAuto.GetScriptingEngine&lt;BR /&gt;'End If&lt;BR /&gt;If Not IsObject(Connection) Then&lt;BR /&gt; Set Connection = Application1.Children(0)&lt;BR /&gt;End If&lt;BR /&gt;If Not IsObject(session) Then&lt;BR /&gt; ' ########################### you can change this 0 to 1, 2, 3, 4, or 5 to change SAP session ########&lt;BR /&gt; Set session = Connection.Children(0)&lt;BR /&gt;End If&lt;BR /&gt;If IsObject(WScript) Then&lt;BR /&gt; WScript.ConnectObject session, "on"&lt;BR /&gt; WScript.ConnectObject Application1, "on"&lt;BR /&gt;End If&lt;/P&gt;
  &lt;P&gt;But how can we set this up so we can tell it which client to look for? &lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 20:11:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-vba-scripting-two-ecc-systems/qaq-p/619612</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-01-25T20:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAP VBA Scripting two ECC systems</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-vba-scripting-two-ecc-systems/qaa-p/619613#M151105</link>
      <description>&lt;P&gt;Hello Stacy,&lt;/P&gt;
  &lt;P&gt;you can find a solution, how to select a specific session, &lt;A href="https://blogs.sap.com/2012/11/19/how-to-select-a-specific-session-to-do-sap-gui-scripting-activities-inside-it/"&gt;here&lt;/A&gt;.&lt;/P&gt;
  &lt;P&gt;Let us know if it is solve your problem.&lt;/P&gt;
  &lt;P&gt;Request: Could you please post your future SAP GUI Scripting questions in the &lt;A href="https://www.sap.com/community/topic/gui/all-content.html"&gt;SAP GUI Community&lt;/A&gt;. This is the correct section for this kind of questions, because SAP GUI Scripting is part of the SAP GUI Frontend. On this way, you will receive an answer to your questions faster. Thank you.&lt;/P&gt;
  &lt;P&gt;Best regards&lt;BR /&gt;Stefan&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 19:30:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-vba-scripting-two-ecc-systems/qaa-p/619613#M151105</guid>
      <dc:creator>Stefan-Schnell</dc:creator>
      <dc:date>2018-01-30T19:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAP VBA Scripting two ECC systems</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-vba-scripting-two-ecc-systems/qaa-p/619614#M151106</link>
      <description>&lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Sorry new to questions.... So I have a script in excel that open SAP and runs COOIS one for our B-SAP system and the other for our C-SAP system and I'm trying to automate it to do both. I have a .bat file that runs the macros but I need the macro that is supposed to run for the B-SAP system to look for that session that is open.&lt;/P&gt;
  &lt;P&gt; Here is my script currently &lt;/P&gt;
  &lt;P&gt;Sub Auto_Open()&lt;BR /&gt; Call Module1.MainMacro&lt;BR /&gt;End Sub&lt;BR /&gt;Sub MainMacro()&lt;BR /&gt;'&lt;BR /&gt;' Macro1 Macro&lt;/P&gt;
  &lt;P&gt;Application.DisplayAlerts = False&lt;BR /&gt;Application.ScreenUpdating = False&lt;/P&gt;
  &lt;P&gt;Workbooks.Open Filename:= _&lt;BR /&gt; "Z:\xxxxxxx\yyyyyyy\4COOIS.csv"&lt;BR /&gt;Range("A1").Select&lt;BR /&gt; Range(Selection, Selection.End(xlDown)).Select&lt;BR /&gt;Selection.Copy&lt;BR /&gt;&lt;BR /&gt;If Not IsObject(Application1) Then&lt;BR /&gt; Set SapGuiAuto = GetObject("SAPGUI")&lt;BR /&gt; Set Application1 = SapGuiAuto.GetScriptingEngine&lt;BR /&gt;End If&lt;BR /&gt;If Not IsObject(Connection) Then&lt;BR /&gt; Set Connection = Application1.Children(0)&lt;BR /&gt;End If&lt;BR /&gt;If Not IsObject(Session) Then&lt;BR /&gt; Set Session = Connection.Children(0)&lt;BR /&gt;End If&lt;BR /&gt;If IsObject(WScript) Then&lt;BR /&gt;WScript.ConnectObject Session, "on"&lt;BR /&gt;WScript.ConnectObject Application1, "on"&lt;BR /&gt;End If&lt;BR /&gt; With Session&lt;BR /&gt; .findById("wnd[0]/tbar[0]/okcd").Text = "/ncoois"&lt;BR /&gt; .findById("wnd[0]").sendVKey 0&lt;BR /&gt; .findById("wnd[0]/usr/ssub%_SUBSCREEN_TOPBLOCK:PPIO_ENTRY:1100/ctxtPPIO_ENTRY_SC1100-ALV_VARIANT").Text = "/M&amp;amp;I_OPNRES"&lt;BR /&gt; .findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/btn%_S_AUFNR_%_APP_%-VALU_PUSH").press&lt;BR /&gt; .findById("wnd[1]/tbar[0]/btn[24]").press&lt;BR /&gt; .findById("wnd[1]/tbar[0]/btn[8]").press&lt;BR /&gt; .findById("wnd[0]/tbar[1]/btn[8]").press&lt;BR /&gt; .findById("wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell").pressToolbarButton "&amp;amp;NAVIGATION_PROFILE_TOOLBAR_EXPAND"&lt;BR /&gt; .findById("wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell").pressToolbarContextButton "&amp;amp;MB_EXPORT"&lt;BR /&gt; .findById("wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell").selectContextMenuItem "&amp;amp;PC"&lt;BR /&gt; .findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").Select&lt;BR /&gt; .findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").SetFocus&lt;BR /&gt; .findById("wnd[1]/tbar[0]/btn[0]").press&lt;BR /&gt; .findById("wnd[1]/usr/ctxtDY_PATH").Text = "Z:\Information Flow\Open Order Reservations"&lt;BR /&gt; .findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "COOIS.txt"&lt;BR /&gt; .findById("wnd[1]/tbar[0]/btn[11]").press&lt;BR /&gt; End With&lt;BR /&gt;Application.Quit&lt;BR /&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 21:52:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-vba-scripting-two-ecc-systems/qaa-p/619614#M151106</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-01-31T21:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAP VBA Scripting two ECC systems</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-vba-scripting-two-ecc-systems/qaa-p/619615#M151107</link>
      <description>&lt;P&gt;Hello Stacy,&lt;/P&gt;
  &lt;P&gt;you can exactly use the approach from the referenced post. E.g. like this (it is in VBScript but it should not be very difficult to transfer it to VBA):&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;  Function GetSystem(SID)
   
      Set SapGuiAuto = GetObject("SAPGUI")
      If Not IsObject(SapGuiAuto) Then
        Exit Function
      End If

      Set SapAppl = SapGuiAuto.GetScriptingEngine
      If Not IsObject(SapAppl) Then
        Exit Function
      End If

      Set CollCon = SapAppl.Connections()
      If Not IsObject(CollCon) Then
        Exit Sub
      End If
     
      '-Loop over connections-------------------------------------------
        For i = 0 To CollCon.Count() - 1

          Set oCon = SapAppl.Children(CLng(i))
          If Not IsObject(oCon) Then
            Exit Sub
          End If 

          Set CollSes = oCon.Sessions()
          If Not IsObject(CollSes) Then
            Exit Sub
          End If 
       
          '-Loop over sessions------------------------------------------
            For j = 0 To CollSes.Count() - 1
       
              Set oSes = oCon.Children(CLng(j))
              If Not IsObject(oSes) Then
                Exit Sub
              End If 

              If oSes.Busy() = vbFalse Then
         
                Set oSesInf = oSes.Info()
                If IsObject(oSesInf) Then

                    SID = oSesInf.SystemName()

                    If SID = "BAP" Then

                      GetSystem = oSes

                    End If

                End If
             
              End If

            Next

        Next

    End Function&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;All you have to do now is to call&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;Session = GetSytem("BAP") 'Here you must insert the SID of your B-SAP
If Not IsObject(Session) Then
  "Here you must insert your code to open a new session of your B-SAP
End If&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Cheers&lt;BR /&gt;Stefan&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 04:31:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-vba-scripting-two-ecc-systems/qaa-p/619615#M151107</guid>
      <dc:creator>Stefan-Schnell</dc:creator>
      <dc:date>2018-02-01T04:31:39Z</dc:date>
    </item>
  </channel>
</rss>

