You are on page 1of 85

Advanced Macros

Release 310

ADDON.NDAPODP

SAP Online Help

07/04/02

Copyright
Copyright 2002 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, WINDOWS, NT, EXCEL, Word, PowerPoint and SQL Server are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix and Informix Dynamic ServerTM are trademarks of IBM Corporation in USA and/or other countries. ORACLE is a registered trademark of ORACLE Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, the Citrix logo, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, MultiWin and other Citrix product names referenced herein are trademarks of Citrix Systems, Inc. HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. JAVA is a registered trademark of Sun Microsystems, Inc. JAVASCRIPT is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. SAP, SAP Logo, R/2, RIVA, R/3, SAP ArchiveLink, SAP Business Workflow, WebFlow, SAP EarlyWatch, BAPI, SAPPHIRE, Management Cockpit, mySAP, mySAP.com, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. MarketSet and Enterprise Buyer are jointly owned trademarks of SAP Markets and Commerce One. All other product and service names mentioned are the trademarks of their respective owners.

Advanced Macros

401

SAP Online Help

07/04/02

Icons
Icon Meaning Caution Example Note Recommendation Syntax

Typographic Conventions
Type Style Example text Description Words or characters that appear on the screen. These include field names, screen titles, pushbuttons as well as menu names, paths and options. Cross-references to other documentation. Example text EXAMPLE TEXT Emphasized words or phrases in body text, titles of graphics and tables. Names of elements in the system. These include report names, program names, transaction codes, table names, and individual key words of a programming language, when surrounded by body text, for example, SELECT and INCLUDE. Screen output. This includes file and directory names and their paths, messages, source code, names of variables and parameters as well as names of installation, upgrade and database tools. Keys on the keyboard, for example, function keys (such as F2) or the ENTER key. Exact user entry. These are words or characters that you enter in the system exactly as they appear in the documentation. Variable user entry. Pointed brackets indicate that you replace these words and characters with appropriate entries.

Example text

EXAMPLE TEXT Example text <Example text>

Advanced Macros

401

SAP Online Help

07/04/02

Advanced Macros ............................................................................................................. 6 MacroBuilder Screen..................................................................................................... 8 Advanced Macro Structures........................................................................................ 9 Using Macro Elements...........................................................................................12 Using Macro Tools.................................................................................................15 Definition of Macros in the MacroBuilder .................................................................17 Semantic Check for Macros....................................................................................19 Menu Functions for Macros ....................................................................................21 Operators and Functions in Macros ........................................................................22 Mathematical Operators and Functions ................................................................24 Statistical Functions ...........................................................................................27 Logical (Boolean) Functions ................................................................................31 Functions Related to Info Objects and Planning Books .........................................32 Multilevel Functions in the Supply Chain Network..............................................44 Date Functions ...................................................................................................46 General and Planning Table Functions ................................................................51 Attributes of Macro Elements..................................................................................58 Standard Macros ...................................................................................................60 Forecast Analysis Using Macros....................................................................................61 Example of a Macro Alert ..........................................................................................63 Translating Advanced Macros .......................................................................................64 Business Cases for Macros...........................................................................................65 Example of a Macro to Convert Percentage Values.....................................................66 Make 2nd Column Read-Only/Make 2nd Column Ready-For-Input...............................67 Make 2nd Column Invisible/Make 2nd Column Visible .................................................68 Hide All Columns <> December (Year View)...............................................................69 Set/Delete Icon for Row 1 (All Planning Objects).........................................................70 Change Foreground Color to Red for Negative Values ................................................71 Calculate Cumulated Values: Year-to-Date.................................................................72 Calculate and Round % Difference.............................................................................73 Info Message If Sum > 1000 ......................................................................................74 Trigger DB Alerts If Value > 0 ....................................................................................75 Calculate Sum of 3 Successive Periods Using Rows/Areas .........................................76 Using Nested Functions ............................................................................................77 Calculate Only for Periods Before 01/01/2000.............................................................78 Using the Number of Workdays for the Calculation......................................................79 Using Actual Currency Conversion Factor...................................................................80 Get Missing Forecast Entries from User .....................................................................81 Using Values from Different Periods ...........................................................................82

Advanced Macros

401

SAP Online Help

07/04/02

Adjust Forecast Depending on LifeCycle ....................................................................83 Values of Row 1 Shift by Offsets in Row 2..................................................................84 Submit a User-Specific Report ...................................................................................85 Trigger Alert Based on Reorder Point .........................................................................86 Popup With Standard Deviation of Forecast Key Figures .............................................87

Advanced Macros

401

SAP Online Help

07/04/02

Advanced Macros
Use
Use advanced macros to perform complex calculations quickly and easily. Macros are executed either directly by the user in interactive planning or automatically at a predefined point in time during a background job. The definition of macros is optional. You do not have to write macros yourself. Some stock level and days' supply macros are also delivered with the standard SNP planning books. You can create your own planning book for SNP using one of the existing books as a template, and copy the standard macros to the new book.

Integration
You create an advanced macro either when creating or chaning a planning book in Customizing, or in design mode of interactive planning. You can define a macro either for an entire planning book or for a specific data view.

Prerequisites
1. 2. 3. You have created a planning area. You have created a planning buckets profile. You have created a planning book with at least one data view.

Features
You can: Control how macro steps are processed through control instructions and conditions. Build a macro consisting of one or more steps. Control how macro results are calculated through control instructions and conditions. Use a wide range of functions and operators (see Operators and Functions in Macros [Page 22] ). Define offsets so that, for example, the result in one period is determined by a value in the previous period. Restrict the horizon in which the macro is executed to a specific period or periods. Write macro results to either a row, or a column, or a cell. Write the results of one macro step to a row, column, cell or variable, and use them only in subsequent iterations, macro steps or macros. Trigger an alert in the Alert Monitor showing the outcome of a macro execution.

Advanced Macros

401

SAP Online Help

07/04/02

To create authorizations for the creation and execution of macros, choose Tools Administration User Maintenance Roles from the SAP Easy Access menu. For more details see Authorization in Supply Network and Demand Planning [Ext.].

Advanced Macros

401

SAP Online Help

07/04/02

MacroBuilder Screen
Definition
When defining advanced macros, you work in a special desktop environment known as the MacroBuilder.

Use
To open the MacroBuilder, do one of the following: From the SAP Easy Access menu, choose Demand Planning Environment Current Settings MacroBuilder. From design mode of interactive demand planning, choose MacroBuilder => Planning book or MacroBuilder => Data view .

Structure
The MacroBuilder consists of the following screen areas: Macro elements [Page 12] in a tree on the top left Depot with parked macros on the bottom left Keep all macros that you are not currently editing in the depot. This has performance advantages: the macros tree containing the macros that you are currently editing works faster. Demand planning table in the top center Macro tree with the macro tools [Page 15] in the bottom center To see the attributes of any item in the tree, double-click on the item. Standard macros [Page 60] on the top right Clipboard on the bottom right

For more information on how to edit macros, see Definition of Macros in the MacroBuilder [Page 17].

Advanced Macros

401

SAP Online Help

07/04/02

Advanced Macro Structures


Definition
An advanced macro consists of one or more macro steps. To define the conditions under which individual macro steps are carried out, you use control structures. Each macro step consists of one or more calculations. To define these calculations in the macro tree, you use calculation structures.

Structure
A macro can comprise of up to 4 levels. The graphic below shows a simple example :
1 Macro 2 3 4 Step Result Argument Level

Macro Title Name of step Row row name1 (validity) = Row row name2 (validity) Operator/function Row row name3 (validity)

Macro level Step level Result level Argument level

1.

Macro level This is the top level and consists of the macro name only.

2.

Step level At this level you can enter either a step or a control structure. A macro must contain at least one step. A step contains a calculation or series of calculation. A step is also an iteration loop. The calculation or operation is repeated over a predefined period, if you work with rows.

3.

Result level At this level you specify the macro object to which the results of a calculation or operation is written. This can be a key figure in the planning book, or an element in the auxiliary table that you use to store an intermediate result temporarily. At this level you can also enter control structures, action boxes, documents, procedural messages, or alerts.

4.

Argument level At this level you enter the calculations or operations. Similarly conditions are defined at argument level, if the control structure is entered at result level.

The graphic below is a concrete example of the structure above. The macro calculates the adjusted forecast by adding the manual adjustment to the sales forecast. This is done for the period of one year in the future.

Advanced Macros

401

SAP Online Help

07/04/02

Calculate adjusted forecast Calculate (12 Iterations : M01.2003 ; M 12.2003 ) Row Adjusted forecast (frm M01.2003) = Row Sales forecast (frm M01.2003) + Row Manual adjustment (frm M01.2003)

Macro level Step level Result level Argument level

Control Structures
As mentioned above, you use control structures at either step level or result level. In the first case you can control structures to decide which step to execute depending on which conditions are satisfied. The statements that are available here are based on the corresponding ABAP statements, such as IF, DO, CASE, WHILE and are similar in most programming languages. For more details refer to the SAP Library for the SAP Web Application Server under Controlling the Program Flow [Ext.]. Not all ABAP statements are supported in macro control structures. There are more options when working at the step level than the result level. For instance, you can use CASE WHEN structures to branch to different steps depending on the value of a variable or key figure.

The following is an example of a macro that makes extensive use of control structures. Note the level of the various objects. For information on the functions used, see Functions Related to Info Objects and Planning Book [Page 32].
Using layout variable as loop counter Initialize counter Set loop counter = 1 LAYOUTVARIABLE_SET( LOOPCOUNTER ; 1 ) DO New Step: (1 iterations: M 01.2000 ; M01.2000) Row: Manual Adjustments (Frm M 01.2000) = LAYOUTVAR_VALUE( LOOPCOUNTER ) Add 1 to loop counter LAYOUTVARIABLE_SET( LOOPCOUNTER ; EVAL(LAYOUTVAR_VALUE( LOOPCOUNTER ) + 1 ) ) IF Condition LAYOUTVAR_VALUE( LOOPCOUNTER ) >5 EXIT ENDIF ENDDO

Advanced Macros

401

10

SAP Online Help

07/04/02

Calculation Structures
You use calculation structures not only to execute calculations but also to carry out other actions in which a value is not directly assigned to a key figure or variable. Examples of such actions are: Triggering an alert Displaying a message or dialog box Sending an e-mail

Calculation structures always consist of at least one step. In general a calculation step consists of a macro element at the result level followed by one or more elements at the argument level. A simple example is the second graphic above.

Advanced Macros

401

11

SAP Online Help

07/04/02

Using Macro Elements


Use
Use macro elements in combination with macro tools [Page 15] and drag&drop techniques [Page 17] to define macros.

Features
Icon Element Macro Description Used in Demand Planning or Supply Network Planning to carry out complex or frequent planning tasks quickly and easily. You can execute a macro in interactive planning or as part of mass processing. A unique and/or complex macro used in Demand Planning or Supply Network Planning that you implement through functional enhancement APODM005 (transaction CMOD). A user exit macro can be executed in interactive planning or mass processing. A macro step consists of one or more macro calculations or macro activities. For each macro step, you define how many iterations of the macro calculations or macro activities are to be performed; that is, the area of the table to which the macro calculations/activities apply. The sequence of the macro calculations/activites in a step is not significant; that is, a calculation/activity cannot use the results of another calculation/activity within the same iteration. Control statement Condition Used together with a condition (see below) to control macro steps and calculations. Used for the definition of a logical condition that, together with a control instruction, is used for macro steps and calculations. Row in the table. You can assign the results of a calculation to a row (a results row). A row can be used as an argument in a calculation. A row can also be an argument in a logical condition (an argument row). The calculation is repeated for all the cells that lie within the period defined for the step. Column in the table. You can assign the results of a calculation to a column (a results column). A column can be used as an argument in a calculation. A column can also be an argument in a logical condition (an argument column). As for rows, calculations are repeated for all the cells in the column. Cell in the table. You can assign the results of a calculation to a cell (a results cell). A cell can be used as an argument in a calculation. A cell can also be an argument in a logical condition (an argument cell). Several adjacent cells in the table. You can assign the results of a calculation to an area. Use an area if the function of a macro step changes several cells in one iteration. For example, the function CPY copies values

User exit macro

Step

Row

Column

Cell

Area

Advanced Macros

401

12

SAP Online Help

07/04/02

from one area to another area: e.g. to the auxiliary table. In the "copy to" area, you select only the top left cell of the area before pasting. Another use of areas is in mathematical operations, for example where a sum is formed over a range of cells or a maximum value is found. Auxiliary table Holds data that is used subsequently as part of the macro execution. Use the auxiliary table to retain intermediary results for subsequent calculations, or to collect data for calculations. The same elements are avialble in the auxillary table as in the planning book table. An auxiliary table is available in every macros book. Values in an auxiliary table cannot be saved. To save them, you must assign them to elements in the planning book table. Operator/function Symbolizes: Comparative operators such as < or > Arithmetic operators such as + or A wide range of complex functions that enable you to manipulate data in your planning book. These functions include several useful DP and SNP tools.

See also Operators and Functions in Macros [Page 22]. Function You define functions for a rectangular section of the table. The section borders either are fixed or move with each iteration. If an "$" appears next to a function in the macro tree, this means that the coordinates of the section are fixed and are not relative to the iterations. See also F1 Help. Alert/status Using this element, you can send an alert to the Alert Monitor: for example, you can define an alert that is triggered when a condition (e.g. demand > 1000 boxes) is fulfilled. A status alert displays the status after the execution of the macro. Any previous statuses are deleted from the Alert Montior. If you run a macro twice, you see only the latest alert. A message alert displays the current status after the execution of the macro, and also any previous statuses. If you run a macro twice, you see two alerts. You assign one of the following priorities to an alert: Error Warning Information

You also assign a text to an alert. This is the text that appears in the Alert Monitor; for example, MAPE is too big: &. In the Alert Monitor, the actual value of MAPE

Advanced Macros

401

13

SAP Online Help

07/04/02

