Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Active Contributor
This blog post is a part of SAP Conversational AI Tutorial Challenge 2021. This tutorial explains how to build a chatbot which helps to simplify and automate supply chain planning tasks. We will be looking at a specific scenario which deals with rough cut capacity planning.


How Digital Assistant makes planner’s job easy?


Identifying and removing resource bottlenecks are one of the critical planning tasks. In the process, planners may need to navigate through multiple screens to check utilization, capture, and share reports with other stakeholders, update the numbers and re-generate the plan to assess if bottlenecks are removed.

Using Digital Assistant - powered by SAP Conversational AI, planners can get a summarized view of  constraints in the supply chain network so that they can quickly collaborate with stakeholders to mitigate supply shortage risks without navigating through multiple screens. They can also update the capacity details and re-generate supply plan through chatbot in a seamless manner.

Here’s how it will work –

Behind the scenes


There are multiple tools and technologies working in tandem to simplify planner’s task at hand. Let’s have a look :

  1. SAP Conversational AI – Dialogue engine to identify intent, trigger skills and actions.

  2. SAP Integrated Business Planning – OData services to schedule planning algorithm, read and write planning data

  3. SAP Cloud Platform – Python app to convert data to insights

The chatbot can be deployed to any channel for e.g. MS Teams or SAP Jam where a user can swiftly communicate with the bot to perform various planning tasks.


Connecting the dots


Step 1 : Configure data integration scenarios in SAP IBP


We will use following out-of-box communication scenarios in SAP IBP –

  1. Job Scheduling API (SAP_COM_0064) : This API is used to schedule application jobs in SAP IBP through external systems. Using this API, users can run supply planning algorithms without logging into IBP system.

  2. Extract Analytics Data (SAP_COM_0143) : This allows external systems to extract master and transactional data records from IBP.

  3. Planning Data Integration (SAP_COM_0720) : This service allows an external tool to upload data into SAP IBP.

These communication scenarios are used in maintaining communication arrangements like shown below which contains information on inbound services, authentication, and the scenario under use. Create other arrangements as well for rest of the two communication scenarios mentioned above.


Step 2 : Build an app to fetch data from SAP IBP and convert it to insights


A webhook is created to extract data from SAP IBP and convert raw data to insights. Refer this detailed tutorial on how to build and deploy python webhook on SAP cloud platform.

A similar webhook with additional functionalities is used for this use case. The application is deployed on SAP Cloud Platform. Below code explains how the application extracts available capacity and resource utilization data from SAP IBP basis user input on plant details in SAP Conversational AI.
url = "$select=RESID,LOCID,PERIODID4,ZUTILIZATIONPCT1&$filter=RESID eq '" + resid.upper() + "' and LOCID eq '" + locid + "' and ZUTILIZATIONPCT1 gt 0&$format=json"

url2 = "$select=RESID,LOCID,PERIODID4,ZCAPASUPPLY&$filter=RESID eq '" + resid.upper() + "' and LOCID eq '" + locid + "' and ZCAPASUPPLY gt 0&$format=json"

r = requests.get(url,auth=('XXXX', 'XXXXXXXXX'))
planning_data = json.loads(r.content)
cap_uti = list(map(float,pluck("ZUTILIZATIONPCT1",planning_data["d"]["results"])))

r2 = requests.get(url2,auth=('XXXX', 'XXXXXXXXX'))
planning_data2 = json.loads(r2.content)
cap_sup = list(map(float,pluck("ZCAPASUPPLY",planning_data2["d"]["results"])))


The next step is to plot the chart using acquired json data from planning system. We have not used any third-party service (for e.g. to generate the chart. It is created in the same Python application deployed on SAP Cloud Platform so that business data always reside within client's own ecosystem.

There are many libraries available in Python for data visualization. Out of which, Matplotlib is used here to create combination chart for available supply and utilization over the period. It is very flexible to use and one can format charts as needed.
pd1 = pd.DataFrame({
'cap_sup' : cap_sup,
'cap_uti' : cap_uti})

a1 = pd1[['cap_sup']].plot(kind='bar',color='springgreen', width = 0.8)
a2 = pd1['cap_uti'].plot(color='black',secondary_y=True,linewidth = 2)


To send above chart to SAP Conversational AI, below lines of code convert the chart to base64 format and sends it as a json response to SAP Conversational AI. In step 3, we will see how to consume this data.
s1 = io.BytesIO()
plt.savefig(s1, format='png', bbox_inches="tight")
s1 = base64.b64encode(s1.getvalue()).decode("utf-8").replace("\n", "")
s1_final = "data:image/png;base64," + s1


Once application is built and deployed on SAP Cloud Platform, make sure the instance has started successfully.


Step 3 : Build a chatbot in SAP Conversational AI platform


Here we will create intents and entities, build skills, and assign actions for following tasks.

Task 1 : Schedule a job


Create an intent which identifies user wants to schedule an application job. This should trigger job intent skill shown below. In this skill, list of jobs is maintained.


Once job scheduling intent is detected, system triggers a sequence of skills to trigger a job. User can select the job to be executed from the list as shown below.










Follow-up skill and action triggers an API service to schedule the job selected by user.


Task 2 : Generate a report


Create an intent which identifies user wants to generate a report. For this use case, we are modeling only one report – resource utilization. Here, a webhook is configured which connects to the app built in step 2. As an input, user sends plant location for which resource utilization summary to be generated.


In the response, python app first extracts data from SAP IBP, converts it to the chart and base64 format which is consumed in SAP Conversational AI. Planner can save the chart image offline or send it via email/MS Teams to plant manager.


Task 3 : Update planning data


Once plant manager finds a way to increase resource capacity (for e.g. adding another shift), the planner now wants to update the capacity details in SAP IBP. Here, we are using Planning Data Integration API in SAP IBP to update the resource capacity.


It is required to send details like resource, plant, new capacity, and date with the POST request. These details are added in Body of the request.


Once new resource capacities are updated in SAP IBP, user can take a re-run of planning algorithm to check if constraints are vanished.


And there you go!!


Here is a quick demo of how the chatbot works.


Thanks for reading. Hope you find this blogpost helpful!! Share your thoughts on what aspects of supply chain planning processes can be improved using SAP Conversational AI.
Labels in this area