Skip to content

Looping APO Macros

January 5, 2013

Click here to see my newer post with screenshots for this macro.

I love macros: they have the capability to improve the user experience and open the door to a wide variety of functionality.  You are largely only limited by your own imagination.

The next time somebody tells you that APO “does not support” something….. think twice.  Can a macro solve the problem?!!?

Here is one of my favorite macros:

Looping:

If you have a formula that must loop (due to the fact that it calculates one of its own inputs), you can loop it.  Below is code that I also posted at the SAP forum.

Writing a looping macro with an input for a variable loop number:

new step – 1 iteration

<Action Box> set loopcounter to 1

LAYOUTVARIABLE_SET ( ‘LOOPCOUNTER’ ; 1)

new step – 1 iteration

<Action Box> get Loop Number

LAYOUTVARIABLE_SET ( ‘LOOP_NUMBER’ ;

NUM_VALUES_INPUT( Enter ; Number_of_iterations )

)

<control statement>

DO

New step(s)

(Add your calculation steps here)

New step – 1 iteration

Add +1 to your Loop Counter

<Action Box> Add +1 to Loop Counter

LAYOUTVARIABLE_SET( LOOPCOUNTER ;

EVAL( LAYOUTVAR_VALUE ( LOOPCOUNTER ) + 1 )

)

<control statement>

IF

<condition>

Until loop number is reached

LAYOUTVAR_VALUE( ‘LOOPCOUNTER’ )

>

LAYOUTVAR_VALUE( ‘LOOP_NUMBER’ )

<control statement>

EXIT

<control statement>

ENDIF

<control statement>

ENDDO

From → APO Macros

6 Comments
  1. How do you handle multiple arguments in NUM_VALUES_INPUT() function for further processing? Please provide an example.

    • Ramesh,
      As far as I know, without any enhancements, NUM_VALUES_INPUT() allows only one value to be captured per pop up. However, you can collect several inputs from several input boxes that popup in sequence. Once the inputs are collected, then you can use the inputs in a formula.
      These are the ways that I know of that you can save the inputs:
      1. Temporarily as layout variables: The system will remember the variables that you collect until the user reloads data.
      2. In a vector using one extra key figure and VEC_LAYOUTVARIABLE_APP
      3. In a Ztable, where you create a user exit macro to read and use the table
      4. In several key figures (which may be a waste of key figures)
      Recently, I created a NUM_VALUES_INPUT() macro solution that saved several date values. The user could press a button to input start and end dates for four different plans, and the system would remember all of the date values until the user reloaded data on the screen. The dates were used to calculate a consensus plan.
      Here is a link to a copy of my notes that shows the macro code for one of the plans. This macro captures the user input for the start and end date of the STAT key figure. Then in my notes you can see how the dates are used to populate the Release key figure.
      Hope this helps.

      • Hi Artster,

        Thank you for your response.

        My problem is different. I have NUM_VALUES_INPUT( ‘desc’ ; ‘label1’ ; ‘label2’ ). Now I have 2 variables in the same dialog where the user can enter data. How do I handle these arguments?

      • Ramesh – I want to change my response to you, because I found that I do have notes about multiple inputs saved into a key figure. I have not done this, but here is a link to my notes: link

    • Ramesh,
      To my knowledge having more than one input variable in the same dialog box does not work. I am sorry I do not have a better answer for you in this case. As you can see in my code, I used two boxes that popped up one after the other in order to capture two.

Leave a comment