appears in place of the &. Procedural message Using this element, you can have the system issue a message. You define the message text yourself. In interactive forecasting, an information message appears in a dialog box, while warning, success and error messages appear at the bottom of the screen. In mass processing, the messages are shown in the job log. Using this element, you can trigger an action that contains a function. If you do not want to assign the macro results to a specific element of the planning table, use an action box. Always use the following functions in an action box: Document HELPTAB_CLEAR OUTPUT_POPUP() REPORT_SUBMIT()

Action box

Using this element, you can have the system send an email. The recipients can be a single internal user, a distribution list, or an external user. There are options for sending to Internet addresses, for sending regular or express mails, and for including the demand planning table as an attachment to the email.

Advanced Macros

401

14

SAP Online Help

07/04/02

Using Macro Tools


Use
Use macro tools in combination with macro elements [Page 12] and drag&drop techniques [Page 17] to define macros.

Features
Icon Tool Attributes Use this icon to Display or change an element's attributes. Select the element, whose attributes you want to change or display. Click on the icon. A dialog box with the attributes of the selected element. This has the effecvt as double-clicking on the element or selecting it and choosing Attributes from the context menu. See also Macro Attributes [Page 58]. Delete Delete an element in the macro tree. The deleted element is automatically copied to the macro clipboard. Check the syntax of one macro or of all macros in the tree. Generate one macro or all macros. You must generated a macro before it can be executed. Activate/deactivate an element in the macro tree. For example, use this tool to check individual sections of complex macros by deactivating some sections and then checking the remaining section(s). Copy an element in the macro tree to the clipboard. Paste the contents of the clipboard to the macro tree. Undo the previous step. You can undo up to 15 steps. Redo the step you have just undone. You can redo up to 15 undone steps. Expand all nodes in the macro tree. Collapse all nodes in the macro tree. Save the MacroBuilder's new layout after you have adjusted the size of some of the screen areas. The new screen layout is then retained and appears the next time you open the MacroBuilder.

Check Generate

Active/inactive

Copy to macro clipboard Paste Undo Redo Expand all Collapse all Save layout settings

Advanced Macros

401

15

SAP Online Help

07/04/02

Definition of Macros in the MacroBuilder


Use
There are two basic methods of working in the MacroBuilder: The context menu Drag&Drop techniques

You define macros in planning books in combination with macro elements [Page 12] and macro tools [Page 15].

Activities
Context Menu
You use the context menu primarily in the macro tree section. If you select an existing macro element (this can even be at the Macro level), the system displays a menu with all the available options for this element at the current position in the macro. Each macro element is listed separately.

Terminology Insert - Enter the new element before the selected element Attach - Enter the new element after the selected element at the same level Add - Enter the new element after the selected element at the next level

The context menu offers two options that are not available with Drag&Drop: Active/inactive Activate/deactivate an element in the macro tree as in the macro toolbar [Page 15]. Stopping point on/off Sets a stopping point. This means that during execution of the macro the macro stops at this element. A dialog box appears in which the value of the element is displayed. You continue processing by choosing .

These two options are for use when creating macros, particularly for debugging complex macros.

Drag&Drop
Use Drag&Drop to do any of the following: Add or insert any macro element in the macro tree When you drop the element, the system offers you a choice of options if more than option is available. Move elements within the macro tree Drag a macro from the macro tree to the standard macros [Page 60] screen area Remove a macro from a standard macro sequence by dragging the macro downwards to the blank space in the standard macros screen area Change the sequence of the standard macros Copy a part of the macro tree to the clipboard

Advanced Macros

401

16

SAP Online Help

07/04/02

The appearance of the icon means that the action is not possible for this element. The appearance of the + icon means that the action is possible for this element, in which case you can let go of the left mouse button. For more information on the different areas of the MacroBuilder screen, see MacroBuilder Screen [Page 8].

Advanced Macros

401

17

SAP Online Help

07/04/02

Semantic Check for Macros


Use
The syntax checker in the Macro Builder checks the formal correctness of the macro coding. There were however some situations that cannot be checked, but cause problems when using the macro. These are often performance issues, where setting an indicator can drastically accelerate the execution of a macro. (In an extreme case a macro could contain a never-ending loop that is not detected by the syntax check.) This function has been conceived so that new checks can be added as necessary.

Integration
This section is optional. Answer the following questions: How is it related to other functions? What other functions does the customer need for this function to work?

Subsequently delete the paragraphs in green.

Prerequisites
This section is optional. Answer the following questions: What has to be in place or has to happen before the customer can use this function? What events or system settings (Customizing) trigger this function?

Subsequently delete the paragraphs in green.

Features
This section is optional. Answer the following question: What does the function do in detail? Subsequently delete the paragraphs in green. You can start the semantic check at the following levels: Macro book The check runs for all the macros in the book. Macro One or more macros are checked Step A macro step is checked Result The individual calculation or process is checked. A semantic check at more detailed (argument) level is superfluous.

At the moment the following checks are available:

Advanced Macros

401

18

SAP Online Help

07/04/02

'Do not initialize aux. table' The system checks wheteher this indicator at the macro level has been set. If not a warning is displayed. If the auxiliary table is not initialized when you call up the macro, any values that are in the table from the execution of previous macros remain in the table and can be used in the current macro. All entries in the auxiliary table are lost when you leave the planning book.

Layout The system checks that the correct Change scope has been assigned to a results element in the attributes. If the function that is called changes the attributes of a cell, for instance by changing the background color or settin an icon, the Change scope should be Attributes, otherwise Values or Fixed values.

'Do not display initial values'

This indicator at macro level affects performance. If it is not set initial values, that is cells that have no entry, are converted to '0', and are taken into consideration during calculations.

Activities
This section is optional. Answer the following questions: What does the customer do? What does the system do?

Subsequently delete the paragraphs in green. You can start the semantic check from either the Macro Workbench or the Macro Builder

Example
This section is optional. Answer the following question: Can you give me an example of the use of this function? Subsequently delete the paragraphs in green.

Advanced Macros

401

19

SAP Online Help

07/04/02

Menu Functions for Macros


Use
Three functions are available to you if you access the MacroBuilder as a stand-alone application (Demand Planning/Supply Network Planning Environment Current Settings Macro Builder ) as opposed to through interactive planning. You find these functions in the Edit menu.

Features
Menu option Change name of book Use this function to Change the name of a macro book. A macro book contains either all of the macros created for the planning book as a whole or all of the macros created for a specific data view in the planning book. Initially, the macro book has the same name as the planning book.

Import macro(s)

Import either all macros or one macro from another macro book. After you have carried out the import, you must perform a consistency check on the macros to ensure, for example, that all the rows in the source book also exist in the target book. After you have carried out the consistency check, you must activate the macros in the target macro book.

User function

Add a function that you have programmed in your own system to the list of possible operators/functions in the MacroBuilder. You have programmed the function with transaction SE37. In the dialog box, which appears after choosing the menu entry, enter the technical name of the user function. Choose Enter. Another screen appears in which you select the export parameters of the function. This selection must be consistent with parameters in the function itself.

Advanced Macros

401

20

SAP Online Help

07/04/02

Operators and Functions in Macros


You enter functions in the following manner: 1. 2. Drag and drop the operator/function icon dialog box appears. to the relevant line in the macro work area. A

On the bottom line choose the function you want to insert by using the pull-down box or F4 help. The function automatically appears in both lines. On the top line you can add alpha-numeric arguments to the functions.

For more details of individual function see the following topics according to the type of function you want to use: Mathematical Operators and Functions [Page 24] Statistical Functions [Page 27] Logical (Boolean) Functions [Page 31] Functions Related to Info Objects [Page 32] Date Functions [Page 46] General and Planning Table Functions [Page 51] SNP Functions [Ext.] 3. If you want to add another macro element (an icon) to your macro, do not close the parentheses (in other words delete the right-hand parenthesis) and choose . Enter the macro element as usual. After you have made all the necessary entries, finish the function by adding ) as the last line. You can nest macro functions within each other. In the following example the macro step converts the value of row 1 from the internal unit of the current resource to the external unit contained in the resource master.

Convert to resource unit (12 Iterations : Column 1 ; Column 12 ) Row: Values of row 1 in resource unit ( Frm Column 1 ) = Row row1 (Frm Column 1 ) * UNIT_CON_FAC ( INTERNAL_RESOURCE_UNIT( ACT_RESOURCE ) ; RESOURCE_UNIT( ACT_RESOURCE ) )

You can also define and use your own functions. For more details, see User function in Menu Functions for Macros [Page 21].

Entry Conventions
An argument is an input parameter, an independent variable, in a function. Enter character values of an argument in single inverted commas. Enter numerical values of an argument without single inverted commas.

Advanced Macros

401

21

SAP Online Help

07/04/02

Use a semicolon as a separator between the arguments of a function. Leave no space between a function operator and a parenthesis, but insert blanks before and after arguments in the parentheses; for example, o o ROUND( X ; Y ) ROUND( SUM ( X ; Z ) ; Y )

$ represents a fixed coordinate.

Changing Attributes
Most of the functions available are value functions, controlling the numbers or values stored within APO. However, there is another class of functions in APO, the attribute functions, that control the properties of the data view instead of the stored values. For instance, these functions change the color of a cell or row, hide or unhide cells or rows, or changes the avaialability for input. If you want to use one of these functions, you must change the Change scope field on the attributes of the result (row, column, or element) to Attributes.

The results of attribute functions are not persistent in APO. In other words, if you turn a rows background color green, this change is not stored permanently by the system. So when you make a new selection in interactive planning or leave and reenter the planning view, that green color change will be lost. Therefore, if you want to see the results of the attribute change next time you enter the selection, you will need to rerun the relevant macros again. In some circumstances you may also need an additional key figure to save the results of actions from previous sessions or selections.

It is not possible to modify the same result row with two or more attribute functions at the same time. The example below would lead to an error during the check. You must repeat the results row for each attribute function.
Row Adjusted forecast (Attributes) = CELL_INPUT( 0 ) CELL_BG( 12 )

Similarly if you wish to use the attribute of a cell, column, or row in a calculation, you must change the Data Source field in the attributes of the argument to Row attributes or Column attributes .

Advanced Macros

401

22

SAP Online Help

07/04/02

Mathematical Operators and Functions


Mathematical Operators
Operator ( ) * ** + / ; Explanation Opening bracket Closing bracket Multiplication Power (e.g. 2 * * 3 = 2 * 2 * 2) Addition Subtraction Division Separator between arguments. An argument is an input parameter. For example, in function f, expressed as f( X1 ; X2 ), the arguments are X1 and X2. Smaller than Smaller than or equal to Larger than Larger than or equal to

< <= > >=

Mathematical Functions
Function ABS() Explanation ABS( X ) returns the absolute value |X| for X. The argument can be either a number that you enter in an Operator/function dialog box or one of the macro elements cell, row or column from the planning table or auxiliary table. Arccos( X ) where X is between 1 and 1, so that the function has values in the range [-/2, /2]. The argument can be either a number that you enter in an Operator/function dialog box or one of the macro elements cell, row or column from the planning table or auxiliary table. Arc sin( X ) where X is between 1 and 1, so that the function has values in the range [-/2, /2]. The argument can be either a number that you enter in an Operator/function dialog box or one of the macro elements cell, row or column from the planning table or auxiliary table. Arc tan( X ) has values in the range [-/2, /2]. The argument can be either a number that you enter in an Operator/function dialog box or one of the macro elements cell, row or column from the planning table or auxiliary table. Operator: for example, X BETWEEN 0 AND 10 returns the value 1 if X falls within the range 0 through 10. COS( X ) returns the cosine of an angle measured in radians. The argument can be either a number that you

ACOS()

ASIN()

ATAN()

BETWEEN COS()

Advanced Macros

401

23

SAP Online Help

07/04/02

COSH()

DIV EXP()

FAC()

FLOOR()

FRAC()

LOG()

LOG10()

MOD PARTIALSUM()

ROUND()

SIGN()

enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or auxiliary table. COSH ( X ) returns the hyperbolic cosine. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or auxiliary table. Whole number division (quotient) operator: for example, 6 DIV 4 returns 1. EXP( X ) is the exponential function. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. FAC( n ) returns the factor of n, that is, the result of multiplying the integers from 1 through n, expressed as n! If n = 3, then 3! = 3 * 2 * 1 = 6. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row, or column from the planning table or the auxiliary table. FLOOR( X ) returns the largest integer value that is not greater than X. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. FRAC( X ) returns the decimal part of X. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or auxiliary table. LOG( X ) returns the natural logarithm of X. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. LOG10( X ) returns the logarithm to the base 10 of X .The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. Whole number division (remainder) operator: for example, 6 MOD 4 returns 0.5. PARTIALSUM( X ; Y1 ; ... ; Yn ) allows you to sum a variable number of values in a time series where X specifies the number of values and Y1 through Yn specify the time series. ROUND( X ; Y ) rounds X to Y decimal places. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s), row(s) or column(s) from the planning table or the auxiliary table. SIGN( X ) returns the value of 1 if X>0 the value of 0 if X=0 the value of -1 if X<0 The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table.

Advanced Macros

401

24

SAP Online Help

07/04/02

SIN()

SQRT()

SUM() TAN()

TANH()

TRUNC()

SIN( X ) returns the sine of angle X measured in radians. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column or from the planning table or the auxiliary table. SQRT( X ) returns the square root of a non-negative number. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. SUM ( X1 ; X2;... Xn ) returns the sum of the specified numbers. TAN( X ) returns the tangent of angle X measured in radians. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. TANH( X ) returns the hyperbolic tangent of X. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. TRUNC( X ) returns the integer part of X. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table.

Advanced Macros

401

25

SAP Online Help

07/04/02

