Background
Macros are stored development objects that populate key figures in the planning book. They are very important on DP and SNP projects. When standard macros are used, this is simply the development repository. When a pre-existing macro is created (it is often easier to adjust a pre-existing macro rather than start from scratch), or when a new macro is created from scratch, this is a custom development activity. Because a macro is not coding, some people that work in APO may not consider it classical development, however it is. Macros can be designed to do a lot of things, however, when making new macros, they need to be approached within the development context as they have similar maintenance implications to other forms of development.
The Macro Walk Through
The first step is to go to the Macro Builder, and then move the macro from the Macro Depot to the Macro Work area.

I have chosen this macro as it is simple, and is commonly used. Many areas of functionality are actually just macros. The macro calculates a value, which is then stored in a key figure in the planning book. Because this is seamless it appears to users that the key figure is providing a value that is part of some deeper APO functionality, when in fact it is just a macro. This is an advantage and a disadvantage as the only real way to know for sure what is controlling a key figure in the planning book is to check the Macro Builder.

The macro shows as a series of steps. Everything that is created in a macro could be replicated in Excel. In fact Excel is much more powerful than the SAP APO Macro Builder. While Excel is easy to use, the Macro Builder takes a while to get used to, and its development productivity is low. That means that it takes a lot of experience to get good at it, and even experience macro builders produce less output than comparable environments given the same time. Also, SAP macros do not have absolute reference capability. This means that when a macro is moved (up or down in the key figure sequence), the key figure that it was pointing to is changed, and this means that all macro calculated key figures below the adjustment must have their macros changed. This is very different from Excel where formulas to can be moved in an unlimited fashion without causing the references to break.
Also, it should be recognized the term “macro” is used differently here than in Excel. In Excel a macro reverts to a recording that allows Excel to replicate a series of steps. The Macro Builder should probably have been named differently, especially considering the fact that Microsoft had already essentially created the term. Microsoft’s use of the term is not correct either as its official computer science definition is “Computing a single instruction that expands automatically into a set of instructions to perform a particular task.” – Apple Dictionary. If SAP and Microsoft had used existing terminology correctly a macro in Excel would have been called an “instruction recording,” and SAP would have called its macro builder something like “key figure custom calculator.” Terminology that is accurate in this way has the benefit of not having to be internally translated. However, when you are a big and influential software company you don’t have to follow any of the preexisting vocabulary of the English language, and create your own make believe set of terms, and while confusing to other people, it will eventually become used. Making up one’s own terminology from scratch saves large software companies’ countless hours from having to use a dictionary or thesaurus.
Macro Header
The macro header screen is shown below:

As to the third point above, there are several important types of macros that can be created and used.
- Default macro: Carried out whenever the forecasting screen is regenerated, such as when the planning book is opened or closed, or when the planner chooses ENTER.
- Start macro: Carried out whenever the planning book is opened.
- Level change macro: Carried out whenever the planner drills up or down in interactive forecasting.
- Exit macro: Carried out whenever the planning book is saved and closed. – SAP Help
The most frequently used type is the Default macro. The macro type is determined above by entering a value into one of the four boxes in the Macro header screenshot above.
Step 1
Step 1 is a very basic set of options. It provides the name and time line over which the macro should be calculated. It also defined what to do when the value cannot be calculated (either replace with 0, or provide no value). This particular macro only has one step, but on more complex macros there can be many steps, and this is screen and object is more of a step header.

Row
Every macro applies to a row. This screen declares the row’s name or key figure as it will appear in the planning book (the planning book is shown above the macro). The column indicator controls which “columns” or timer periods the macro applies. The other settings on this screen are processing administration.

Cover Calculation and Open Parenthesis
This invokes the “cover calculation” and opens parenthesis in which the calculated values will reside.

The macro builder offers a wide variety of mathematical functions. These can be seen by performing the drop down from this box.

Some are self explanatory, but many are not. In order to find the descriptions so you can choose a function that meets your needs you can find them online.
They are categorized in the following way:
- Mathematical Operators and Functions
- Statistical Functions
- Logical (Boolean) Functions
- Functions for InfoObjects and Planning Books
- Date Functions
- General and Planning Table Functions
- SNP Functions
As you can see SNP has its own category.
The COVER_CALC function is described below:
COVER_CALC(rows for stock on hand ; area (I call this area 1 in this article) for demand from the next period to the end of the time period ; area (I call this area 2 in this article) containing the number of workdays ; demand from the next period to the end of the time period) returns the days supply of a product by considering the current stock on hand, the total demand of subsequent time periods, and the number of workdays in this time period.
For example:
Time span w11 w12 w13 m04 m05
Total demand: 0 20,0 0 25,0 27,5
Stock level 68,7 48,7 48,7 23,7 0
Daysí supply 70 63 57 26 0
Workdays 7 7 7 30 31 – SAP Help
Row Stock on Hand
This declares the row to be calculated by the macro.

This macro simply compares the demand
Area 1
This declares the “from row” and the “to row,” which are both the Total Demand Key Figure (actually its helpful to simply consider the row synonymous with the term key figure).

Area 2
This sets the second area as workdays.

Close Parenthesis
The final part of the macro closes the parentheses, ending this step of the macro.

Conclusion
The macro builder is essentially a clumsy Excel. Like Excel it has many functions, which can be employed. The Days Supply macro is one of the most commonly employed on SNP projects. It allows planners to understand if the stocking level is within appropriate boundaries and is a good way to diagnose the system output. It is also entirely the result of the macro which was described in this post.
In future articles I will walk through more complex macros that have things like if then statements.
References
http://help.sap.com/saphelp_scm50/helpdata/en/f3/852d3af6ecd02ae10000000a114084/content.htm
http://help.sap.com/saphelp_scm50/helpdata/en/1d/310ea4d0ee11d4b2e40050da385632/content.htm