SAP Automation for Retail

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

Samir Saci
DataDrivenInvestor

--

SAP Automation for Retail
SAP Automation for Product Listing — (Image by Author)

Automating SAP processes can be a game-changer for businesses looking to streamline their operations and increase productivity.

In this article, we’ll explore how automation using Visual Basic and Python can benefit the retail industry and share examples of basic manual task automation for SKU listing, purchase order creation, and goods transfer order extraction using the SAP GUI scripting tool.

Introduction

SAP is a powerful enterprise software suite that can help businesses streamline their operations and increase productivity.

However, many businesses still rely on manual processes to complete tasks within SAP, which can be time-consuming and prone to errors. This is where automation comes in.

By automating repetitive tasks within SAP, businesses can free up their employees to focus on higher-value tasks and improve their overall productivity.

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 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 ToolIf 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 ToolIf 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 ToolIf 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 detail in the next article to understand it.

2. Second part: Performing Action

# Test 1session.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

Follow me on medium for more insights related to Data Science for Supply Chain.

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

Purchase Order Creation:
SAP Automation for Retail — PO Creation

If you are interested in Supply Chain Analytics, have a look at my website

References

--

--

Top Supply Chain Analytics Writer — Follow my journey using Data Science for Supply Chain Sustainability 🌳 and Productivity ⌛