Skip to Content

Hello community,

since four days offers SAP a new patch level of the SAP GUI for Windows. With this patch level 7 SAP offers also a new version of the SAP GUI Scripting API (sapfewse.ocx). There are some notable changes:

  • The following controls
    $CLSID_SAPFEWSELib_GuiListControl = GUID$("{CC75EA97-3DB1-4BDF-9791-89D09B1800A0}")
    $CLSID_SAPFEWSELib_GuiInputControl = GUID$("{31233701-DF39-49F7-A641-16CAB0C9C5F0}")

    are changed to

    $CLSID_SAPFEWSELib_GuiComboBoxControl = GUID$("{CC75EA97-3DB1-4BDF-9791-89D09B1800A0}")
    $CLSID_SAPFEWSELib_GuiInputFieldControl = GUID$("{31233701-DF39-49F7-A641-16CAB0C9C5F0}")

    Also the interfaces from

    $IID_SAPFEWSELib_ISapListControlTarget = GUID$("{6E824989-726A-45EE-9FF0-52DC1A41D8D4}")
    $IID_SAPFEWSELib_ISapInputControlTarget = GUID$("{D2C7FEC7-052E-4BA3-BE44-526D9E0925C4}")

    to

    $IID_SAPFEWSELib_ISapComboBoxControlTarget = GUID$("{6E824989-726A-45EE-9FF0-52DC1A41D8D4}")
    $IID_SAPFEWSELib_ISapInputFieldControlTarget = GUID$("{D2C7FEC7-052E-4BA3-BE44-526D9E0925C4}")
  • It seems that the GuiListControl is now renamed to a GuiComboBoxControl with different methods.

    As far as I can see the methods

    SetSelectionID <1> (In i As Long<0>)
    GetSelectionID <2> () As Long
    GetSelectionText <3> () As WString
    GetTextFromID <4> (In idVal As Long<0>) As WString
    SetInputControlText <5> (In ISapListControlTarget As WString<0>) As Integer
    GetInputControlText <6> () As WString
    SetComboboxText <7> (In Text As WString<0>)
    GetLabelText <9> () As WString

    doesn’t exists anymore and the method

    FireSelected <6> ()

    is new.

  • It is the same with GuiInputControl and now GuiInputFieldControl.
    As far as I can see the methods

    SetInputControlText <1> (In ISapInputControlTarget As WString<0>) As Integer
    GetInputControlText <2> () As WString
    GetLabelText <4> () As WString
    GetButtonTooltip <5> () As WString
    GetNumberOfEntries <6> () As Long
    GetHistoryEntryText <7> (In ISapInputControlTarget As Long<0>) As WString
    IsHistoryOpend <8> () As Integer
    GetSelectedHistoryItem <9> () As WString

    doesn’t exists anymore.

If you use this controls in your SAP GUI Scripting programs, be careful if you update to PL7.

Hint: I detect the GuiListControl class at the SAP GUI 7.30 PL6, you can find more information here. The class has never been documented. The renamed class GuiComboBoxControl is actually also not completely documented. The GuiInputControl class has never been documented too and the renamed class GuiInputFieldControl is actually also not completely documented too.

