SAP Automation for Retail
Design RPA solutions using Visual Basic scripts built with SAP GUI Scripting Tool
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.
You can find it on SAP GUI Home Page
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
Output
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
Output
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
- First part: Setting Up Connection with SAP GUI
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
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.
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:
- Set Up Connection with SAP GUI: adapt this code to be replicated in Excel VB
- 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
Purchase Order Creation:
SAP Automation for Retail — PO Creation
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.