Minor daily fluctuations in safety stock requirements, while they may be accurate reflections of forecast demand and other factors, have no practical significance and may create extra work and confusion in production planning. Learn how to use macros to smooth out the unnecessary bumps in your safety stock calculations.
Key Concept
Companies keep safety stock as a reserve to call upon in times of unexpected high demand or late delivery from their suppliers. How much safety stock to keep on hand is calculated by SAP's Advanced Planning and Optimization (APO), using one of three types of methods: quantity-based methods (SB and MB), demand-based methods (SZ, SM, MZ, and MM), and statistical methods that incorporate forecast error and demand (AS, AT, BS, and BT).
The safety stock calculations standard in all releases of Advanced Planner and Optimizer (APO) are, in most cases, sufficient to cover most business requirements. In specific scenarios, however, these methods should be refined to increase user satisfaction. I'll look at specific requirements for companies that use safety days' supply definitions or one of the extended safety stock methods for their safety stock calculations.
Companies, such as those in the fast moving consumer goods (FMCG) sector,
frequently use the safety stock method SZ, which is based
on a user-defined safety days' supply value. Using this safety days' supply
value (expressed in days), the safety stock calculations ensure that a safety
stock requirement is calculated per period based on this value and the known
future demand.
For detailed explanations of safety stock calculation methods, see my previous articles: "Are Your Safety Stock Levels Optimal? Match Your Method with APO Supply Planning Methodology to Be Sure," "Improve Safety Stock Accuracy with APO's Extended Method," and "Demystify Safety Stock Calculation Methods in PP/DS."
If, for example, the safety days' supply is set to three (i.e., three
days) and the accumulated demand for the next three days is 500, then the result
of this calculation is a safety stock requirement of 500. The known future
demand can be based on sales orders, forecast demand, dependent requirements,
or combinations thereof. Since most demands vary from one day to the next,
the resulting safety stock requirements change accordingly (Figure
1). The same relationship exists when using extended safety stock
methods in combination with daily granularity (AS, AT, BS,
and BT).
Having a different safety stock requirement every day is accurate, but
in most cases rather difficult to work with. Why is this so? Safety stock
requirements may fluctuate only slightly. For example, requirements of approximately
1,000 pieces per day may range from 950 to 1,050, due to smaller changes
in demand (Figure 1). While the display in the SNP Interactive Planning table
looks tidy, the Product View transaction in Production Planning
and Detailed Scheduling (SAP APO PP/DS) appears a bit messy. It displays
the current day's safety stock requirement and then, for each subsequent
day, the delta amount, which can be positive or negative. Figure
2 displays the Product View transaction for a product
with safety stock method AS. The same result would be visible
when using any of the other extended safety stock methods.

Figure 1
Day-to-day safety stock requirement fluctuations
Most production planners can ignore these insignificant fluctuations, but
would probably prefer if they did not affect safety stock requirements at
all. Use one of two methods to ensure that safety stock requirements do not
change by minute amounts from one day to the next. Both solutions actually
change the calculated result of the safety stock determination in a subsequent
step, using a macro.
• Stepping. The safety stock requirements of two consecutive
days are compared. If the change is less than a predefined value, the second
day's safety stock requirement is changed to equal that of the first
day. In the next iteration, that second day is compared with the subsequent
day and so on. The result is less frequent changes in safety stock requirements.
• Averaging. The daily safety stock requirements
over a certain period are averaged. The result is that the same safety stock
requirement is valid for an entire period (e.g., one week). Changes become
effective only on a predefined day of the week.
Create Macros to Adjust Calculations
The flow diagram in Figure 3 displays the order in which
the macros must be executed. You need to define four macros in the planning
book as "default" macros, which means they are carried out anytime
you enter or exit the planning book and when you change data interactively
or in the background.

Figure 3
Process flow for macro execution Click the image above for a larger version
Use transaction /SAPAPO/ADVM or follow Supply
Network Planning> Environment>Current Settings>Macro Builder.
Then, select the planning book and data view for which you want to change
the macros.
Note
The syntax to read a product master field depends on whether the field contains numerical values (use MATLOC) or alpha characters (use MATLOC_C).
The macros are:
Macro 1: Determine workdays. The standard macro to calculate
workdays is part of the SNP planning books delivered with the system.
Macro 2: Safety stock. The standard system comes with
a macro in which the demand used by the safety stock calculations is the
total of sales order/forecast and dependent demand. Replace the macro step
with the one shown in Figure 4 if only sales order demand
should be used.

