SAP Automation for Retail

Design RPA solutions using Visual Basic scripts built with SAP GUI Scripting Tool

SAP Automation for Retail

Design RPA solutions using Visual Basic scripts built with SAP GUI Scripting Tool

Article originally published on Medium.

I. What is Robotic Process Automation?

Management Consulting firm Deloitte defines Robotic Process Automation (RPA) as using “software, commonly known as a ‘robot’, to capture and interpret existing IT applications to enable transaction processing, data manipulation and communication across multiple IT systems.”

Like many Automation Enthusiasts (or Lazy Engineers), I define it as “finding a way to automate boring and time-consuming tasks to create more time for working on analysis and design solutions that are adding value to your project.”

II. Automation of SAP using SAP GUI Scripting

I needed to perform numerous fastidious manual tasks with limited time. In this series of articles I will share several examples of basic manual tasks automation:

  • 1. SKU Listing: link an article to his assortments (Location: Warehouse or Store)
  • 2. Purchase Order Creation: a document used to request items or services from a vendor at an agreed-upon price
  • 3. Goods Transfer Orders Extraction: Goods transfers allow you to map transfer deliveries in the system in one data entry transaction

Our Tool: SAP GUI Scripting
SAP GUI includes a recording tool, like Microsoft Excel Macro, to record tasks and convert them into Visual Basic Code.

Record and Playback tool of SAP GUI to record tasks performed — (Image by Author)

You can find it on SAP GUI Home Page

SAP GUI Scripting Tool Menu — (Image by Author)
Experiment 1: Launching a Transaction

To understand the Recording tool, we will perform two simple tasks and analyze the recording tool outputs. Based on these examples, we can get the logic behind it and try to adapt it to any task we plan to automate.

Let us start with the simple task of launching a transaction

Launching MM43 Transaction Code (Display Material) from SAP GUI Home Page — (Image by Author)

Output

#Visual Basic Script Exported by Recording Tool
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If

If Not IsObject(connection) Then
Set connection = application.Children(0)
End If

If Not IsObject(session) Then
Set session = connection.Children(0)
End If

If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "MM43"
session.findById("wnd[0]").sendVKey 0
Experiment 2: Filling a Form

Let us now have a look at how to fill out a form

Form filling example — (Image by Author)

Output

#Visual Basic Script Exported by Recording Tool

If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If

If Not IsObject(connection) Then
Set connection = application.Children(0)
End If

If Not IsObject(session) Then
Set session = connection.Children(0)
End If

If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If

session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").text = "100607255"
session.findById("wnd[0]/usr/ctxtRMMW1-EKORG").text = "WXYZ"
session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").setFocus
session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").caretPosition = 9
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").caretPosition = 9
session.findById("wnd[0]").sendVKey 0
Results Analysis: Visual Basic Code

Looking at the two outputs we can see similarities in the code

  1. First part: Setting Up Connection with SAP GUI
#Visual Basic Script Exported by Recording Tool

If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If

If Not IsObject(connection) Then
Set connection = application.Children(0)
End If

If Not IsObject(session) Then
Set session = connection.Children(0)
End If

If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If

After looking at SAP GUI Scripting Documentation, we can understand that this part of the code is to set up a connection with the GUI. We’ll go further in details in the next article to understand it.

2. Second part: Performing Action

# Test 1
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "MM43"
session.findById("wnd[0]").sendVKey 0

“MM43” in line 2 is showing us that this line is linked to what is typed in the Transaction Name Field.

# Test 1
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").text = "100607255"
session.findById("wnd[0]/usr/ctxtRMMW1-EKORG").text = "WXYZ"
session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").setFocus
session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").caretPosition = 9
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").caretPosition = 9
session.findById("wnd[0]").sendVKey 0

“100607255” in line 3 and “WXYZ” in line 3 are showing us that these lines are linked to what is typed in “MM43” Form Fields.

III. Conclusion and Next Steps

Looking at these two simple examples we can foresee the potential of SAP GUI Recording Tool in designing scripts to Automate Tasks.

In the next part we’re going to see how:

  1. Set Up Connection with SAP GUI: adapt this code to be replicated in Excel VB
  2. Scripting to Perform Action: Data Input, Pasting Values to Clipboard and Data Export

In the next two parts, we study how to automate

SKU Listing
Operations that link an article to its assortment

SAP Automation of Product Listing for Retail
Automate Product Listing in SAP with SAP GUI Scripting Tool using Visual Basic

Purchase Order Creation:
SAP Automation for Retail — PO Creation

SAP Automation of Orders Creation for Retail
Automate Purchase Order Creation in SAP with SAP GUI Scripting Tool using Visual Basic

About Me

Let’s connect on Linkedin and Twitter, I am a Supply Chain Engineer that is using data analytics to improve logistics operations and reduce costs.