Skip to Content
Author's profile photo Stefan Schnell

Tip: How to use AutoIt and SAP GUI Scripting without SAP ROT Wrapper

In the SAP GUI Scripting API help file shows us an example how to use the SAP GUI Scripting ROT Access Helper. Furthermore, I quote: “This is for example the case for the following engines … AutoIt, a freeware Windows automation language ” Consequently I assume that is the only way to connect a running SAP GUI instance wit AutoIt. But this is wrong. It is also possible to use the function ObjGet with the relevant display name from the Running Object Table (ROT).

Here an example with an NWBC instance:

;-Begin-----------------------------------------------------------------

  ;-Directives----------------------------------------------------------
    AutoItSetOption("MustDeclareVars", 1)

  ;-Includes------------------------------------------------------------
    #Include "C:\\Language\\AutoIt\\Include\\MsgBoxConstants.au3"

  ;-Sub Main------------------------------------------------------------
    Func Main()

      ;-Variables-------------------------------------------------------
        Local $oSapGuiAuto

      $oSapGuiAuto = ObjGet("SAPGUISERVER")
      If Not IsObj($oSapGuiAuto) Or @Error Then
        MsgBox($MB_SYSTEMMODAL, "", "The variable is not an object")
        Return
      EndIf

      If @AutoItX64 Then
        MsgBox($MB_SYSTEMMODAL, "x64", "The variable is an object")
      Else
        MsgBox($MB_SYSTEMMODAL, "x86", "The variable is an object")
      EndIf

    EndFunc

  ;-Main----------------------------------------------------------------
    Main()

;-End-------------------------------------------------------------------

If you take an access to the SAP GUI Scripting on this way, you have also the possibility to use the 32-bit (x86) and the 64-bit (x64) version of AutoIt. It works with both versions.

Here an example which detects the SAP GUI Scripting version:

;-Begin-----------------------------------------------------------------

  ;-Directives----------------------------------------------------------
    AutoItSetOption("MustDeclareVars", 1)

  ;-Includes------------------------------------------------------------
    #Include "C:\\Language\\AutoIt\\Include\\MsgBoxConstants.au3"

  ;-Function GetAutoItArchitecture--------------------------------------
    Func GetAutoItArchitecture()
      If @AutoItX64 Then
        Return "x64"
      Else
        Return "x86"
      EndIf
    EndFunc

  ;-Sub Main------------------------------------------------------------
    Func Main()

      ;-Variables-------------------------------------------------------
        Local $oSapGuiAuto, $Application

      $oSapGuiAuto = ObjGet("SAPGUISERVER")
      If Not IsObj($oSapGuiAuto) Or @Error Then
        Return
      EndIf

      $Application = $oSapGuiAuto.GetScriptingEngine()
      If Not IsObj($Application) Then
        Return
      EndIf

      MsgBox($MB_SYSTEMMODAL, GetAutoItArchitecture(), _
        "SAP GUI Scripting Version " & $Application.MajorVersion() & _
        "." & $Application.MinorVersion())

    EndFunc

  ;-Main----------------------------------------------------------------
    Main()

;-End-------------------------------------------------------------------

Here an example how to use the SessionInfo object:

;-Begin-----------------------------------------------------------------

  ;-Directives----------------------------------------------------------
    AutoItSetOption("MustDeclareVars", 1)

  ;-Includes------------------------------------------------------------
    #Include "C:\\Language\\AutoIt\\Include\\MsgBoxConstants.au3"

  ;-Function GetAutoItArchitecture--------------------------------------
    Func GetAutoItArchitecture()
      If @AutoItX64 Then
        Return "x64"
      Else
        Return "x86"
      EndIf
    EndFunc

  ;-Sub Main------------------------------------------------------------
    Func Main()

      ;-Variables-------------------------------------------------------
        Local $oSapGuiAuto, $Application, $Connection, $Session
        Local $Info

      $oSapGuiAuto = ObjGet("SAPGUISERVER")
      If Not IsObj($oSapGuiAuto) Or @Error Then
        Return
      EndIf

      $Application = $oSapGuiAuto.GetScriptingEngine()
      If Not IsObj($Application) Then
        Return
      EndIf

      $Connection = $Application.Children(0)
      If Not IsObj($Connection) Then
        Return
      EndIf

      $Session = $Connection.Children(0)
      If Not IsObj($Session) Then
        Return
      EndIf

      $Info = $Session.Info()

      MsgBox($MB_SYSTEMMODAL, GetAutoItArchitecture(), _
        "Transaction: " & $Info.Transaction() & @CRLF & _
        "Program: " & $Info.Program() & @CRLF & _
        "ScreenNumber: " & $Info.ScreenNumber() & @CRLF & _
        "CodePage: " & $Info.CodePage() & @CRLF & _
        "GuiCodePage: " & $Info.GuiCodePage() & @CRLF & _
        "I18NMode: " & $Info.I18NMode() & @CRLF & _
        "Language: " & $Info.Language() & @CRLF & _
        "IsLowSpeedConnection: " & $Info.IsLowSpeedConnection())

    EndFunc

  ;-Main----------------------------------------------------------------
    Main()

;-End-------------------------------------------------------------------

With ObjGet we save the using of the SAP ROT wrapper, which has the disadvantage only to be available as an x86 version. And so we save ourselves the “crooked” way to make the SAP ROT wrapper available in the x64 area.

Enjoy it.

Cheers
Stefan

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.