Date post: | 24-Oct-2014 |
Category: |
Documents |
Upload: | ankush-agrawal |
View: | 27 times |
Download: | 1 times |
4.3 Planning Book, Macros and Interactive Planning 51
4.3.2 Macros
Macro functionality supports the data processing from a simple addition of
rows to more complex calculations using a set of standard functions. Even
own coding can be applied in user function macros. The macros are de-
fined specifically for each data view in the macro builder. The macro
builder is accessed via the macro workbench with the transaction
/SAPAPO/ADVM. To avoid the tedious search for one’s own data views,
we recommend to assign a group to the data vies and set a filter for this
group as shown in figure 4.17.
Create and Assign Group
(Ctrl + F6)
Set Filter
Apply Filter
Fig. 4.17.Macro Workbench
The macro builder is called for the data view by double-click onto the row
of the according data view, figure 4.18.
52 4 Demand Planning
Activate all Macros in Data View
Activate Macro
Check Macro
Deactivate Macro or Step
Fig. 4.18.Macro Builder
To create a macro the according elements (starting with the ‘macro’ ele-
ment) are picked from the ‘element’-window on the top left by drag and
drop. After the macro is defined, it has to be activated before it can be
used. By default a macro is directly executable, unless it is inhibited within
the macro definition. If the macro shall be executed at start of the interac-
tive planning, when the level changes or after exit, the macro has to be as-
signed to the according events in the top right window by drag & drop.
Note that frequent execution of macros affects the performance, therefore
the assignment as default macro (i.e. the macro is executed after each ‘en-
ter’) should not be generous.
Since the macro syntax is a bit tricky in some cases, the use of the
‘check’ function is helpful. Especially for the search of errors the deactiva-
tion of macro steps is another useful feature.
•Macro Syntax
A macro consists of one or more steps with one ore more operations each.
The processing area (total, future, past or freely defined) is selected on step
level. The basic syntax – row 1 equals row 2 operator row 3 – is shown in
figure 4.19. In this example the forecast is calculated as an average be-
tween sales forecast and statistical forecast.
4.3 Planning Book, Macros and Interactive Planning 53
Fig. 4.19.Macro – Basic Syntax
An IF-statement requires a control statement and a condition, figure 4.20.
The only difficulty is to place the objects into the right level.
Fig. 4.20.Macro – Syntax for IF-Statement
Another peculiarity is the use of brackets for the functions, figure 4.21.
Make sure there is always a space between the expressions.
Fig. 4.21.Macro – Syntax for Functions
The available macro functions are described in the SAP standard help and
in the notes 403072, 438766, 433166 and others. There is also a collective
consulting note for macro functionality, note 539797.
For intermediate calculation steps an auxiliary key figure can be used
(as row, element or column). There is only one auxiliary key figure avail-
able which is used by all macros. In the macro it is specified whether this
auxiliary key figure is cleared before start.
• Format Macros
Macros help not only to calculate values but can also be used to change the
property of cells like their colour, the displayed symbols, their ability for
input or display only and other. To change these properties the change
scope of the according rows has to be switched to ‘attributes’ (this option
is selected by double clicking on the row in the macro builder).
Macros can be carried out depending whether rows or columns in inter-
active planning are marked, e.g. using the function ROW_MARKED ( row
54 4 Demand Planning
number ). The corresponding function to find out the row number is
MARKED_ROW.
• User Function Macros
With user function macros it is possible to include own routines and tables
into the macro application. User function macros are defined in the menu
path ‘Edit User Function’ within the macro builder. The naming conven-
tion for the user function macros is Z_[MACRONAME]. The interface pa-
rameters VALUE_TAB (TABLE, LIKE /SAPAPO/VALUE_TAB),
F_ARGUMENT (CHANGING, TYPE /SAPAPO/MXVAL) and
F_CALC_ERROR (CHANGING, TYPE C) are set by default. Additional in-
terface parameters can be selected – mainly regarding the format of the
planning book – when creating the user function in the macro builder. The
parameter VALUE_TAB is used to transfer numbers and strings from the
planning book to the function, whereas the parameter F_ARGUMENT is
used to transfer the result of the user function back to the planning book.
The user function with the according interface definitions has still to be
created with the transaction SE37.
• User Exit Macros
User exit macros allow to process a whole grid – in contrast to user func-
tion macro.
• Effects of Changes in the Data View
If a change in the sequence of the key figures in the data view occurs, the
logic of the macros is not affected. Before APO 4.1 the selected rows in
the macro were related to their position in the data view and not to the
name of the key figure. Therefore a change in the sequence of the key fig-
ures – e.g. the insertion of a new key figure – had led to a disturbance of
the macro semantic.
• Copy Macros
There are two ways to copy macros. To copy a macro within a data view,
select the macro and use right mouse Copy to Clipboard, then select any
macro and use right mouse Insert From Clipboard. The other way is to
import the macros from another data view via the menu path ‘Edit Import
Macro’.
•Macro Execution
Macros are used in interactive planning by manual request from the plan-
ning book or triggered by events like the start of the interactive planning,