# Leveraging SCM APO Forecasting by using external web services

Have you ever thought to use the latest algorithm in SCM APO without developing it first? With SOA you can easily integrate any kind of forecasting algorithm which is offered as an web service.

In the following we will show the basic steps to consume an external web service in SAP SCM APO. In particular we will demonstrate how to access an external forecasting algorithm of the 3^{rd} party statistical package “R” from SCM APO Demand Planning. Therefore, this is an example for using external algorithms or other web services in your SCM business processes in an SAP SCM enviroment by using SOA (Service Oriented Architecture) techniques. This “R” software package is open source and was designed and built at universities. It is a language and environment for statistical computing and graphics. “R” provides a wide variety of statistical (linear and nonlinear models, classical statistical tests, time-series analysis etc.) and graphical techniques, and is highly extensible. Of course SAP SCM APO already contains state of the art forecasting algorithms. Nevertheless, standard software can never cover every functionality. There are the following reasons to go this way:

- Use of newest developments in science, the most advanced algorithms (maybe even industry-specific algorithms)
- Improve accuracy of the forecasts with external algorithms
- Use of a forecasting algorithm for which no parameters have to be set by the planner. Therefore no “calibration” of parameters is necessary.
- Additional (statistical) functionality: External forecasting algorithm not only delivers forecast results but also confidence intervals. This is the value range in which the forecast falls with a defined probability (e.g. with 90% probability the forecast value lies between 203 and 215).

Instead of rebuilding the algorithms in ABAP, integrating the algorithms from an off-the-shelf statistics tool like the “R” package has the following advantages:

- New, powerful algorithms are regularly developed by the academic world
- Algorithms might already have an optimized implementation making them more efficient
- The quality of different algorithms can be evaluated for the specific customer situation without developing several algorithms and then only using one of them. One algorithm can be quickly exchanged with another one.
- Re-building the algorithms can be a complex task and lead to a long testing phase due to errors
- Save time in the project by having a quick standard method to access external algorithms instead of having a more complex development for the algorithm

In our case two different algorithms from the “R” software package should be used. We will use two different techniques to consume them in SCM APO in order to show different possibilities how web services can be called from SCM APO.

- The first algorithm is a new implementation of an exponential smoothing forecasting method based on so-called “state space models”. It will be called via a BAdI.
- The second algorithm is a historical baseline smoothing algorithm. It is used to improve the evaluation of promotions with a more consistent historical baseline of (past) sales. The proposed method to estimate the baseline is a smoothing method called LOESS, more descriptively known as locally weighted polynomial regression. The generated historical baseline of sales (determined in SCM APO by calling the web service) can be compared with actual sales for the same period in order to evaluate the effectiveness of promotions (in BW or CRM).

Details on the solution design

As you can see in the following illustration,

- the “R” package is deployed on Windows server,
- one .NET web service is provided for each algorithm
- and on the SCM APO box a BAdI and a macro (+ function module) are developed to consume the web services.

The exponential smoothing forecasting algorithm is called via the standard Interactive Forecasting transaction (invoked by the BAdI for external forecasts). This fills the values for the standard key figures in the planning area from which they support the following planning process. In contrast, a macro is ran in background for the historical baseline smoothing algorithm. It fills a customer-defined key figure in the planning area for the historical baseline at the most detailed aggregation/disaggregation level. In the subsequent process, the historical baseline is copied into an InfoCube of the external BW. Afterwards, CRM can use this historical baseline data from the external BW to assist in future promotion decisions.

If you want further insight of how it was done and how SOA can leverage your SAP SCM installation, do not hesitate to contact us.

*http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/u/48526 [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] is a consultant for Supply Chain Management and SOA at SAP Consulting.*

This blog post is extraordinary exciting for APO consultants. Could we have a sample implementation of the corresponding BAdI to demo how to consume web services to give values to key figures in the Interactive Planning?

Thanks for the post,

best regards,

Ádám