Statistical Functions
Function AVG() Explanation AVG( X1 ;...; Xn ) returns the mean average of X1 through Xn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as rows, columns, cells or areas from the planning table or auxiliary table. BINOM( n ; k ) calculates the binomial coefficient based on the formula n! / k!(n-k)! Use this function to determine the total number of possible combinations without repetition of k items in a set of n items. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as rows, columns or cells from the planning table or auxiliary table. CDFB( X ; n ; p ) returns the probability that the value of a binomial ( n ; p ) distributed variable (see DFB() ) is less than or equal to X; thus, the cumulative probability function of the binomial distribution in a sample of size n where p is the probability that a faulty item is drawn. The arguments can be numbers that you enter in Operator/function dialog boxes as well as rows, columns or cells from the planning table or auxiliary table. CDFH( X ; n ; M ; N ) returns the probability that the value of a distributed variable (see DFH() ) is less than or equal to X; thus, the cumulative probabiity function of the hypergeometric distribution, where n is the size of the sample, M is the number of faulty items in the sample, and N is the size of the population. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as rows, columns or cells from the planning table or auxiliary table. CDFN( X ) returns the probability that the value of a standard normal distributed variable is less than X; thus, the cumulative function of the standard normal distribution. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements row, column or cell from the planning table or auxiliary table. CDFT( X ; n ) returns the probability that the value of a standard normal distributed variable is less than X; thus, the cumulative density function of Student's t distribution where n is the degrees of freedom (n >= 4). The arguments can be numbers that you enter in Operator/function dialog boxes, as well as rows, columns, or cells from the planning table or auxiliary table. CONSTANT( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) returns the constant A of a linear regression line Y = A + BX for a series of observed values. X1 through Xn gives the values of the explanatory variable. Y1 through Yn gives the values of the depedent variable. The number of the values

BINOM()

CDFB()

CDFH()

CDFN()

CDFT()

CONSTANT()

Advanced Macros

401

26

SAP Online Help

07/04/02

Xi and Yi must be the same. The arguments of the function can be number(s) that you enter in Operator/function dialog boxes as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. COR() COR( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) returns the correlation coefficient for a two-dimensional random variable for which the values X1 through Xn and Y1 through Yn are observed. This allows you to examine the relationship between two random variables. The number of the values Xi and Yi must be the same. The arguments of the function can be number(s) that you enter in Operator/function dialog box as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. COV( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) returns the covariance for the two data sets X1 through Xn and Y1 through Yn. The arguments of the function can be number(s) that you enter in Operator/function dialog boxes as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. DFB( m ; n ; p ) returns the probability of the binomial distribution where m is the number of faulty items in a sample of size n, and p is the probability that a faulty item will be drawn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as rows, columns or cells from the planning table or auxiliary table. DFH( m ; n ; M ; N ) returns the probability of the hypergeometric distribution, that is, the probability of finding m faulty items in a sample of size n where M is the number of faulty items in the population and N is the size of the population. The arguments can be number(s) that you enter in Operator/function dialog boxes, as well as rows, columns or cells from the planning table or auxiliary table. E_STDEV( X1 ; ... ; Xn ) returns the estimated value for the standard deviation of a random variable based on the observed values X1 through Xn, i.e. SQRT( E_VAR( X1 ; ... ; Xn ) ). The arguments can be number(s) that that you enter in Operator/function dialog boxes, as well as row(s), column(s), cell(s), or area(s) from the planning table or auxiliary table. E_VAR( X1 ; ... ; Xn ) returns the unbiased estimated value for the variance of a random variable based on the observed values X1 through Xn. The arguments can be number(s) that that you enter in Operator/function dialog boxes, as well as row(s), column(s) , cell(s) , or area(s) from the planning table or auxiliary table. The correction factor n / n-1 is the difference between the functions E_VAR() and VAR(). GAMMA( X ) returns the gamma function for X. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table.

COV()

DFB()

DFH()

E_STDEV()

E_VAR()

GAMMA()

Advanced Macros

401

27

SAP Online Help

07/04/02

MAD()

MAD( X1 ; ... ; Xn ) returns the mean absolute deviation of the values of the values X1 through Xn. The arguments can be number(s) that you enter in Operator/function dialog boxes, as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. MAPE( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) returns the mean absolute percentage error for the values X1, Y1 through Xn, Yn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. MAX( X1 ; ... ; Xn ) returns the greatest value in the range X1 through Xn. The arguments can be either numbers that you enter in Operator/function dialog boxes, or cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. MEAN( X1 ; ... ; Xn ) returns the mean of the values X1 through Xn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. MEDIAN( X1 ; ... ; Xn ) returns the median of the values X1 through Xn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. MIN( X1 ; ... ; Xn ) returns the smallest value of the values X1 through Xn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. MPE( X1 ; ... ; Xn ; Y1 ; ... ; Yn) returns the mean percentage error for the values X1, Y1 through Xn, Yn. The arguments can be number(s) that you enter in Operator/function dialog boxes, as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. MSE( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) returns the mean square error for the values X1, Y1 through Xn, Yn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. PERMUT( X ; Y ) returns the number of possible permutations when X objects are selected from a set of Y objects where Y > X or Y = X. PERMUT (X ; Y ) = X! /(X Y)! The arguments can be numbers that you enter in an Operator/function dialog box, as well as cell(s) , row(s) or column(s) from the planning table or the auxiliary table. RMSE( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) returns the root of the mean square error for the values X1, Y1 through Xn, Yn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s), row(s), column(s) or area(s) from the planning table or

MAPE()

MAX()

MEAN()

MEDIAN()

MIN()

MPE()

MSE()

PERMUT()

RMSE()

Advanced Macros

401

28

SAP Online Help

07/04/02

the auxiliary table. STDEV() STDEV( X1 ; ... ; Xn ) returns the standard deviation of the values X1 through Xn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s) , row(s), column(s) or area(s) from the planning table or the auxiliary table. TREND( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) returns the trend B in a linear regression line Y = A + BX for a series of observed pairs of values. X1 through Xn gives the values of the explanatory variable. Y1 through Yn gives the values of the depedent variable. The number of the values Xi and Yi must be the same. The arguments can be numbers that you enter in an Operator/function dialog box, as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. VAR( X1 ; ... ; Xn ) returns the variance of the values X1 through Xn. The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s), row(s), column(s) or area(s) from the planning table or the auxiliary table. VX( X1 ; ... ; Xn ) returns the coefficient of variation for the values X1 through Xn, calculated as the standard deviation STDEV( X1 ; ... ; Xn ) divided by the mean MEAN ( X1 ; ... ; Xn ). The arguments can be numbers that you enter in Operator/function dialog boxes, as well as cell(s) , row(s), column(s) or area(s) from the planning table or the auxiliary table.

TREND()

VAR()

VX()

Advanced Macros

401

29

SAP Online Help

07/04/02

Logical (Boolean) Functions


Function AND NOT OR Explanation Boolean operator for conditions: true only if both conditions are true. Boolean operator for conditions: logical negation. Logical operator: true if either one or both conditions are true.

Advanced Macros

401

30

SAP Online Help

07/04/02

Functions Related to Info Objects and Planning Books


