SAP Intelligent Enterprise - Machine Learning with SAP EWM
Updated: Jun 18, 2020
The primary focus of this blog post is to showcase how Machine Learning can be used with SAP EWM to unlock new business value
To narrow down further, this blog post explains how Machine Learning “Association Rule” algorithm can be used to optimise the standard “Putaway Strategy” in SAP EWM.
This blog covers the following aspects:
Introduction to Machine Learning
Understanding Association Rule in ML
SAP EWM Putaway Strategy
Benefit of using Association Rule in SAP EWM
ML Implementation Steps
Snapshot of Full Python Script
Translating Results into SAP EWM
Tools used while building this use case
How to generate Machine Learning Use Cases?
Let us say that we are storing Bread, Egg & Milk next to each other in a warehouse so that picking is efficient since customers mostly buy all three items together (refer Fig 1.0).
Now, imagine that a new product (Butter) has arrived in the warehouse and it is associated with Bread, Egg, and Milk, hence it must be kept next to each other.
How do we solve these constantly evolving complex product associations so that stocks of these products are kept next to each other for efficient picking at scale?
If we have to build logic in SAP ABAP, we need to write complex logical expressions on the sales data to figure out which items are closely associated, and then we need to maintain the results in the product master data so that we can use that to influence the putaway strategy. We can certainly write the code in ABAP if the warehouse is handling only tens of products.
Now imagine the same situation with hundreds of thousands of different products. We need to re-write the logic in ABAP for new association & this would mean massive load on the system, code maintenance activity, and master data activity. Certainly, scaling becomes a bottleneck.
Now, let us add a new dimension to the above case. Imagine that the warehouse is interested in implementing an image recognition robot to detect a mixed pallet containing Bread, Milk, Butter & Shampoo, and then send the pallet for deconsolidation (Milk, Bread & Butter go next to each other and Shampoo into different Pallet & a different Storage Area). There is no way we could pass the image input to ABAP and integrate it with our analysis. Then what is the alternate way to achieve optimized picking at scale with least maintenance? The answer is Machine Learning.
What’s Machine Learning?
In traditional programming, we know how to build rules using addition, multiplication, subtraction, logical expression, etc. These rules can take inputs and process them to provide an answer. But it needs constant effort to change/maintain the rules if there are changes in either input or expected output.
To deal with scenarios where traditional programming becomes too unwieldy to build these rules, an alternative approach is used.
In this approach, the program can build a rule automatically based on the huge amounts of input data and pre-determined answers for these inputs. The more input and answers we provide to the program, the better it learns and creates more accurate rules. This simple principle of a program constantly learning and adjusting its rules to provide increasingly accurate answers for an input question is called machine learning
Understanding the Association Rule in ML
“Association Rule analysis is a technique to uncover how items are associated to each other”
Analogy: When we go grocery shopping, we often have a standard list of things to buy. Each shopper has a distinctive list, depending on one’s needs and preferences. Understanding these buying patterns can help to increase sales in several ways. If there is a pair of items, X and Y, that are frequently bought together:
Both X and Y can be placed on the same shelf, so that buyer of one item would be able to buy the other one easily (Shortest Pick Path in EWM terms)
Recommend associated products to customers during sales order entry
In the below example we can see that a person buying Bread & Egg would most probably buy milk,
SAP EWM Putaway Strategy
Method of performing the putaway process from a business point of view where the system searches for a suitable storage bin within a storage type. You map putaway strategies in the system using various settings, with the storage behavior and the putaway rule for the storage type. More details can be found in the below SAP documentation
Benefits of using Association Rule in SAP EWM
The immediate benefit is that the picker in the warehouse can pick the most relevant items, which would lead to the shortest pick path. Since these items are recommended based on buying patterns of the customer, we could also feed this relevance back to user while booking Sales Order in SAP which eases the order booking step for customers (Similar to the way we get recommendation while shopping in Amazon)
Solution Architecture Overview:
In the below picture we can place the ML solution in the cloud (to take advantage of cloud capabilities). Sales order data can be extracted directly from the SAP system and fed into the ML model and vice versa
Fetch Sales order data (VBAK Table) from S/4HANA system into an excel input file (In production, this can be a weekly or monthly batch input to cloud ML server based on the forecast period applicable to business)
Feed Excel file input to ML Model, generate results (Excel is only for prototype development, in production this can be a direct integration between systems)
Pass the ML results in terms of ranking into SAP EWM (Direction Integration or can be updated via a BAPI)
SAP EWM stores the results into a Z field in product master
EWM uses ranking data during putaway to influence standard EWM putaway strategy
Ranking in EWM: Ranking is based on the highest LIFT value determined as part of the AR algorithm. This means, higher the lift the higher the chances of association, which means we need to assign the highest ranking to these items associated together. Hence the ranking would be treated as #1 and so on for the rest of the products. If the ranking is #1, then that associated product must be given preference to occupy bins first before a second-rank candidate can occupy it, hence the sort sequence is influenced in the putaway list to follow the ranking
Group Ranking: All products which contain same ranking (let’s say 1st rank is provided to 2 products out of 10), then it means only those products with the same ranking are treated as associated together, hence can be kept next to each other in the bin or shelf and also the sorting would work as required in the putaway sort sequence. Hence, the relationship between ranks is only for the purpose of sorting and not to measure/understand the difference between the ranks
Sales Data is read from SAP S/4HANA
Determine Association Rule and update SAP EWM product master with group ranking for each product groups
New Bin Sorting Rule is determined in EWM (This sorting is not the same as putaway sort sequence)
Determine and assign ranking for each item in the putaway list based on product master ranking. Ex: All 1st rank products are preferred to store next to each other
First determine the destination bin for the product with common ranking, then determine the next available bin for the second product following standard but while determining the second bin, choose the one closest to the first product and so on for next ranking products in the putaway list
Do not override the standard putaway strategy, instead only apply to sort on top of standard putaway rules
Provide Switch to activate AR at the putaway rule level (The option for using this new rule should be at the putaway rule level. Hence, putaway rules which are only active with this new sorting would use the group ranking values, else it would follow the standard approach. Hence the switch must be placed at this level)
Bin Determination follows standard putaway rule, however, the preference of selecting the available bins for 2nd rank and so on would be sorted based on this new sort rule
Enhance “BAdI: Change Storage Type Search Sequence and Putaway Rule” to influence this new sorting
Machine Learning Implementation Steps:
The primary aspect of implementing ML modeling is to arrive at a sequence of steps that will lead to the desired result. In this case, the result would be getting the most quality association between products. You can also use other association rule algorithms such as Max-Miner etc, but for simplicity, we have implemented using only one of such algorithm. APRIORI algorithm can be used either as supervised or unsupervised. In this use-case we have used it for unsupervised approach since the sales data we are using is purely statistical and does not require any training period
Download VBAK table Data into excel with products ordered for each sales order
In the above file, we have considered the sales order number as a unique key, which holds 3-line items that are associated together. The excel file contains 23k+ unique records (You can download it from GitHub - https://github.com/RaghavNaiduR/SAPEWMMLAssociationRule )
Load data into Python
Excel file is loaded from the local system. (Please change the file path to your local path in the script when you run the script in your system)
nan: in ML, empty values are filled with “nan” and these are considered as null values and influences the algorithm, hence it is required to remove these junk values after loading into ML data frame
Apply Association Rule
Association Rule is part of APRIORI library in ML. You need to have these libraries preinstalled before you can call it in the program. APRORI algorithm mainly uses probability and permutation logic.
APRIORI uses a "bottom-up" approach, where frequent subsets are extended one item at a time (a step is known as candidate generation), and groups of candidates are tested against the data. The algorithm terminates when no further successful extensions are found
You can find several documentations on AR in the internet and also wiki
Snapshot of Full Script:
only first 3 output is shown here, you should get results for all the combinations
Results are into 4 categories,
Rule: Comparison of two products Support: The number of transactions that include items in the DPC1002 and DPC1013 parts of the rule as a percentage of the total number of transactions. It is a measure of how frequently the collection of items occur together as a percentage of all transactions Confidence: The confidence level for the rule is 0.66 which shows that out of all the transactions that contain DPC1002, 66.66% of the transactions also contain DPC1013 Lift: Lift basically tells us that the likelihood of buying a DPC1002 and DPC1013 together is 9.66 times more than the likelihood of just buying the DPC1013. Higher the lift, higher the chances
Translating result in EWM ranking
Assign Ranking: For simplicity, we have chosen “Lift” as the most important variable. Hence, sort Lift Value with the highest number (Descending Order)
In the above result, we can see that the product DPC1003 & DPC1012 has the highest likelihood hence rank #1, same as goes for other products. We can also notice that the product DPC1003 is repeated twice in the list, which means it has a good likelihood with two of the other products. In this case, product DPC1003 retains rank #1, wherein the product DPC1012 gets rank #2 and DPC1010 rank #3.
You can also consider the other two variables in the sequence of its influence and build a similar ranking portfolio.
Group Ranking: Assign common Rank for groups of associated products
[If only one product exist for each rank in a warehouse task list, as shown in Fig 15, then EWM ignores ranking, because there is no guarantee that two different ranks are associated (unless rule says)]
Measuring the Success:
It could be possible that the results are not completely true on the first instance and if we do not have reference to correct values then it might lead to a wrong interpretation and putaway. Hence, we can improve the results by below two methods,
By shifting to Supervised approach, we can train the algorithm initially for 6 months or so and then deploy it for production. This would ensure that the error factor is already reduced during the training period before it is deployed to production
One way is to get Real-Time feedback from EWM system. The whole purpose of applying AR in EWM is to derive an efficient picking, which means a product which was associated and kept next to each other must have got get picked up during the outbound planning period if it doesn’t then something is missing. This could be due to wrong association logic and hence by providing a feedback loop to ML model on the success rate, the algorithm can improve continuously and lead to quality results and this approach can be at scale (real-time)
Tools used while building this use case
Anaconda Environment Local (https://www.anaconda.com/products/individual)
Notepad - Jupyter (part of Anaconda)
SAP EWM model system
SAP 1809 model system
Excel Data File & Python script can be downloaded from the below link (https://github.com/RaghavNaiduR/SAPEWMMLAssociationRule )
Missing Piece Below Items are still under research & development and will be made available in future,
BAPI or an efficient method to pass ranking from ML model to EWM
Enhancement of SAP EWM BADI to sort warehouse task based on ranking
How/What are the ways to connect cloud ML infra natively with SAP EWM module
Closure: Los geht's (let’s go/way to go) ……. SAP Intelligent Enterprise!
By now you might have got a fair idea on how to develop and implement ML use cases with SAP EWM. A use case should touch all important aspects of business such as value, viability, scalability, and implementation cost.
How to generate Machine Learning Use Cases?
Generating and implementing an ML use case requires connecting dots across business and technology. If you wish to know some of the basic guidelines & “Food for Thought” to generate Machine Learning use cases which can be used with SAP EWM solution, please comment “YES”.
If I receive sufficient demand, I will post my next blog on this topic.