Cheers
Stefan

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. Michael Burnett

    Hello Stefan,

    We recently brought in a system running 64-bit Office and can’t figure out how to configure VBA to open a connection to SAP. From the content of your blog posts, it appears that you very likely have some knowledge to share with the community on this topic. Any help will be much appreciated.

    Here are some snippets (functional in the 32-bit environment)…

    Public SAPguiAPP As SAPFEWSELib.GuiApplication

    Public Connection As SAPFEWSELib.GuiConnection

    Public Session As SAPFEWSELib.GuiSession

        If IsObject(SAPguiAPP) Then

            Set SAPguiAPP = CreateObject(“Sapgui.ScriptingCtrl.1”) **

        End If

        If IsObject(Connection) Then

            Set Connection = SAPguiAPP.OpenConnectionByConnectionString(IP_Address)

        End If

        If IsObject(Session) Then

            Set Session = Connection.Children(0)

        End If

    ** run-time error 429…ActiveX component can’t create object

    References clicked…

    Visual Basic for Applications

    Microsoft Excel 16.0 Object Library

    OLE Automation

    Microsoft Office 16.0 Object Library

    SAP GUI Scripting API

    Microsoft ActiveX Data Objects 6.1 Library


    If you do indeed decide to create a blog post or document on this topic or know somebody that will be able to help us, please let me know by responding to this post (I am now following it).

    Thank you very much for your consideration,


    Mike

    (0) 
    1. Stefan Schnell Post author

      Hello Mike,

      I think this thread answers your question. In my opinion it should be possible to use SAP GUI Scripting API inside 64-bit VBA but I never tried it. If you want to use your code inside x86 und x64 note this thread and for more information this thread.

      Let us know your results.

      Cheers

      Stefan

      (0) 
        1. Michael Burnett

          Hi Stefan,


          I implemented Emmanuel Carabott’s registry hack, rebooted, and tried to login to SAP from Excel VBA. Unfortunately, I’m still getting the 429 run-time error at…


          Set SAPguiAPP = CreateObject(“Sapgui.ScriptingCtrl.1”)


          Here is what my registry currently looks like.


          Capture1.PNG

          Capture2.PNG

          Capture3.PNG

          One thing that didn’t go as per the instructions…


          When I went to add the new key under HKey_Local_Machine\Software\Classes\AppID\ the key with the name of the COM object GUID was already there (and already contained the DllSurrogate string). It was if if the key I added under HKey_Classes_Root\Wow6432Node\AppID\ was automatically replicated.


          To be certain, I deleted everything and did it again, paying close attention to which HKey area I was in. Again, the key was automatically added to the HKey_Local_Machine area. Not sure if that would cause this not to work.




          As per your thread, is the declaration…


          Public SAPguiAPP As SAPFEWSELib.GuiApplication


          appropriate in a 64-bit VBA environment?





          Thanks!


          Mike


          Here is my current reference setup…I don’t think the ActiveX DO reference is necessary…I was just trying a few things.


          Capture4.PNG

          (0) 
          1. Stefan Schnell Post author

            Hello Mike,

            you modify the wdtfuncs.ocx library, but this library isn’t SAP GUI Scripting API with the ID Sapgui.ScriptingCtrl.1. What do you want exactly to do? Do you want to use SAP GUI Scripting API or the ActiveX controls of librfc in the context of VBA 64 bit?

            If you want to use SAP GUI Scripting API search for Sapgui.ScriptingCtrl.1 to find the correct CLSID.

            /wp-content/uploads/2016/01/001_862495.jpg

            I check the SAP GUI Scripting API and the first step works. I set the registry entries as I described and I can instantiate the SAP GUI Scripting API inside VBA 64 bit.

            Here a snippet of my debugging perspective of VBA IDE inside Excel x64:

            /wp-content/uploads/2016/01/001_862495.jpg

            It is generally important and good to know that it is basically possible to use x86 SAP GUI Scripting API inside x64 applications.

            It is not possible to reference to the library inside the x64 VBA IDE, so you must use the Object type for an x86 ActiveX library inside an x64 VBA IDE.

            Let us know your results.

            Cheers

            Stefan

            (0) 
            1. Stefan Schnell Post author

              Hello Mike,

              in my case a normal script works without any problems in 64-bit VBA with the actual SAP GUI for Windows:

              Sub Test()
              
                Set SapGuiAuto = GetObject("SAPGUI")
                Set appl = SapGuiAuto.GetScriptingEngine
                Set connection = appl.Children(0)
                Set session = connection.Children(0)
              
                session.FindById("wnd[0]/tbar[0]/btn[3]").Press
              
              End Sub

              It seems that is not necessary to modify the registry for this kind of programs.

              I build a new environment without any modifications on the registry and the following code works without any problems in 64-bit VBA:

              Sub Test()
              
                Set SapGuiAuto = GetObject("SAPGUI")
                Set appl = SapGuiAuto.GetScriptingEngine
                Set Connection = appl.Children(0)
                Set session = Connection.Children(0)
                Set info = session.info
                Debug.Print info.Program
              
              End Sub

              But if I call

              Set SAPguiAPP = CreateObject("Sapgui.ScriptingCtrl.1")

              I get the same runtime 429 error as you. With the modification in the registry I can instantiate the class, but I can’t call the method OpenConnection or OpenConnectionByConnectionString successfully.

              Cheers

              Stefan

              (0) 
              1. Michael Burnett

                Thanks Stefan!

                I found your other helpful link here which I meshed with your recommendations above to come up with this…

                Sub SAP_OpenSessionFromLogon()

                    Dim WSHShell

                    #If VBA7 Then

                        Dim SapGuiAuto As Object

                    #Else

                        Dim SapGuiAuto As SAPFEWSELib.GuiApplication

                    #End If

                    Dim Appl

                    Dim Connection

                    Dim Session

                    Shell (“C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe”)

                    Set WSHShell = CreateObject(“WScript.Shell”)

                    Do Until WSHShell.AppActivate(“SAP Logon “)

                        Sleep 1000

                    Loop

                    Set WSHShell = Nothing

                    Set SapGuiAuto = GetObject(“SAPGUI”)

                    Set Appl = SapGuiAuto.GetScriptingEngine

                    ‘Set Connection = Appl.Children(0) ‘ this command did not work…RTE 614 “The enumerator of the collection cannot find en [sic] element with the specified index”

                    Set Connection = Appl.OpenConnection(“BLP on Windows 2012”, True)

                    Set Session = Connection.Children(0)

                    Session.FindById(“wnd[0]”).Maximize

                    Session.FindById(“wnd[0]/usr/txtRSYST-MANDT”).Text = “100”

                    Session.FindById(“wnd[0]/usr/txtRSYST-BNAME”).Text = “mburnett”

                    Session.FindById(“wnd[0]/usr/pwdRSYST-BCODE”).Text = “password”

                    Session.FindById(“wnd[0]/usr/txtRSYST-LANGU”).Text = “EN”

                    Session.FindById(“wnd[0]”).SendVKey 0

                    Session.SendCommand (“/nse16n”)

                    ‘e.g. Pull some table data

                    Set Session = Nothing

                    Connection.CloseSession (“ses[0]”)

                    Set Connection = Nothing

                    Set SapGuiAuto = Nothing

                End Sub

                It works well, but I’m concerned with shelling this instead of having it run as it an instance within Excel. It might create confusion/problems when a user has active sessions running in the SAP logon 740 environment. I opened a few sessions and ran the above code and all my existing instances remained open, but again I think it would be worth investigating how to get SAP to run within Excel without having to shell it (like we can in 32-bit Office using SAPguiAPP = CreateObject(“Sapgui.ScriptingCtrl.1”)).

                Can you think of any drawbacks of using the shell commands to get a session going versus running SAP directly within the Office environment?

                Again, thanks very much for your help. You definitely helped me get over this hump!

                Mike

                (0) 

Leave a Reply