Function ACT_COLUMN ACT_IOBJNM_VALUE() Explanation ACT_COLUMN returns the number of the column that is currently being processed. ACT_IOBJNM_VALUE( 'IOBJNM'; <GRID=2'> ) returns the value of the InfoObject that is currently being planned. 'GRID=2' is an optional parameter. If you specify this parameter, the value of the specified InfoObject in the second grid at the time of the calculation is returned. For example, the result of ACT_IOBJNM_VALUE( 'SALORG') might be 'north'. ACT_LEVEL returns the level of the object you are planning. 'GRID=2' is an optional parameter. If you specify this parameter, the level of the planning object in the second grid is returned. For example, the result of ACT_LEVEL ( 'GRID=2' ) is 2, if the planning object at the time of the calculation is the result of the second drilldown. in grid 2. ACT_LOCATION returns the name of the location that is currently being planned where the InfoObject for the location is 9ALOCNO. For example, the result of ACT_LOCATION might be DC-BERLIN. 'GRID=2' is an optional parameter. If you specify this parameter, the name of the location being calculated in the second grid is returned. ACT_LOCATION _PRODUCTS returns all the productlocations pairs that are contained in the current selection. 'GRID=2' is an optional parameter. If you specify this parameter, the system returns the location products in the selection in the second grid. ACT_PLOB returns the internal number of the planning object for which the macro is currently being processed. The internal number of a planning object is often needed in other macro functions. ACT_PLOB_GRID2 returns the internal number of the planning object in grid 2 for which the macro is currently being processed. The internal number of a planning object is often needed in other macro functions. ACT_PRODUCT returns the name of the product that is currently being calculated where the InfoObject for the product is 9AMATNR. For example, the result of ACT_PRODUCT might be 4711. 'GRID=2' is an optional parameter. If you specify this parameter, the name of the product ACT_RESOURCE returns the name of the resource that is currently being planned where the InfoObject name of the resource is 9ARNAME. For example, the result of ACT_RESOURCE might be RES-20_1000_001. 'GRID=2' is an optional parameter. If you specify this parameter, the

ACT_LEVEL or ACT_LEVEL()

ACT_LOCATION or ACT_LOCATION()

ACT_LOCATION _PRODUCTS or ACT_LOCATION _PRODUCTS()

ACT_PLOB

ACT_PLOB_GRID2

ACT_PRODUCT or ACT_PRODUCT()

ACT_RESOURCE or ACT_RESOURCE()

Advanced Macros

401

31

SAP Online Help

07/04/02

name of the resource being calculated in the second grid is returned. ACT_USER ACT_VERSION or ACT_VERSION() ACT_USER returns the user name of the current planner. ACT_VERSION returns the version that is currently being planned where the InfoObject name of the version is 9AVERSION. 'GRID=2' is an optional argument. If you specify this argument, the version being planned in the second grid is returned. For example, the result of ACT_VERSION( 'GRID=2' ) might be 001. AGG_LEVEL( 'IOBJNM'; <GRID=2'> ) returns 1 if you are planning on an aggregate level with respect to the InfoObject IOBJNM; where IOBJNM is the technical name of the InfoObject. For example, if your selection contains product 11 and product 12 and if 9AMATNR is the InfoObject name of the product, AGG_LEVEL( '9AMATNR' ) returns 1. AGG_LEVEL( 'IOBJNM' ) returns 0 if you are planning on the detailed level with respect to the InfoObject IOBJNM; for example, if your selection contains product 11 only, AGG_LEVEL ('9AMATNR' ) returns 0. You enter the InfoObject name - in this example, '9AMATNR' - as the argument in an Operator/Function dialog box. 'GRID=2' is an optional parameter. If you specify this parameter, the function is carried out with respect to the InfoObject currently being planned in the second grid. ALERT_BDATE( ALERT ) returns the start date of the earliest valid alert/status of the alert/status type specified by ALERT for the current selection. The argument of this function is an alert/status element. For more information on macro elements, see the Application Help for Demand Planning. ALERT_EDATE( ALERT ) returns the finish date of the latest valid alert/status of the alert/ status type specified by ALERT for the current selection. The argument of this function is an alert/status element. ALERT_EXIST( ALERT ) returns the number of alerts/statuses that exist for alert/status type ALERT for the current selection. The argument of this function is an alert/status element. ALERT_PROFILE_THRESH( profile ; alert type ; alert priority ; <alert object type> ; <application>) returns the threshold value for a particular alert type and Priority (information, warning, error) in an alert profile. ALLOC( n ; m ; X1 ; ... ; Xn + m + 1 ; Y1 ; ... ; Yn + m + 1 ) returns the open allocation quantity that is available for satisfying sales orders, where n is the number of allocation periods before the current period, m is the number of allocation periods after the current period, Xi is the allocation quantity for period i ( i = 1 ... n + m + 1 ), and Yi is the incoming orders quantity for period i. The arguments can be numbers that you enter in Operator/function dialog boxes as well as rows, columns, cells or areas from the planning table or auxiliary table.

AGG_LEVEL()

ALERT_BDATE()

ALERT_EDATE()

ALERT_EXIST()

ALERT_PROFILE_THRESH()

ALLOC()

Advanced Macros

401

32

SAP Online Help

07/04/02

ALLOC_MISQTY()

ALLOC_MISQTY( n ; m ; X1 ; ... ; Xn + m + 1 ; Y1 ; ... ; Yn + m + 1 ) returns the amount by which the customer has already exhausted their allocation, where n is the number of allocation periods before the current period, m is the number of allocation periods after the current period, Xi is the allocation quantity for period i ( i = 1 ... n + m + 1 ), and Yi is the incoming orders quantity for period i. The arguments can be numbers that you enter in Operator/function dialog boxes as well as rows, columns, cells or areas from the planning table or auxiliary table. BUCKET_BDATE( X1 ; ... ; Xn ) returns the earliest start date of the periods given by the cell(s) , row(s) and/or column(s) (not areas) X1 through Xn of the planning table or the auxiliary table. This date is expressed as an integer with reference to the date 0001/01/01. In the attributes of the argument elements, you must specify Period data as the data source. BUCKET_DATE_IN( X ; Y1 ; ... ; Yn ) returns 1 if date X falls within the periods given by the cell(s), row(s) and/or column(s) (not areas) Y1 through Yn. Otherwise, 0 is returned. The date X (for example, the function TODAY or DATE() ) is expressed as an integer with reference to the date 0001/01/01. The argument can be either a number that you enter in an Operator/function dialog box or one of the macro elements cell, row or column from the planning table or auxiliary table. In the attributes of the argument elements Y1 through Yn, you must specify Period data as the data source. BUCKET_DAYS( X1 ; ... ; Xn ) returns the number of Gregorian calendar days of the periods given by the cell(s), row(s) and/or column(s) (not areas) X1 through Xn. In the attributes of the argument elements, you must specify Period data as the data source. BUCKET_DESCRIPTION( X ) returns for the specified column X the text that appears in the column of that period in the planning table. BUCKET_EDATE( X1 ; ... ; Xn ) returns the latest finish date of the periods given by the cell(s) , row(s) and/or column(s) (not areas) X1 through Xn. This date is expressed as an integer with reference to the date 0001/01/01. In the attributes of the argument elements, you must specify Period data as the data source. BUCKET_WDAYS( <calendar> ; X1 ; ... ; Xn) returns the number of workdays in the periods given by the cell(s), row(s), and/or column(s) (not areas) X1 through Xn. In the attributes of the argument elements, you must specify Period data as the data source. The specification of a calendar as the first argument is optional. If you do not specify a calendar, the system reads the calendar given by the time stream in the storage buckets profile. If no time stream is defined, the system uses calendar days. CALC_ERROR returns the value X if an error has occurred during execution of the macro. CALENDAR( 'location' ; 'calendar type' ; <version> )

BUCKET_BDATE()

BUCKET_DATE_IN()

BUCKET_DAYS()

BUCKET_DESCRIPTION()

BUCKET_EDATE()

BUCKET_WDAYS()

CALC_ERROR CALENDAR()

Advanced Macros

401

33

SAP Online Help

07/04/02

returns the calendar of the specified type that is used by the specified location in the specified version. The specification of a version as the third argument is optional. CALENDAR( ACT_LOCATION ; 'PP' ) would return the production planning calendar of the location you are currently planning. CALENDAR_WDAYS() CALENDAR_WDAYS( calendar ; from date ; <to date> ) returns the number of workdays between the from date and the to date in the calendar specified. CBP_SET_INDICATOR ('mode') switches the display of the CBP progress indicator on or off. The argument is either 'ON' or 'OFF'. The default value is 'ON'. CBP_SET_ROUNDING ('mode') switches rounding on or off for CBP. The argument is either 'ON' or 'OFF'. The default value is 'ON'. COLLABORATION ( NAME ) returns a value of 1 if you are currently planning collaboration NAME; otherwise, 0. You enter the name NAME of the collaboration as an argument in an Operator/function dialog box. DET_LEVEL( 'IOBJNM' ; <GRID=2> ) returns 0 if you are planning on an aggregate level with respect to the InfoObject IOBJNM, where IOBJNM is the technical name of the InfoObject. For example, if your selection contains product 11 and product 12, and if 9AMATNR is the InfoObject name of products, DET_LEVEL( '9AMATNR' ) returns 0. DET_LEVEL( 'IOBJNM' ) returns 1 if you are planning on the detailed level with respect to the InfoObject IOBJNM; for example, if your selection contains product 11 only, DET_LEVEL( '9AMATNR' ) returns 1. You enter the InfoObject name - in this example, 9AMATNR - as the argument in an Operator/function dialog box. 'GRID=2' is an optional parameter. If you specify this parameter, the function is carried out with respect to the InfoObject currently being planned in the second grid. DRILL_DOWN(' InfoObject',<'internal'>) carries out a drilldown using the specified InfoObject. The display is as for Details (all ) in planning table. If you set the optional argument 'internal' the display is not changed. This option improves performance, if you intend to drill-up in the same macro subsequently. DRILL_UP(' InfoObject') carries out a drill-up using the specified InfoObject. FIX_CALC( X1; X2: <input check> ) performs fixing calculation with X1 as the row containing the key figure with the value to be fixed and X2 the key figure for the fixed values. If the input check indicator is set (for instance X), the system tries to correct any inconsistencies that may occur due to changes being made on the detail level. For example, a key figure has a value of 100 at the aggregate level and consists of three values at detail level 50, 30 and 20. You then change the last value to 40, the system will reduce the remaining levels so that the total is still 100. Macros using this function should not be used at detail

CBP_SET_INDICATOR()

CBP_SET_ROUNDING()

COLLABORATION()

DET_LEVEL()

DRILL_DOWN()

DRILL_UP() FIX_CALC()

Advanced Macros

401

34

SAP Online Help

07/04/02

level. FORECAST_PROFILE_SET() FORECAST_PROFILE_SET('profile'; 'profile type'; 'version';< key figure 'IOBJNM'> ) sets the forecast profile 'profile' for the forecasting type 'profile type' (S univariate, M - MLR, C - composite) and the version 'version'. An optional entry is the key figure for which the profile is valid, for example 9AFCST for the standard forecast key figure. INVENTORY_COST( 'product' ; 'location' ; <'version'> ) returns the inventory cost of the specified product at a specified location in the specified version. The third argument for the version is optional. INVENTORY_COST( ACT_PRODUCT ; ACT_LOCATION ) returns the inventory cost of the currently planned product in the currently planned location. INTERNAL_RESOURCE_UNIT( 'resource' ; 'version' ) returns the unit of measure in which a resource is saved in LiveCache. ITERATION_COUNTER returns the number of iterations that have been carried out in the current step. IOBJNM_VALUE( 'IOBJNM' ; 'VALUE' ) determines whether the current selection contains only data for the specified characteristic value VALUE of the InfoObject IOBJNM. If yes, the system returns the value 1; otherwise, 0. Enter the arguments in a dialog box of the Operator/function element. Use this function to find out, for example, if the current selection contains data for product VALUE. KEYFS_PLOB(X) returns the internal number of planning object in row X. In the attributes of the argument row, the value in the Data field must be Row attributes. You can use this function as an argument in other macro functions. KEYFS_VERSION( X ) returns the version of the key figure values in row X. In the attributes of the argument row, the value in the Data field must be Row attributes. LAYOUTVAR_VALUE ( 'my_variable' ) returns the value of a numeric layout variable where 'my_variable' is the name of the variable. LAYOUTVARIABLE( 'my_variable' ) returns the value of an alpha-numeric layout variable where 'my_variable' is the name of the variable. LAYOUTVARIABLE_SET( 'my_variable' ; X ) sets the value of a numerical or alphanumerical layout variable to X where 'my_variable' is the name of the variable and X is the value of the variable. With this function you can use the specified variable in (an)other macro(s) in the same macro book. Put the value of the variable in inverted commas if it is a character value; for example, 'X'. If the value of the variable is a quantity, do not put it in inverted commas; for example, X. LOC( 'FIELD_NAME' ; <'location'> ; <'version'> ) returns the content of a numerical field in the location master record of the specified location. The arguments for the location and version are optional. If you specify no

INVENTORY_COST()

INTERNAL_RESOURCE_UNIT()

ITERATION_COUNTER IOBJNM_VALUE()

KEYFS_PLOB()

KEYFS_VERSION()

LAYOUTVAR_VALUE()

LAYOUTVARIABLE()

LAYOUTVARIABLE_SET()

LOC()

Advanced Macros

401

35

SAP Online Help

07/04/02

argument for the location, the system uses the currently planned location. However, it is better for performance reasons to use the function ACT_LOCATION. For example, LOC( 'DURAT' ; ACT_LOCATION ) returns the maximum duration during continuous move of the current location. LOC_C() LOC_C( 'FIELD_NAME' ; <'location'> ; <'version'> ) returns the content of a character field in the location master record of the specified location. The arguments for the location and version are optional. If you specify no argument for the location, the system uses the currently planned location. However, it is better for performance reasons to use the function ACT_LOCATION. For example, LOC_C( 'PARTNER' ; ACT_LOCATION ) returns the partner for the current location. LOG_EXTRA( n ; <'location'> ; <'version'> ) gets the value of an extra field in the location master record for the specified location in the specified version, where n represents the number of the extra field. For example, LOC_EXTRA( 1 ; ACT_LOCATION ) gets the value in extra field 1 for the currently planned location. The arguments for location and version are optional. If you specify no argument for the location, the system uses the currently planned location. However, it is better for performance reasons to use the function ACT_LOCATION. Use this function for numeric fields. LOG_EXTRAC( n ; <'location'> ; <'version'> ) gets the value of an extra character field in the location master record for the specified location in the specified version, where n represents the number of the extra field. For example, LOC_EXTRAC( 1 ; ACT_LOCATION ) gets the value in extra field 1 for the currently planned location, if this field is of type character. The arguments for location and version are optional. If you specify no argument for the location, the system uses the currently planned location. However, it is better for performance reasons to use the function ACT_LOCATION. LOG_EXTRA_SET( n ; 'field_value' ; <'location'> ; '<version>' ) sets the value of an extra field in the location master record for the specified location in the specified version, where n represents the number of the extra field and 'field_value' represents the character or numerical value you want to give the field. Enter a numerical value without single inverted commas. The arguments for location and version are optional. If you specify no argument for the location, the system uses the currently planned location. However, it is better for performance reasons to use the function ACT_LOCATION. LOC_SET( field name ; 'field_value' ; <'location'> ; '<version>' ) sets the value of the specified field in the location master record for the specified location in the specified version. The arguments for location and version are optional. If you specify no argument for the location, the system uses the currently planned location. However, it is better for performance reasons to use the function ACT_LOCATION.

LOC_EXTRA()

LOC_EXTRAC()

LOC_EXTRA_SET()

LOC_SET()

Advanced Macros

401

36

SAP Online Help

07/04/02

LOCATION_TYPE()

LOCATION_TYPE ( 'location' ) returns the location type of the location in the argument, for example ACT_LOCATION. MAT( 'FIELD_NAME' ; <'product'> ; <'version'> ) returns the content of a numerical field in the product master record of the specified product. MAT( 'BRGEW' ; ACT_PRODUCT ) returns the gross weight of the current product. The arguments for product and version are optional. If you specify no argument for the product, the system uses the currently planned product. However, it is better for performance reasons to use the function ACT_LOCATION. MAT_C( 'FIELD_NAME' ; <'product'> ; <'version'> ) returns the content of a character field in the product master record of the specified product. The arguments for product and version are optional. If you specify no argument for the product, the system uses the currently planned product. However, it is better for performance reasons to use the function ACT_PRODUCT. For example, MAT_C( 'KOSCH' ; ACT_PRODUCT ) returns the product allocation procedure for the current product. MAT_EXTRA( n ; <'product'> ; <'version'> ) gets the value of an extra field in the product master record for the specified product in the specified version, where n represents the number of the extra field. The arguments for product and version are optional. If you specify no argument for the product, the system uses the currently planned product. However, it is better for performance reasons to use the function ACT_PRODUCT. For example, MAT_EXTRA( 1 ; ACT_PRODUCT ) gets the value in extra field 1 for the currently planned product. MAT_EXTRA_SET( n ; 'field_value' ; <'product'> ; '<version>' ) sets the value of an extra field in the product master record for the specified product in the specified version, where n represents the number of the extra field and 'field_value' represents the character or numerical value you want to give the field. Enter a numerical value without single inverted commas. The arguments for product and version are optional. If you specify no argument for the product, the system uses the currently planned product. However, it is better for performance reasons to use the function ACT_PRODUCT. MAT_SET ( field name ; field_value' ; <'product'> ; '<version>' ) sets the value of the specified field in the product master record for the specified product in the specified version. The arguments for product and version are optional. If you specify no argument for the product, the system uses the currently planned product. However, it is better for performance reasons to use the function ACT_PRODUCT. MATLOC( 'FIELD_NAME' ; <'product'> ; <'location'> ; <'version'> ) returns the content of a numerical field in the location/product master record of the specified product and location. The arguments for the product, location and version are optional. If you specify no argument for the product and/or location, the system uses the current

MAT()

MAT_C()

MAT_EXTRA()

MAT_EXTRA_SET()

MAT_SET()

MATLOC()

Advanced Macros

401

37

SAP Online Help

07/04/02

product/location. However, it is better for performance reasons to use the functions ACT_LOCATION aYYnd ACT_PRODUCT. For example, MATLOC( 'BSTMA' ; ACT_PRODUCT ; ACT_LOCATION ) returns the maximum lot size for this location product. MATLOC_C() MATLOC_C( 'FIELD_NAME' ; <'product'> ; <'location'> ; <'version'> ) returns the content of a character field in the location/product master record of the specified product and location. The arguments for product, location and version are optional. If you specify no argument for the product and/or location, the system uses the current product/location. However, it is better for performance reasons to use the functions ACT_LOCATION and ACT_PRODUCT. For example, MATLOC( 'BESKZ' ; ACT_PRODUCT ; ACT_LOCATION ) returns the procurement type for this location product. MATLOC_EXTRA( n ; <'product'> ; <'location'> ; <'version'> ) gets the value of an extra field in the product/location master record for the specified product and location in the specified version, where n represents the number of the extra field. The arguments for the product, location and version are optional. If you specify no argument for the product and/or location, the system uses the current product/location. However, it is better for performance reasons to use the functions ACT_LOCATION and ACT_PRODUCT. For example, MATLOC_EXTRA( 1 ; ACT_PRODUCT ; ACT_LOCATION ) gets the value in extra field 1 for the currently planned location product. Use this function for numeric fields MATLOC_EXTRA( n ; <'product'> ; <'location'> ; <'version'> ) gets the value of an extra character field in the product/location master record for the specified product and location in the specified version, where n represents the number of the extra character field. The arguments for the product, location and version are optional. If you specify no argument for the product and/or location, the system uses the current product/location. However, it is better for performance reasons to use the functions ACT_LOCATION and ACT_PRODUCT. For example, MATLOC_EXTRA( 1 ; ACT_PRODUCT ; ACT_LOCATION ) gets the value in extra character field 1 for the currently planned location product. MATLOC_EXTRA_SET( n ; 'field_value' ; <'product'> ; <'location'> ; '<version>' ) sets the value of an extra field in the location product master record for the specified product and location in the specified version, where n represents the number of the extra field and 'field_value' represents the character or numerical value you want to give the field. Enter a numerical value without single inverted commas. The arguments for the product, location and version are optional. If you specify no argument for the product and/or location, the system uses the current product/location. However, it is better for performance reasons to use the functions ACT_LOCATION and ACT_PRODUCT. MATLOC_SET(( field name ; ; 'field_value' ; <'product'> ;

MATLOC_EXTRA()

MATLOC_EXTRA_C()

MATLOC_EXTRA_SET()

MATLOC_SET()

Advanced Macros

401

38

SAP Online Help

07/04/02

<'location'> ; '<version>' ) sets the value of the specified field in the location product master record for the specified product and location in the specified version. The arguments for the product, location and version are optional. If you specify no argument for the product and/or location, the system uses the current product/location. However, it is better for performance reasons to use the functions ACT_LOCATION and ACT_PRODUCT. MULTILEVEL_DEMAND_MEAN() (SNP) MULTILEVEL_DEMAND_MEAN( forecast key figure, actual key figure, product, location, version, <period>) returns the sum of demands from all locations in the supply chain. Values for the future are taken from the forecast key figure, for the past from the actual key figure, in both cases for the given product, location (here for instance the plant or distribution center for which you are planning), and version. The entries actual key figure and period are not strictly necessary but improve performance, if you use MULTILEVEL_DEMAND_VAR in the same macro. For more information, see Multilevel Functions in the Supply Chain Network [Page 44]. MULTILEVEL_DEMAND_VAR( forecast key figure, actual key figure, product, location, version, <period> ) returns the error variance between the forecast demand and actual demand for all locations in the supply chain. This value is determined for the whole historical period or the period specified. As above you also enter the product, location, and version of interest, for example ACT_PRODUCT, ACT_LOCATION, and ACT_VERSION. For more information, see Multilevel Functions in the Supply Chain Network [Page 44]. MULTILEVEL_LEAD_MEAN( forecast key figure, actual key figure, product, location, version, <period>) is similar to MULTILEVEL_DEMAND_MEAN(). From a customer view it calculates the lead time for a product in a location. For more information, see Multilevel Functions in the Supply Chain Network [Page 44]. MULTILEVEL_LEAD_VAR( forecast key figure, actual key figure, product, location, version, <period> ) returns the error variance between the forecast lead time and actual lead time for the specified product and location. This value is determined for the whole historical period or the period specified. As above you also enter the product, location, and version of interest, for example ACT_PRODUCT, ACT_LOCATION, and ACT_VERSION. For more information, see Multilevel Functions in the Supply Chain Network [Page 44]. PARTNER( NAME ) returns the value 1 if planning is currently being done by partner NAME; otherwise, 0. You enter the name NAME of the partner as an argument in an Operator/function dialog box. Use this function in Collaborative Planning. PLOBS_FOR_LEVEL( X ) returns the number of planning objects on the specified level where X represents the planning level. For example, PLOBS_FOR_LEVEL( 1 ) returns the number of products in the product group selection if you have first selected a product group and

MULTILEVEL_DEMAND_VAR() (SNP)

MULTILEVEL_LEAD_MEAN() (SNP)

MULTILEVEL_LEAD_VAR() (SNP)

PARTNER()

PLOBS_FOR_LEVEL()

Advanced Macros

401

39

SAP Online Help

07/04/02

then drilled down to product level. PRODUCT_LIFE() PRODUCT_LIFE( X ; <'product'> ) returns the value 1 if data is selected for exactly one product and if the specified date X comes after the phase-in time span and before the phase-out time span of the product. Otherwise, a value of 0 is returned. For example, PRODUCT_LIFE ( DATE ( 20010220 ) ) returns the value 1 if the product is in its growth or maturity phase on February 20th, 2001. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. The argument for product is optional. PRODUCT_PHIN_END( <'GRID=2'> ; <'product'> ) returns the end date of the specified product's launch phase as maintained for the phase-in profile in the product master record. The arguments for grid 2 and product are optional. If you do not specify a product, the system returns the end date of the phase-in time span of the currently planned product. However, for performance reasons, SAP recommends that you use the function ACT_PRODUCT to represent the current product. PRODUCT_PHIN_START( <'GRID=2'> ; <'product'> ) returns the start date of the specified product's launch phase as maintained for the phase-in profile in the product master record. The arguments for grid 2 and product are optional. If you do not specify a product, the system returns the start date of the phase-in time span of the currently planned product. However, for performance reasons, SAP recommends that you use the function ACT_PRODUCT to represent the current product. PRODUCT_PHOUT_END( <'GRID=2'> ; <'product'> ) returns the end date of the specified product's decline phase as maintained for the phase-out profile in the product master record. The arguments for grid 2 and product are optional. If you do not specify a product, the system returns the end date of the phase-out time span of the currently planned product. However, for performance reasons, SAP recommends that you use the function ACT_PRODUCT to represent the current product. PRODUCT_PHOUT_START( <'GRID=2'> ; <'product'> ) returns the start date of the specified product's decline phase as maintained for the phase-out profile in the product master record. The arguments for grid 2 and product are optional. If you do not specify a product, the system returns the start date of the phase-out time span of the currently planned product. However, for performance reasons, SAP recommends that you use the function ACT_PRODUCT to represent the current product. RESOURCE_COST( 'resource' ; 'resource variant' ; DATE ) returns the cost of the specified resource for the specified capacity variant on the specified date. RESOURCE_EDIT( 'resource' ; 'version' ) returns the value ' X ' if the resource can be edited in the specified version, ' ' if it cannot. RESOURCE_OVERLOAD( 'resource' ; 'version' ) returns the resource overload for the specified resource in the

PRODUCT_PHIN_END or PRODUCT_PHIN_END()

PRODUCT_PHIN_START or PRODUCT_PHIN_START()

PRODUCT_PHOUT_END or PRODUCT_PHOUT_END()

PRODUCT_PHOUT_START or PRODUCT_PHOUT_START()

RESOURCE_COST()

RESOURCE_EDIT()

RESOURCE_OVERLOAD()

Advanced Macros

401

40

SAP Online Help

07/04/02

specified version. For example, RESOURCE_OVERLOAD ( ACT_RESOURCE ; ACT_VERSION ) might return 10%. RESOURCE_RESTYPE() RESOURCE_RESTYPE( 'resource' ; 'version' ) returns the resource type of the specified resource in the specified version. For example, RESOURCE_RESTYPE( ACT_RESOURCE ; ACT_VERSION ) returns resource type 'P', 'T', 'S' or 'H' (production, transportation, storage or handling) for the current resource in the current version. RESOURCE_UNDERLOAD( 'resource' ; 'version' ) returns the resource underload for the specified resource in the specified version. For example, RESOURCE_UNDERLOAD ( ACT_RESOURCE ; ACT_VERSION ) might return 10%. RESOURCE_UNIT ( 'resource' ; 'version' ) returns the unit for the resource that is contained in the resource master record in the specified version. RESOURCE_VARIANT( 'version' ; 'resource_variant' ; 'from_date' ; 'to_date' ) returns the available capacity for the specified resource variant in the specified time span. SUM_CALC( key figure ) calculates the sum of all detail levels of the specified key figure. TIMESHIFT_BACKWARDS( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) shifts the values of time series X1 through Xn backward in time by the number of periods given in time series Y1 through Yn. For example, the time series look like this: X 10 20 30 Y 1 2 1 The result looks like this: 30 40 30 40 3 50 1. 50 -

RESOURCE_UNDERLOAD()

RESOURCE_UNIT()

RESOURCE_VARIANT()

SUM_CALC() TIMESHIFT_BACKWARDS()

The value 10 is shifted back 1 period in time, the value 20 is shifted back 2 periods in time, and so on. TIMESHIFT_FORWARDS() TIMESHIFT_FORWARDS( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) shifts the values of time series X1 through Xn forward in time by the number of periods given in time series Y1 through Yn. For example, the time series look like this: X 10 20 30 40 50 Y 1 3 1 2 1. The result looks like this: 10 30 20 90 The value 10 is shifted forward 1 period in time, the value 20 is shifted forward 3 periods in time, and so on

TS_GET()

TS_GET( 'TS_TYPE' ; 'key_value_1' ; 'key_value_2' ; 'key_value_3' ; <value_from> ; <value_to> ) reads the values of a database time series where 'TS_TYPE' defines the time series type, the second, third and fourth arguments represent the values from the 3 possible key fields of the time series, and the fifth and sixth arguments (which are optional) define the value range that you want to read.

Advanced Macros

401

41

SAP Online Help

07/04/02

The mandatory fields have the following types: TSTYPE = CHAR 20 key_value1 = CHAR 60 key_value2 = CHAR 60 key_value3 = CHAR 60 Example: A time series with ID 'I'', 'A' ; 'B' ; 'C' is Pos Value 1 8 10 60 2 9 10 90 3 20 120. 4 30 5 50 6 50 7

TSGET ( ''I'', 'A' ; 'B' ; 'C' ; 2 ; 9 ) returns 10 20 30 50 50 60 120 Use an area as the macro result element. TS_SET()

90

TS_SET( 'TS_TYPE' ; 'key_value_1' ; 'key_value_2' ; 'key_value_3' ; offset_value ; Y1 ; ... ; Yn ) writes values to a database time series where 'TS_TYPE' defines the time series type, the second, third and fourth arguments represent the values from the 3 possible key fields of the time series, the fifth argument defines the period offset (for example, 5 = starting in column 5), and Y1 through Yn define the row, column, cell or area to which you want to write the values. VALUE_CONTAINED( value ; range ) returns the value 1 if the value is contained in the specified range. W_AVG_CALC( key figure with values ; key figure with weighting factors ) calculates the weighted average of the first key figure using the weighting factors given in the second key figure.

VALUE_CONTAINED() W_AVG_CALC()

Advanced Macros

401

42

SAP Online Help

07/04/02

Multilevel Functions in the Supply Chain Network


These four functions enable you to determine statistical values for use with multilevel scenarios.

20

Supplier

40

Distribution center with own consumption

100

150

130

Customers

In the above graphic example, the figures represent the planned consumption of a product at different levels in the supply chain for one particular period. As well as aggregating the demand from the lower levels the locations also have their own consumption. The function MULTILEVEL_DEMAND_MEAN forms the sum of these planned demands, in this case 100 + 150 + 130 + 40 + 20 = 440.

The function MULTILEVEL_DEMAND_VAR determines the error variance between the planned and actual values for the whole specified period or if you have not specified a period, the complete past.

(Error variance = respectively.)

( Xp
i

Xai ) 2 where Xpi and Xai are the planned and actual values

Advanced Macros

401

43

SAP Online Help

07/04/02

Suppliers

4 days 2 days

2 days

2 days

3 days

Customer

The function MULTILEVEL_LEAD_MEAN calculates the planned lead time for a customer to a receive a product in the period. The system always uses the longest lead time, that is the values from the critical path. The system considers the time from the customer back to the next location that has safety stock. In the above graphic the value would be 6 days. The function MULTILEVEL_LEAD_VAR determines the error variance between the planned and actual values for the whole specified period or if you have not specified a period, the complete past.

(Error variance = respectively.)

( Xp
i

Xai ) 2 where Xpi and Xai are the planned and actual values

Advanced Macros

401

44

SAP Online Help

07/04/02

Date Functions
Function ALERT_BDATE() Explanation ALERT_BDATE( ALERT ) returns the start date of the earliest valid alert/status of the alert/status type specified by ALERT for the current selection. The argument of this function is an alert/status element.. ALERT_EDATE( ALERT ) returns the finish date of the latest valid alert/status of the alert/ status type specified by ALERT for the current selection. The argument of this function is an alert/status element. BUCKET_BDATE( X1 ; ... ; Xn ) returns the earliest possible start date of the periods given by the cell(s), row(s) and/or column(s) (not areas) X1 through Xn of the planning table or the auxiliary table. This date is expressed as an integer with reference to the date 0001/01/01. In the attributes of the argument elements, you must specify Period data as the data source. BUCKET_DATE_IN( X ; Y1 ; ... ; Yn ) returns 1 if date X falls within the periods given by the cell(s), row(s) and/or column(s) (not areas) Y1 through Yn. Otherwise, 0 is returned. The date X (for example, the function TODAY or DATE() ) is expressed as an integer with reference to the date 0001/01/01. The argument can be either a number that you enter in an Operator/function dialog box or one of the macro elements cell, row or column from the planning table or auxiliary table. In the attributes of the argument elements Y1 through Yn, you must specify Period data as the data source. BUCKET_DAYS( X1 ; ... ; Xn ) returns the number of Gregorian calendar days of the periods given by the cell(s), row(s) and/or column(s) (not areas) X1 through Xn. In the attributes of the argument elements, you must specify Period data as the data source. BUCKET_EDATE( X1 ; ... ; Xn ) returns the latest finish date of the periods given by the cell(s) , row(s) and/or column(s) (not areas) X1 through Xn. This date is expressed as an integer with reference to the date 0001/01/01. In the attributes of the argument elements, you must specify Period data as the data source. see FISCAL_PERIOD() BUCKET_WDAYS( <calendar> ; X1 ; ... ; Xn) returns the number of workdays in the periods given by the cell(s), row(s), and/or column(s) (not areas) X1 through Xn. In the attributes of the argument elements, you must specify Period data as the data source. The specification of a calendar as the first argument is optional. If you do not specify a calendar, the system reads the calendar given by the time stream in the storage buckets profile. If no time stream is defined, the system uses calendar days. CALENDAR_WDAYS( calendar ; from date ; <to date> ) returns the number of workdays between the from date and the to date in the calendar specified. The calendar is

ALERT_EDATE()

BUCKET_BDATE()

BUCKET_DATE_IN()

BUCKET_DAYS()

BUCKET_EDATE() _

BUCKET_FISCAL_PERIOD() BUCKET_WDAYS()

CALENDAR_WDAYS

Advanced Macros

401

45

SAP Online Help

07/04/02

the timestream ID. DATE() DATE( YYYYMMDD ) returns the integer value which corresponds to the number of days between 0001/01/01 and the specified date. You enter the date YYYYMMDD in the format YYYYMMDD in an Operator/function dialog box. For example, DATE( 19990101 ) = 729756. Use this function in order to include a fixed, known date in a macro. DAY( X ) returns the day of a date that is expressed in integer format with reference to the date 0001/01/01. For example, DAY( DATE( 19990220 )) = 20. The argument can be either a number that you enter in an Operator/function dialog box or one of the macro elements cell, row or column from the planning table or auxiliary table. FISCAL_BDATE( X;<fiscal year variant>) returns the start of the posting period contains the date X expressed in integer format with reference to the date 0001/01/01. You can enter the date as DATE ( 19990101 ) or using other date functions such as BUCKET EDATE(). The optional second argument specifies the fiscal year variant. FISCAL_EDATE( X;<fiscal year variant>) returns the end of the posting period containing the date X expressed in integer format with reference to the date 0001/01/01. You can enter the date as DATE ( 19990101 ) or using other date functions such as BUCKET EDATE(). The optional second argument specifies the fiscal year variant. FISCAL_PERIOD(X) returns the number of the posting period specified by column X. FISCAL_YEAR (X) returns the fiscal year of the period specified by column X. MONTH( X ) returns the month of a date X that is expressed in integer format with reference to the date 0001/01/01. For example, MONTH( DATE ( 19990220 ) returns 2. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. MONTH_BDATE( X ) returns the start date of the month given in the argument in integer format with reference to the date 0001/01/01. MONTH_EDATE( X ) returns the finish date of the month given in the argument in integer format with reference to the date 0001/01/01. PRODUCT_PHIN_END( <'GRID=2'> ; <'product'> ) returns the end date of the specified product's launch phase as maintained for the phase-in profile in the product master record. The arguments for grid 2 and product are optional. If you do not specify a product, the system returns the end date of the phase-in time span of the currently planned product. However, for performance reasons, SAP recommends that you use the function ACT_PRODUCT to represent the current product. PRODUCT_PHIN_START( <'GRID=2'> ; <'product'> ) returns the start date of the specified product's launch

DAY()

FISCAL_BDATE()

FISCAL_EDATE()

FISCAL_PERIOD() FISCAL_YEAR MONTH()

MONTH_BDATE()

MONTH_EDATE()

PRODUCT_PHIN_END or PRODUCT_PHIN_END()

PRODUCT_PHIN_START or PRODUCT_PHIN_START()

Advanced Macros

401

46

SAP Online Help

07/04/02

phase as maintained for the phase-in profile in the product master record. The arguments for grid 2 and product are optional. If you do not specify a product, the system returns the start date of the phase-in time span of the currently planned product. However, for performance reasons, SAP recommends that you use the function ACT_PRODUCT to represent the current product. PRODUCT_PHOUT_END or PRODUCT_PHOUT_END() PRODUCT_PHOUT_END( <'GRID=2'> ; <'product'> ) returns the end date of the specified product's decline phase as maintained for the phase-out profile in the product master record. The arguments for grid 2 and product are optional. If you do not specify a product, the system returns the end date of the phase-out time span of the currently planned product. However, for performance reasons, SAP recommends that you use the function ACT_PRODUCT to represent the current product. PRODUCT_PHOUT_START( <'GRID=2'> ; <'product'> ) returns the start date of the specified product's decline phase as maintained for the phase-out profile in the product master record. The arguments for grid 2 and product are optional. If you do not specify a product, the system returns the start date of the phase-out time span of the currently planned product. However, for performance reasons, SAP recommends that you use the function ACT_PRODUCT to represent the current product. TIMESHIFT_BACKWARDS( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) shifts the values of time series X1 through Xn backward in time by the number of periods given in time series Y1 through Yn. For example, the time series look like this: X 10 20 30 Y 1 2 1 The result looks like this: 30 40 30 40 3 50 1. 50 -

PRODUCT_PHOUT_START or PRODUCT_PHOUT_START()

TIMESHIFT_BACKWARDS()

The value 10 is shifted back 1 period in time, the value 20 is shifted back 2 periods in time, and so on. TIMESHIFT_FORWARDS() TIMESHIFT_FORWARDS( X1 ; ... ; Xn ; Y1 ; ... ; Yn ) shifts the values of time series X1 through Xn forward in time by the number of periods given in time series Y1 through Yn. For example, the time series look like this: X 10 20 30 40 50 Y 1 3 1 2 1. The result looks like this: 10 30 20 90 The value 10 is shifted forward 1 period in time, the value 20 is shifted forward 3 periods in time, and so on

TODAY

TODAY returns today's date in integer format with reference to the date 0001/01/01. For example, you can use this function as the argument of another function: DAY ( TODAY ) WEEK ( TODAY ) MONTH ( TODAY )

Advanced Macros

401

47

SAP Online Help

07/04/02

PRODUCT_LIFE ( TODAY ) WEEKDAY ( TODAY ) WEEK_BDATE( TODAY ) WEEK_EDATE( TODAY ) YEAR ( TODAY ) YEAR_BDATE( TODAY ) YEAR_EDATE( TODAY ) BUCKET_DATE_IN ( TODAY ; ... ) WEEK() WEEK( X ) returns the week of a date X that is expressed in integer format with reference to the date 0001/01/01. For example, WEEK( DATE ( 20001220 ) returns 51. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. WEEK_BDATE( X ) returns the start date of the week in which the specified day X falls. For example, if today's date is Wednesday, December 20th in the year 2000, WEEK_BDATE( TODAY ) returns 20001218. WEEK_EDATE( X ) returns the end date of the week in which the specified day X falls. For example, if today's date is Wednesday, December 20th in the year 2000, WEEK_EDATE( TODAY ) returns 20001224. YEAR_BDATE( X ) returns the start date of the year in which the specified day X falls. For example, if today's date is Wednesday, December 20th in the year 2000, YEAR_BDATE( TODAY ) returns 20000101. YEAR_EDATE( X ) returns the end date of the year in which the specified day X falls. For example, if today's date is Wednesday, December 20th in the year 2000, YEAR_EDATE( TODAY ) returns 20001231. WEEKDAY( X ) returns as a number between 1 and 7 the weekday of a date that is expressed in integer format with reference to the date 0001/01/01, where 1 = Monday and 7 = Sunday. For example, for January 20th 1999 WEEKDAY( DATE( 19990120 ) ) returns 3. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. YEAR( X ) returns the year of a date that is expressed in integer format with reference to the date 0001/01/01. For example, for January 20th 1999 YEAR( DATE ( 19990120 ) ) returns 1999. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table.

WEEK_BDATE()

WEEK_EDATE()

YEAR_BDATE()

YEAR_EDATE()

WEEKDAY()

YEAR()

Advanced Macros

401

48

SAP Online Help

07/04/02

General and Planning Table Functions


Function CELL_BG() Explanation CELL_BG( X ) sets the background color of a cell to: black if X = 0, blue if X = 1, white if X = 2, yellow if X = 3, cyan if X = 4, green if X = 5, red if X = 6, magenta if X = 7, deep blue if X = 8, gray if X = 9, bright yellow if X = 10, intensive cyan if X = 11, intensive green if X = 12, deep red if X = 13, deep magenta if X = 14. The argument can be a cell, a row or a column of the planning table. You can apply this function to a row, column or cell of the planning table. In the attributes of the row/column/ cell you must set the Scope of change to Attributes. For example, Macro1 |----- Step1 (1 iteration) |----- CELL ( sales ; period ) |----- Cell_BG( 6 ) CELL_FG( x ) sets the foreground color of a cell to: black if X = 0, blue if X = 1, white if X = 2, yellow if X = 3, cyan if X = 4, green if X = 5, red if X = 6, magenta if X = 7, deep blue if X = 8, gray if X = 9, bright yellow if X = 10, intensive cyan if X = 11, intensive green if X = 12, deep red if X = 13, deep magenta if X = 14. The argument can be a cell, a row or a column of the planning table. You can apply this function to a row, column or cell of the planning table. In the attributes of the row/column/ cell you must set the Scope of change to Attributes. For example, Macro1 |----- Step1 ( 1 iteration ) |----- CELL ( sales ; period ) |----- Cell_FG( 6 ) CELL_INPUT( X ) sets the input status of a cell. If X = 1, the status of the cell is set to ready-for-input. If X = 0, the status of the cell is set to read-only. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. You can apply this function to a row or cell. In the attributes of the row or cell, set the Scope of change to Attributes. CELL_LICON( x ) displays the icon x to the left of the cell text. Twenty-nine icons are available: 1 = Activity 2 = Alert 3 = Warehouse 4 = Customer 5 = Customer warehouse 6 = Distribution center 7 = Planning level 8 = Hint 9 = Location 10 = Product 11 = Model 12 = Operation 13 = Order

CELL_FG()

CELL_INPUT()

CELL_LICON()

Advanced Macros

401

49

SAP Online Help

07/04/02

14 = Plant 15 = Product group 16 = Relationship 17 = Resource 18 = Store location 19 = Supplier 20 = Transportation mode 21 = Transportation point 22 = Warning 23 = Filter 24 = Sum 25 = Grid OCX 26 = User 27 = Locked 28 = Zoom in 29 = Zoom out Setting X = 0 deletes any existing icon. If you only want to set or delete an icon in Grid2, add 200 to the value determined above. CELL_RICON() CELL_RICON( x ) displays the icon x to the right of the cell text. Twenty-nine icons are available: 1 = Activity 2 = Alert 3 = Warehouse 4 = Customer 5 = Customer warehouse 6 = Distribution center 7 = Planning level 8 = Hint 9 = Location 10 = Product 11 = Model 12 = Operation 13 = Order 14 = Plant 15 = Product group 16 = Relationship 17 = Resource 18 = Store location 19 = Supplier 20 = Transportation mode 21 = Transportation point 22 = Warning 23 = Filter 24 = Sum 25 = Grid OCX 26 = User 27 = Locked 28 = Zoom in 29 = Zoom out Setting X = 0 deletes any existing icon. If you only want to set or delete an icon in Grid2, add 200 to the value determined above CHAR_VALUES_INPUT() CHAR_VALUES_INPUT ( 'dialog_box_description' ; 'field_label_1' ; ... ; 'field_label_n' ) prompts the user to enter n character strings in a dialog box that appears automatically when this function is executed. A maximum of 10 character strings can be entered. Thus, you can have a maximum of 11 arguments for this function. As the

Advanced Macros

401

50

SAP Online Help

07/04/02

first argument you specify the text that will appear in the title bar of the dialog box. Write this text in single inverted commas with underscores between each word. As the other arguments, you specify the field labels for the fields in which the user will enter the character strings. COL_INPUT() COL_INPUT( X ) sets the input status of a column. If X = 1, the status of the column is ready for input. If X = 0, the status of the column is read-only. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column in the planning or auxiliary table. You can apply this function to a column or cell of the planning table. In the attributes of the column or cell, set the Scope of change to Attributes. This applies to Grid 1. To refer to Grid 2 use X = 20 for read-only, and X = 21 for ready for input. Similarly X = 10 and X = 11 to refer just to GRID 1. Displays the icon x to the left of the column text. Twentynine icons are available (see CELL_LICON). In the attributes of the column, set the Scope of change to Attributes. Displays the icon x to the right of the column text. Twentynine icons are available (see CELL_RICON). In the attributes of the column, set the Scope of change to Attributes. COL_VISIBLE( X ) sets the visibility of a column. If X = 1, the column is visible. If X = 0, the column is not visible. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column in the planning or auxiliary table. You can apply this function to a column or cell of the planning table. In the attributes of the column or cell, set the Data source to Attributes. This applies to Grid 1. To refer to Grid 2 use X = 20 for read-only, and X = 21 for ready for input. Similarly X = 10 and X = 11 to refer just to GRID 1. COLUMN_MARKED returns the value 1 if the column specified in the argument has been selected. Otherwise the value is 0. In the attributes of the row or cell, set the Data source to Row Attributes. CURR_CONV_FAC( 'source currency' ; 'target currency' ; 'exchange rate type' ; DATE ) returns the currency conversion factor for the specified source currency, target currency and exchange rate type on the specified date. This date can be TODAY (that is, the system date) or another date (see the functions DATE() and TODAY). TODAY is a function, so you do not need to put it in inverted commas. Example: CURR_CONV_FAC( 'USD' ; 'EUR' ; 'M' ; TODAY ). DATA_IS_LOCKED returns the value 1, if the data is locked for the current user, meaning they can edit the data. It returns the value 0, if the data is locked by another user, meaning the current user cannot edit the data. DISPLAY_CONV_FACTOR (Row) returns the conversion factor between the unit in which the data is stored internally and the unit in which it is displayed for the row. For example, time data may be stored in LiveCache in

COL_LICON()

COL_RICON()

COL_VISIBLE()

COLUMN_MARKED()

CURR_CONV_FAC()

DATA_IS_LOCKED

DISPLAY_CONV_FACTOR()

Advanced Macros

401

51

SAP Online Help

07/04/02

seconds but it is displayed in the planning table in hours. DISPLAY_CONV_FACTOR would then return 3600 In the attributes of the row or cell, set the Data source to Row Attributes. EVAL() EVAL() is an auxillary function for constructing more complicated functions. EVAL() evaluates the arithmetic expression in the argument so that this result can be used in another function. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column in the planning or auxiliary table. Use this function to calculate the argument of other functions at runtime. For example EVAL ( ( 1 + 2 ) * 3 ) = 9 HELPTAB_CLEAR HELPTAB_CLEAR initializes the values in the auxiliary table. You can use this function anywhere in a macro. If you wish to initialize the values in the auxiliary table at the beginning of a macro, leave unchecked the macro attribute Do not initialize auxiliary table. MARKED_COLUMN(<'FIRST/LAST'>) returns the column numbers of all marked columns. If 'FIRST' or 'LAST' is included as an argument, the function returns the first or last marked column in the time series. 'FIRST' and 'LAST' are the only possible arguments. MARKED_FIXED_COLS returns the numbers of the marked fixed columns MARKED_FIXED_ROWS returns the numbers of the marked fixed rows MARKED_PLOB returns the internal planning object number of the marked rows. Using this number has the advantage in comparison to the row number that this number remains constant irrespective of where the object appears in the grid. MARKED_ROW(<'FIRST/LAST'>) returns the row numbers of all marked rows. If 'FIRST' or 'LAST' is included as an argument, the function returns the first or last marked row. 'FIRST' and 'LAST' are the only possible arguments. NUM_VALUES_INPUT ( 'dialog_box_description' ; 'field_label_1' ; ... ; 'field_label_n' ) prompts the user to enter n numerical values in a dialog box that appears automatically when this function is executed. As the first argument you specify the text that will appear in the title bar of the dialog box. Write this text in single inverted commas with underscores between each word or use the function STRING_CONCATENATE () . As the other arguments, you specify the field labels for the fields in which the user will enter the numerical values. A maximum of 10 numerical values can be entered. Thus, you can have a maximum of 11 arguments for this function. NUMBER( E1 ; ... ; En ) returns the total number of cells in the macro elements E1 through En. E1 through En can be cell(s), row(s), column(s) and/or area(s) from either the

MARKED_COLUMN() or MARKED_COLUMN

MARKED_FIXED_COLS MARKED_FIXED_ROWS MARKED_PLOB

MARKED_ROW() or MARKED_ROW

NUM_VALUES_INPUT()

NUMBER()

Advanced Macros

401

52

SAP Online Help

07/04/02

planning table or the auxiliary table. For insatnce, you can use this function to determine the number of time buckets in the current grid. OUTPUT_POPUP OUTPUT_POPUP('dialog_box_description' ; 'field_label_1' ; value in field 1 ; ... ; 'field_label_10' ; value in field 10 ) opens a dialog box that shows the alphanumeric or numerical values of extra fields in the product and/or location master record. A maximum of 10 field values can be displayed in this box. PLOB_DATA_VISIBLE( X; 'planning object'...'planning object n' ) sets the visibility of the specified planning object(s). You use this function if you are are working with drill-down in the Details (all) view. If X =1 the planning objects are displayed. If X=0 the planning objects are hidden. Use functions ACT_PLOB, MARKED_PLOB, or KEYFS_PLOB to specify the planning objects. PLOB_MARKED returns the value 1 if the planning object specified in the argument has been selected. Otherwise the value is 0. Use functions ACT_PLOB, MARKED_PLOB, or KEYFS_PLOB to specify the planning objects. REPORT_SUBMIT( 'program_name' ; <'job_name'> ; <'job_number'>; <'newmode'>) causes the specified program to be executed. Use the optional arguments, job name and job number, if you wish the program to run in the background. If you set the argument 'newmode', the results are displayed in a new window. ROW_BG( X ) sets the background color of a row to: black if X = 0 blue if X = 1 white if X = 2 yellow if X = 3 cyan if X = 4 green if X = 5 red if X = 6 magenta if X = 7 deep blue if X = 8 gray if X = 9 bright yellow if X = 10 intensive cyan if X = 11 intensive green if X = 12 deep red if X = 13 deep magenta if X = 14 The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. You can apply this function to a row or cell. In the attributes of the row or cell, set the Scope of change to Attributes.

PLOB_DATA_VISIBLE()

PLOB_MARKED()

REPORT_SUBMIT()

ROW_BG()

Advanced Macros

401

53

SAP Online Help

07/04/02

ROW_FG()

ROW_FG( X ) sets the foreground color of a row to: black if X = 0 blue if X = 1 white if X = 2 yellow if X = 3 cyan if X = 4 green if X = 5 red if X = 6 magenta if X = 7 deep blue if X = 8 gray if X = 9 bright yellow if X = 10 intensive cyan if X = 11 intensive green if X = 12 deep red if X = 13 deep magenta if X = 14 The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. You can apply this function to a row or cell. In the attributes of the row or cell, set the Scope of change to Attributes.

ROW_INPUT()

ROW_INPUT( X ) sets the input status of a row. If X = 1, the status of the cell is set to ready-for-input. If X = 0, the status of the cell is set to read-only. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. You can apply this function to a row or cell. In the attributes of the row or cell, set the Scope of change to Attributes. Displays the icon X to the left of the row text. Twenty-nine icons are available (see CELL_LICON). ROW_MARKED returns the value 1 if the row specified in the argument has been selected. Otherwise the value is 0. ROW_RELIEF ( X ) sets the contrast status of a row. If X = 1, the row is thrown into relief; that is, it stands out in contrast to the other rows. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. You can apply this function to a row or a cell. In the attributes of the row or cell, set the Scope of change to Attributes. Displays the icon X to the right of the row text. Twentynine icons are available (see CELL_RICON). ROW_VALUES_CHANGED( X ) returns 1 if the user has changed one or more values in row X in the current planning session since last pressing Enter. In the attributes of the row, enter Row Attributes as the data

ROW_LICON() ROW_MARKED() ROW_RELIEF()

ROW_RICON() ROW_VALUES_CHANGED()

Advanced Macros

401

54

SAP Online Help

07/04/02

source. ROW_VISIBLE() ROW_VISIBLE( X ) sets the visibility of a row. If X = 1, the row is visible. If X = 0, the row is not visible. The argument can be either a number that you enter in an Operator/function dialog box, or one of the macro elements cell, row or column from the planning table or the auxiliary table. You can apply this function to a row or a cell. In the attributes of the row or cell, set the Scope of change to Attributes. STRINGS_CONCTENATE('string1'...'stringn') inserts blanks between several character strings to produce one string. TRANSPORT_COST( 'product' ; 'from_location' ; 'to_location' ; 'shipment_type' ; 'version' ) returns the cost of transporting the specified product from one location to another, using the specified shipment type. UNIT_CONV_FAC( NAME1 ; NAME2 ) returns the conversion factor for conversion from unit NAME1 to unit NAME2. You enter the names of the units in Operator/function dialog boxes; for example, UNIT_CONV_FAC ( KG ; TO ) = 1000. USER( NAME ) = 1 if the user name of the person who logged on is NAME; for example, USER( SUCHANEK ) = 1 if the logon name of the planner is Suchanek. Otherwise, USER( SUCHANEK ) = 0. You enter the argument in an Operator/function dialog box. VALUE_OF_ROW_CHANGED( X ; Y1 ; ... Yn ) returns 1 if the user has changed one or more key figure values in columns Y1 through Yn of row X in the current planning session since last pressing Enter. In the attributes of the row, enter Row Attributes as the data source..

STRINGS_CONCTENATE()

TRANSPORT_COST()

UNIT_CONV_FAC()

USER()

VALUE_OF_ROW_CHANGED()

Advanced Macros

401

55

SAP Online Help

07/04/02

Attributes of Macro Elements


Use
You can change the attributes of the various macro elements (macros, steps, conditions etc.). The attributes that can be edited vary with the element type and include the periods for which the element is valid and additional functions.

Features
In every macro element you can change the name in the attributes. Macro Here you specify: Whether the macro can be executed directly Whether a confirmation prompt appears when you execute the macro Whether the auxiliary table is initialized when you call up the macro If the auxiliary table is not initialized when you call up the macro, any values that are in the table from the execution of previous macros remain in the table and can be used in the current macro. All entries in the auxiliary table are lost when you leave the planning book. The level at which the macro operates The level is defined by the current drill-down situation. This means in interactive planning that the aggregate level is the level at which you enter the planning book by making a selection. If you then drill-down on characteristic A, this is level 1. If you subsequently drill-down on a further characteristic B, this is level 2. In batch mode the drill-down situation is controlled by the macro functions DRILL_DOWN() and DRILL_UP() see Functions Related to Info Objects and Planning Book [Page 32]. Whether cells that have no entries (initial) are left blank or receive the value "0". To improve performance, we recommend that you set this indicator.

You can also assign the macro an icon that appears in the planning table. You can then execute the macro by clicking on this icon. You also see whether if the macro is used as a standard macro [Page 60] and if so, which type and at which position the macro appears in the list for the relevant type (start, exit, level chang, or default). You can also define collective macros that consist of other macros in the planning book. These macros are then performed automatically in the given order.

You define a macro as a collective macro when you create it, by setting the Macro type field to Collective macro. If you have already assigned other elements (steps, conditions etc.) to it, you can no longer change a macro to a collective macro. Step In the step attributes you primarily define the time period to which the step applies. You can specify that it applies to: The whole period The past The future

Advanced Macros

401

56

SAP Online Help

07/04/02

Freely definable. Here you can enter existing time buckets or columns. This means that the position of the column in the table remains constant, the dates may move. For example, the macro applies to the second time bucket in the future to the tenth time bucket in the future. Date dependent. Here the time buckets are selected that contain the specified dates. The dates remain constant and the time bucket may change. For example, the macro applies from 01/01/2001 through 06/30/2001. You can specify whether the date has to be at the start of a time bucket or whether it only has to be in a time bucket. Whether the columns at the start and end are adjusted automatically.

Activities
When you create a new macro element the attribute dialog box appears automatically. You can access it later via the context menu, or by double-clicking on the element in the work area.

Advanced Macros

401

57

SAP Online Help

07/04/02

Standard Macros
Definition
A standard macro is a macro that is executed automatically; its execution is not triggered manually by the planner. A standard macro is one of the following types: Default A default macro is executed when the planner opens the planning desktop and specifies the selection ID, regenerates the screen (for example, by choosing Enter or Tab ), or saves the plan. Level change A level change macro is executed when the planner drills up or down in interactive forecasting. Start A start macro is executed when the planner opens the planning desktop and specifies the selection ID. Exit An exit macro is executed when the planner saves the plan. The planning desktop is closed automatically.

Use
To define a macro as a standard macro: 1. 2. Drag and drop the macro from the macro tree to the appropriate standard macro icon in the top right area of the MacroBuilder. Set the attribute No direct execution for the macro.

One possible use of standard macros is to calculate the difference between forecasts of different periods. This is part of the process for Statistical Error Analysis [Ext.].

Advanced Macros

401

58

SAP Online Help

07/04/02

Forecast Analysis Using Macros


Purpose
In this process, you track predefined situations in the forecast through the use of macros.

Prerequisites
You have installed the Alert Monitor.

Process Flow
This process flow describes just one way in which you can use macros and alerts to monitor the forecast. 1. Create a planning book and define in it one or more macros. Attach alerts to the macros; in the macro structure [Page 9] the alert is the result of a condition. For an example, see Example of a Macro Alert [Page 63]. If you want to display only the current forecasting status after the execution of the macro and delete any previous statuses from the Alert Monitor, set a status alert . If you want to display the forecasting status after the execution of the macro, and also any previous statuses, set a message alert . 2. In the Alert Monitor, create an SDP alert profile. Alert profiles are used to display specific alerts to specific users. They do not affect whether or not alerts are created. 3. In interactive demand planning (for mass processing, see below*) assign the alert profile you created in step 2 by choosing Edit Assign alert profile. Do not select Forecast deletes old alerts automatically. For the monitoring of macro alerts in mass processing, see below. Switch to the forecast view of interactive demand planning, using a univariate forecast profile to create a forecast. Return to the user-defined view, adopting the created forecast. Execute the macro(s). From the workspace toolbar, choose Display/refresh alerts The macro alerts appears at the bottom of the screen. 9. Check the macro alerts. .

4. 5. 6. 7. 8.

10. Make any necessary adjustments to the forecast model or the forecast results. 11. Run the forecast again. 12. In the user-defined data view, refresh the alerts by choosing Edit Update alerts. 13. Study the alerts to see if the adjustments you made in step 7 have corrected the problem. If you created message alerts in step 1, you can compare the alerts that you viewed in step 7 with the new ones. This is the case if you did not select Forecast deletes old alerts automatically in step 3. 14. Repeat steps 7 through 10 until no more new alerts appear.

* If you are forecasting in the background, continue as follows at step 3:

Advanced Macros

401

59

SAP Online Help 3. 4.

07/04/02

On the Forecast tabstrip of the mass processing activity, specify that alerts are to be created. If desired, specify that old alerts are to be deleted by this forecast. If you check this box, old alerts are deleted when the mass forecasting job is processed even if no new alerts are created.

5. 6.

Run the forecast in the background as a mass processing job. For more information, see Forecast Execution with Mass Processing [Ext.]. Open the Alert Monitor by choosing Supply Chain Monitoring ? Alert Monitor and check the alerts.

Advanced Macros

401

60

SAP Online Help

07/04/02

Example of a Macro Alert


This macro calculates the difference between this week's forecast and the previous week's forecast and issues an alert if the difference is greater than 20%. Forecast and Previous forecast are two key figures (two rows) in the planning table. Company XYZ manufactures product ABC, sales of which have been stable over time as it is a basic commodity. Therefore, there should be no drastic differences between this weeks forecast and the previous weeks forecast, as under normal circumstances no sudden changes would be expected to occur. If this weeks forecast for period 3 is 100 but last week's forecast for period 3 was 60, this is an exception that needs to be brought to the notice of the demand planner. This macro detects such exceptions, triggers an alert, and changes the color of the corresponding cell to red. The planner can then take action as necessary.

Macros Check for > 20% change in forecast Calculate difference (15 iterations: W 41.2000 ; W3.2001) % difference Fcst and Prev.Fcst (Frm W 41.2000) 100 * ABS( Previous forecast (Frm W 41.2000) Forecast (Frm W 41.2000) )/ Forecast (Frrm W 41.2000) Alert IF Condition: Forecast deviation > 20% % difference Fcst and Prev.Fcst (Frm W 41.2000) > 20 [ Previous forecast deviation in %: & ] with % difference Fcst and Prev.Fcst (Frm W 41.2000) Forecast (Attributes) = CELL_BG(13) ELSE Forecast (Attributes) = CELL_BG(15) ENDIF

Advanced Macros

401

61

SAP Online Help

07/04/02

Translating Advanced Macros


Use
Use this function to translate macro descriptions and alert texts into your logon language.

Prerequisites
The macro was defined or the alert was triggered in a system whose logon language was different than the current logon language.

Features
The language in which macro descriptions and alert texts appear in a planning book is determined as follows: 1. 2. 3. If available, the texts are shown in the logon language. If no texts exist in the logon language, English is shown. If no texts exist in English either, any other available language is shown.

The language in which an alert text appears in the Alert Monitor is determined by the language in which you were logged on when the alert was triggered.

Activities
To translate macro descriptions or alert texts into the current logon language, overwrite the foreign language texts in the planning book. When you save the planning book, the texts you entered are saved as the macro descriptions and alert texts of the current logon language. The foreign language texts are retained for the original language system.

Advanced Macros

401

62

SAP Online Help

07/04/02

Business Cases for Macros


The standard APO system comes with two macros books containing examples of the use of macro functions and operators: SAP Example and Template Macros and SDP Book 9AEXAM VIEW (SALES DATA). In SAP example and template macros you can look at the examples but you cannot execute the macros. To execute the macros, import them to another macro book that you have created yourself (for more information, see Menu Functions for Macros [Page 21] ) and alter their definition to fit the rows of the second book. In SDP Book 9AEXAM VIEW (SALES DATA) you can execute the macros. The following documentation suggests some business cases in which you might use these macros. Where no example macro book is mentioned, please refer to SAP Example and Template Macros .

Advanced Macros

401

63

SAP Online Help

07/04/02

Example of a Macro to Convert Percentage Values


This macro converts a percentage value based on the row Corrected Forecast automatically to an absolute value, and an absolute value into a percentage. The demand planner can decide on a case by case basis in which form to enter the value.
Macros Promotion Percnetage <-> Value Calculate % <-> Value : ( 30 Iterations : W 41.1999; W 18.2000) IF % entered Auxilary row 1 ( Frm W 41.1999) = Absolute Adjustment ( Frm W 41.199) Auxilary row 1 ( FM W 41.1999) Percentage Adjustment ( Frm W 41.199) / 100 * Corrected Forecast (Frm W 41.2000) Absolute Adjustment ( Frm W 41.199) = Percentage Adjustment ( Frm W 41.199) / 100 * Corrected Forecast (Frm W 41.2000) ELSE Percentage Adjustment ( Frm W 41.199) Absolute Adjustment ( Frm W 41.199) / 100 * Corrected Forecast (Frm W 41.2000) Absolute Adjustment ( Frm W 41.199) = Absolute Adjustment ( Frm W 41.199) = ENDIF

Advanced Macros

401

64

SAP Online Help

07/04/02

Make 2nd Column Read-Only/Make 2nd Column Ready-For-Input


A demand planner is planning the demand for a consumer product whose forecast in the last week of the year has already been fixed by top management, on the basis that demand from two major suppliers in this week will be extremely high. This macro ensures that the forecast figures in this period are not touched while the demand planner can apply forecasting techniques to other periods. Some weeks later top management decides that it is necessary to modify the figures they had fixed for the last week of the year, due to a sudden change in the situation of one of the suppliers. They execute a second macro to allow changes to be made to the demand plan in this period.

Advanced Macros

401

65

SAP Online Help

07/04/02

Make 2nd Column Invisible/Make 2nd Column Visible


A demand planner is planning the demand for a consumer product whose forecast in the last week of the year has already been fixed by top management, on the basis that demand from some major suppliers will be extremely high in this week. Management does not wish the demand planner to see their forecast for this period because it might influence his judgement in other periods. This macro ensures that the forecast figures for the last week of the year are not visible to the demand planner, but that he can create demand plans in other periods. Some weeks later top management decides that it is necessary to modify the figures they had fixed for the last week of the year, due to a sudden change in the situation of one of the suppliers. They execute a second macro to make the demand plan in this period visible again.

Advanced Macros

401

66

SAP Online Help

07/04/02

Hide All Columns <> December (Year View)


A demand planner is forecasting a product for which the corporate sector is the major buyer (for example, heavy duty vehicles). He has already done preliminary forecasting without considering seasonal effects because he wants to incorporate seasonal effects into the forecast manually. From previous history, it is known that sales are exceptionally high for this product in December on account of depreciation benefits which are due only in this month. The demand planner uses this macro to hide all columns except those which correspond to the month of December so that he can concentrate on the December columns and make adjustments in these periods.

Advanced Macros

401

67

SAP Online Help

07/04/02

Set/Delete Icon for Row 1 (All Planning Objects)


A planner makes much use of a row and the data in other rows is also dependent on the data in this row. The planner puts an icon in front of this row in order to draw his attention to it. When the planner decides he no longer needs the icon on this row, he can delete it by using a second macro.

Advanced Macros

401

68

SAP Online Help

07/04/02

Change Foreground Color to Red for Negative Values


If a planner enters a large number of values in the interactive planning table, he may not be able to see negative values. In terms of planning, negative values are an incorrect entry as demand cannot be negative. A default macro changes the color of cells with negative values to red. Thus, the planner can quickly identify the errors.

Advanced Macros

401

69

SAP Online Help

07/04/02

Calculate Cumulated Values: Year-to-Date


A demand planner is analyzing various scenarios with respect to the inventory levels resulting from different sales volumes. In a pessimistic scenario, actual sales are less than the forecast, and inventory starts piling up because actual sales are less than production, which is based on the forecast. This macro uses the difference between the forecast and a pessimistic sales estimate (contained in row 2) in order to calculate cumulative inventory levels at the end of every period, and writes the results to row 1. Having seen these worst-case inventory levels, the demand planner may adjust the forecast figures, also taking into account the inventory policy of the company, warehouse capacities, and so on.

Advanced Macros

401

70

SAP Online Help

07/04/02

Calculate and Round % Difference


A demand planner creates a forecast in a planning book that includes rows for the baseline forecast and the final forecast. He uses this macro to calculate the % difference between these two key figures and round it off to 3 digits. The macro writes the result to a third row. For this example, please refer to macro book SDP Book 9AEXAM VIEW (SALES VIEW). Row 1 is the baseline forecast, row 2 is the final forecast, and the results row is Total forecast adjustments in %.

Advanced Macros

401

71

SAP Online Help

07/04/02

Info Message If Sum > 1000


A demand planner is responsible for creating both a baseline forecast and promotions. It is the policy of his company that when forecasted demand in a year is greater than 1000 units, promotions are not planned for that year because the company does not have the capacity to produce more than 1000 units. The macro triggers a message to inform the planner when the forecast is greater than 1000. He is therefore saved the unnecessary effort of planning promotions in that year. In this example, row 1 represents the baseline forecast.

Advanced Macros

401

72

SAP Online Help

07/04/02

Trigger DB Alerts If Value > 0


A Planner has done preliminary forecasting for a product which is in the last stage of its life cycle (decline stage) so after doing preliminary forecasting he wants to incorporate the effects of life cycle to this product. So he will be having a row with the key figure as Adjusted forecast in his planning table. This row will contain adjustment on preliminary forecast due to life cycle stage & should be having negative values. So, if some positive value comes in the table , planner should be informed about this. This macro will trigger an alert with the value shown so that planner can take appropriate action. If this is not the case, this macro will delete all previous alerts in this context. In the example, row 1 represents the preliminary forecast and row 2 the adjusted forecast.

Advanced Macros

401

73

SAP Online Help

07/04/02

Calculate Sum of 3 Successive Periods Using Rows/Areas


A demand planner has done forecasting on monthly basis and wants to get data on a rolling quarterly basis: the sum of the forecasts for January through March, the sum of the forecasts for February through April, and so on. For example, you could create the baseline forecast in one data view and execute this macro as a start macro in a second data view as the preface to doing further forecast calculations. One possibility would be to use these rolling quarterly figures to calculate a moving monthly average and thus arrive at a smoother forecast. Alternatively, the rolling quarterly figures could form the basis for calculating other forecast adjustments.

Advanced Macros

401

74

SAP Online Help

07/04/02

Using Nested Functions


One planner has created a demand forecast. It is the job of a second planner to arrive at a final forecast adjustment figure. The second planner has a data view containing monthly forecast adjustment figures from two departments, say Marketing & Production. In the example, row 1 represents the production adjustments, row 2 the marketing adjustments, and row 3 the final forecast adjustments. He wants to take a conservative estimate for the final forecast adjustments and smooth this figure at the same time. By using this macro he does the following: 1. 2. 3. Calculates rolling quarterly figures for each month in both rows Calculates a mean of the quarterly figure in each month In each month, writes the greater of the two values to the final forecast adjustment figure

Example: Demand Manager's Data View Jan 2002 Production Adjustments Marketing Adjustments Final Forecast Adjustments 10 20 Feb 2002 15 25 25 Mar 2002 20 30 40 Apr 2002 85 35 50 May 2002 45 40

In the example above, the first iteration would be: 1. 2. Production Adjustments Row: 10 + 15 + 20 = 45 Marketing Adjustments Row: 20 + 25 + 30 = 75 Monthly mean for February: Production Adjustments Row = 45/3 = 15 Monthly mean for February: Marketing Adjustments Row = 75/3 = 25 15 < 25 Final Forecast Adjustment for February = 25.

3.

Advanced Macros

401

75

SAP Online Help

07/04/02

Calculate Only for Periods Before 01/01/2000


A demand planner's data view includes rows for actual sales data and sales history. Actual sales data is available until the end of last year. The current period is January. The planner wants to store actual sales data up until the end of the previous year in the sales history row where it can be utilized for forecasting into the future. For this purpose, he uses a macro that checks the date of each column (period) and, for the periods prior to this year, copies the data from the actual sales row to the sales history row. In the example, row 1 represents sales history and row 2 represents actual sales data.

Advanced Macros

401

76

SAP Online Help

07/04/02

Using the Number of Workdays for the Calculation


A planner wishes to roughly estimate the daily average production rate necessary to meet demand. He uses this macro to divide monthly demand by the number of workdays in each month. He can therefore assess whether his forecasts are feasible given normal production rate/capacities of the plant(s). Another scenario in which this macro might be used is as follows: POS data from the past is available to the planner. The planner would like to compare average forecasted daily sales (which will be made on workdays only) with previous average daily sales.

Advanced Macros

401

77

SAP Online Help

07/04/02

Using Actual Currency Conversion Factor


Currency conversion of the forecasted data may be required when all costing calculations are done in DM but profit is to be calculated in $ and all revenue data is also quoted in $. Use macros such as this one to convert monetary values between currencies. In the example, row 1 represents the $ forecast and row 2 represents the DM forecast.

Advanced Macros

401

78

SAP Online Help

07/04/02

Get Missing Forecast Entries from User


A demand planner is entering values for the baseline forecast. He enters zero by mistake in some of the periods, or forgets to enter values. When this macro is executed, a dialog box appears for these periods and prompts the planner to enter values. The values thus entered by the planner are transferred to the planning table. For this example, see the macro book SDP Folder 9AEXAM View (SALES DATA).

Advanced Macros

401

79

SAP Online Help

07/04/02

Using Values from Different Periods


A demand planner is creating the baseline forecast for a product for which demand is growing continuously. The growth pattern can be mapped as a linear trend. The planner is interested in knowing the average percentage growth for each period compared with its previous period. He executes this macro to obtain this information. In the example, the result is shown in the row % growth over previous period. This gives him the possibility to check the consistency of the forecast figures. A great variation in the growth figures may lead him to modify the forecast. For this example, please refer to the macro book SDP Book 9AEXAM VIEW (SALES DATA).

Advanced Macros

401

80

SAP Online Help

07/04/02

Adjust Forecast Depending on LifeCycle


A demand planner is planning a product (for example, microprocessor chips) whose sales are significantly impacted by the product's lifecycle. First, he plans demand for the product without taking into consideration the effects of different lifecycle phases. He saves this first forecast in the row Baseline forecast. Now, he wants to incorporate a factor of, say, 1.4 into the demand for periods for which the product is live (that is, in its growth or maturity phases) and a factor of 0.8 into the demand for periods in which the product is not live (not in its growth or maturity phases). By executing this macro, the planner obtains the Final forecast which has been adjusted for different lifecycle stages. For this example, please refer to the macro book SDP Book 9AEXAM VIEW (SALES DATA).

Advanced Macros

401

81

SAP Online Help

07/04/02

Values of Row 1 Shift by Offsets in Row 2


A demand planner has finished planning demand for the finished product in the given horizon and is interested in finding the demand for dependent components. One unit of component 1 is required to make one unit of the finished product; and under normal circumstances the procurement lead time for component 1 is one month. In previous years, the supplier has been unable to meet the demand for component1 in May on time. Therefore, in order to meet the demand for the finished product in June, a lag of 2 months is required. The order for component1 must be placed in April. In the macro, the month of April (column 4) for row 2 will contain a value of 2 while other columns of this row will contain a value of 1. The macro shows the demand planner the period-dependent demand for component1. Example: Demand for Finished Product and Component 1 January Demand for Finished Product (Row 1) Offsets (Row 2) Demand for Component 1 (Row 4) February 10 March 20 April 30 40 May June 50

10

1 20

1 30

1 90

Advanced Macros

401

82

SAP Online Help

07/04/02

Submit a User-Specific Report


A demand planner wants to execute a program to import data from R/3 to APO before doing any demand planning, He does so by executing this macro. The macro triggers program ZUSER_REP. As the purpose of the macro is to import data for demand planning, the macro is defined as a start macro. Another possible use of this macro would be to attach the final forecast figures to an email which is sent to the supply chain manager for review. The macro could be defined as an exit macro so that the email is sent automatically once the demand planner has finished planning.

Advanced Macros

401

83

SAP Online Help

07/04/02

Trigger Alert Based on Reorder Point


A planner is planning supply and demand for a product at a warehouse location. Row 1 of the data view shows inventory levels for this product at this location. The planner wishes to know when he needs to order new inventory. The macro determines for each period whether the stock level has fallen below the reorder level for this product/location combination. If it has, an alert is triggered informing the planner that he needs to reorder.

Advanced Macros

401

84

SAP Online Help

07/04/02

Popup With Standard Deviation of Forecast Key Figures


A demand planning coordinator is reviewing the forecasts made by two different departments (for example, production and marketing) for twelve periods. To get a quick impression of the standard deviation figures of the two forecasts, he executes this macro. The macro opens a dialog box showing the standard deviations of the forecasts. The planner does not need to view them in the planning table or save them once he has completed the forecast. For this example, please refer to the macro book SDP Book 9AEXAM VIEW (SALES DATA).

Advanced Macros

401

85