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.

image

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.

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

Imports Microsoft.VisualBasic

Public Class SAPGUIScripting

  Sub Main()

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

    Try
      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
    Catch
      Exit Sub
    End Try

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

  End Sub

End Class

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

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

#-Begin-----------------------------------------------------------------

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
  exit
end

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

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

#-End-------------------------------------------------------------------

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