cancel
Showing results for 
Search instead for 
Did you mean: 

Help with DO DP Macro construct

Former Member
0 Kudos

Hi:

I need help with the DO macro construct.

The following works.

DO 3 TIMES.

your statements

ENDDO

What I want to do is to pass a layout variable value to the above DO. I tried a few combinations but none of them seem to work.

DO ( EVAL( LAYOUTVAR_VALUE( 'RESULT' ) ) TIMES.

statements

ENDDO

DO(

LAYOUTVAR_VALUE( 'RESULT' )

TIMES.

)

statements

ENDDO

Could you please help me with this and tell me what is the right construct? What I am trying to do is to loop through a certain number of times based on the value of a variable that has been defined in a previous step.

Thanks.

Satish

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi Satish

If you are using SCM 7.0/onwards, you may thing of using standard function ITERATION_COUNTER in the macro.

you can refer to the below link for details

http://help.sap.com/saphelp_scm70/helpdata/en/82/2101fac5288f4d8c7be7c20e604a8f/frameset.htm

Rgds, Sandeep

Former Member
0 Kudos

Hi Sandeep:

I actually tried some things that are supposed to work but they did not. I looked at iteration_counter function that you mentioned. It is a good idea. But as it states below, it keeps track of the number of iterations in the step. Not in the DO loop. I tried the following

While (layout_variable <= 1)

do something

layout_variable = layout_variable -1

endwhile

I also tried the other method that I mentioned when I created this thread. It did not work.

What I learned is that you have to be gentle with the macros. It is difficult to tell WHY something does not work - after some permutations and combinations, you can figure out what will work. For example, I tihnk that the following construct will work.

layout_variable = x

do

layout_variable = x-1

if layout_variable <= 1

exit

endif

do something

continue

ITERATION_COUNTER

ITERATION_COUNTER returns the number of iterations that have been carried out in the current step.

Former Member
0 Kudos

Hi - I like your puzzle, and I just created a macro in my sandbox that loops. I made a popup, where you enter a number, and that number becomes the number of loops. If I enter "10" then it loops 10 times. If I enter "90" then it loops 90 times, etc. I think the variable logic is what you are looking for. Although I have consulted for many years, this is my first time to ever answer a forum question, so I am sorry if I am not following protocol. Please let me know if this is the logic you are looking for?

Former Member
0 Kudos

Hi Susan:

Yes. THat is exactly what I am looking for. My e-mail address is. Could you send me the screen shot? Thanks for your help.

Satish

Former Member
0 Kudos

Satish,

I will try to write it here so that anyone else finding this thread can use it, too.

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( u2018Enteru2019 ; u2018Number_of_iterationsu2019 )

)

<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( u2018LOOPCOUNTERu2019 ;

EVAL( LAYOUTVAR_VALUE( u2018LOOPCOUNTERu2019 ) + 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

Please award points if this is helpful ....my first points

Susan

Former Member
0 Kudos

Thanks for the time taken. I awarded you the points.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi:

Also, if anyone has examples of WHILE/ENDWHILE, DO/CONTINUE, STOP, could you send them to me? the 9AEXAMPLES does not provide these.

Thanks a bunch.

Satish

Former Member
0 Kudos

Hello

I think I can help with this one if you are looping through columns in a dataview. Is this what yo uare trying to do?

Susan