How to Automate SAP GUI for Windows via dotNETRunner

Scripting Tracker is a SAP GUI Scripting development tool. It is an SAP GUI analyzer, scripting recorder for different programming languages, SAP GUI Scripting API viewer, code composer, screen comparator and dump state viewer on SAP GUI Scripting base. The scripting recorder offers the possibility to generate VBdotNET code, which we can process with dotNETRunner inside Robin.

The first step is to Record the SAP activities.


To use this code with Robin it is in a second step necessary to open the source in the external editor, …

… add the code line Imports Microsoft.VisualBasic and change Public Module to Public Class.


Imports Microsoft.VisualBasic

Public Class SAPGUIScripting

  Sub Main()

    Dim SapGuiAuto As Object
    Dim app As Object
    Dim connection As Object
    Dim session As Object

      SapGuiAuto = GetObject("SAPGUI")
      app = SapGuiAuto.GetScriptingEngine
      connection = app.Children(0)
      If connection.DisabledByServer = True Then
        Exit Sub
      End If
      session = connection.Children(0)
      If session.Info.IsLowSpeedConnection = True Then
        Exit Sub
      End If
      Exit Sub
    End Try

session.findById("wnd[0]/tbar[0]/okcd").text = "/nse16"
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").text = "TADIR"

  End Sub

End Class


Now you can use the VBdotNET with the recorded SAP activities with Robin.


dotNETRunner.AddAssembly \
  Assembly : "Microsoft.VisualBasic.dll"

dotNETRunner.CompileFile \
  FileName : "C:\Dummy\Tracker_EditScript.vb" \
  Language : "VB" \
  ErrorReturn => ErrorReturn

if ErrorReturn <> "" then
  Console.Write Message : ErrorReturn

dotNETRunner.Run \
  Instance : "SAPGUIScripting" \
  Method : "Main" \
  ErrorReturn => ErrorReturn

if ErrorReturn <> "" then
  Console.Write Message : ErrorReturn


On this way, complex activities in the SAP GUI for Windows can be recorded very quickly and easily. The recorded code can be integrated into Robin with a few easy steps. If adjustments, e.g. parameter transfers, should be necessary, these are also realized promptly with a few lines of code.

This approach is similar to using SAP GUI scripting in Blue Prism’s code stages.

1 Like