Figure 4
Safety stock based on sales order demand only
Macro 3: Averaging. Shown in Figure 5 on
the next page, this macro first checks whether the service level defined
in the product master lot size tab is greater than 90 percent. Any other
value would do as well, but, when using the extended safety stock methods,
it is common to define service levels above 90 percent. The macro also checks
for the safety stock method (equal to method BS). Include
other methods if required.

Figure 5
Safety stock averaging
The calculation of the average safety stock is carried out only on Mondays
and then for the next seven days, providing a weekly average. On all other
days, the macro simply copies the previous day's safety stock to the
current day.
The start-up correction is required for the first one to six days, depending
on the day of the week when the macro is run. It populates the safety stock
key figure for all days that are before the first Monday.
You must copy the result of the safety stock calculation back into the
safety stock (planned) key figure, as this is the key figure used by PP/DS.
Not doing so would lead to PP/DS using the initial-not averaged-safety stock.
This task is done in the Copy Back step.
Macro 4: Stepping. Define this new macro to apply the
suggested functionality.
The stepping macro is more complex, since APO macros do not allow the calculation
of a key figure to be followed by a check using an "if" statement
in the same macro step. You must therefore carry out the same calculations
day by day for as many days as required. My suggestion is to limit the number
of days for which you do calculations, for example, for the period of PP/DS
planning horizon.
This macro first checks whether the service level defined in the product
master lot size tab is equal to 50 percent. The macro in Figure 6 does
not check for the safety stock method, but you could incorporate this using
the same logic as shown above.

Figure 6
Stepping calculation for the second day
The macro first calculates the percentage difference between two consecutive
days and stores the result in the auxiliary key figure Safety Stock
Delta. Auxiliary key figures are not saved and have an initial value
of zero.
Figure 6 shows the calculation for the second day. Note that it only runs
on the first day of the planning horizon (one iteration) and potentially
changes the safety stock for day two.
Figure 7 shows the calculation for the third day. Note
that it runs only on the first day of the planning horizon (one iteration)
and potentially changes the safety stock for day three.
As is the case with the averaging method, the result of the stepping calculation
must be copied back into the safety stock (planned) key figure as the last
step of the macro. Refer to Figure 6 for details.
Once the macros are created, ensure that they are all defined as Default
macros by dragging them into the Events section
of the macro builder screen. Figure 8 shows this screen
with the correct sequence of macros.

Figure 8
The final macro sequence
Once these changes have been made, all that is left is to update the product
master, so that the safety stock corrections are carried out as needed. Based
on these definitions, the safety stock levels are adjusted every time the
SNP planning book is accessed interactively or used in a batch-planning run.
The safety stock levels visible in the PP/DS Product View are
also aligned.

Wolfgang Eddigehausen
Wolfgang Eddigehausen is a highly experienced expert in the areas of business process design, re-engineering, and user adaption, as well as process realization in complex SAP-centric environments. He has experience in solution and enterprise architecture and project management (PRINCE2 certified) domains defining enterprise capabilities with a focus on delivering effective and efficient solutions to organizations. Wolfgang's industry knowledge includes public sector, utilities, mining, distribution, general manufacturing, process and steel industries, and consumer goods.
In most roles his task is not only to architect a solution but also to evaluate and define strategic options with a focus on end-to-end solutions rather than systems. This also includes strong emphasis on the user acceptance through an innovative user experience and mobility enablement.
His career includes successful participation and management of projects in Australia, Europe, India, Japan, Singapore, South Africa, Taiwan, and the US. These projects required interaction with all levels of an organization, from the shop floor or office through to the CxO level. Throughout his career, Wolfgang has put emphasis on a holistic approach bringing together people, processes, information, and systems in project management, architecture, and implementation roles.
You may contact the author at we@avox.com.au.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.