Financial Management Blogs by SAP
Get financial management insights from blog posts by SAP experts. Find and share tips on how to increase efficiency, reduce risk, and optimize working capital.
Showing results for 
Search instead for 
Did you mean: 

Like other program language or script, the logic script also supports Loop statement.

Let's see how it works.

Here is the syntax of *FOR - *NEXT statement.
     *FOR  {variable1} = {set1} [ AND {variable2={set2}]

           {other statement...}


And here is an example.




So what is the meaning of the example above?

1. We set a variable as %CURR%
2. %CURR% variable will be replaced with two values USD and EURO.
3. *REC statement includes %CURR% variable.
4. Therefore, it will be translated two statement as below
   because *REC statement exists inside of *FOR - *NEXT statement.


Let's assume %CURR% varible has USD,EURO,CHF,KRW then the it will be translated as below.



Someone may say "we can use multiple line of *REC statement".

Of course, it is correct if it is simple but we need *FOR - *NEXT statement because it can be used as a nested form.

For example,

        *FOR %YEAR%=2003,2004,2005 

If the user is using *REC statement,user should write 36 statements instead of above simple a *FOR - *NEXT statement.

(NOTE: BPC NW supports Nested FOR - NEXT in the version 7.5 )

In addtion, User may use two variable sets like the exmaple below.

        *FOR %X%=1,2,3 AND %Y%=A,B,C



So the first variable set and the second variable set will be matched 1 to 1; then will be replaced as the example below.

             *REC(FACTOR=1.5,TIME=1 ,CURRENCY=A) 
             *REC(FACTOR=1.5,TIME=2 ,CURRENCY=B) 
             *REC(FACTOR=1.5,TIME=3 ,CURRENCY=C)

What if the number of values is not matched between first and second variable?

If the first variable has less values than  the  second  variable,
the  extra  values  of  the  second  variable  will be  ignored. 

If  the  first  variable  has more values than the second variable,
the missing values of the second variable will be assumed null so please be careful to match the number of varible.

The last thing about *FOR - *NEXT is using data set variable as values.
Users can use data_set like %TIME_SET% instead of specifying all time members.
This is very useful when we use script logic with dynamic dataset.

For example, We can use 
        *FOR %MYTIME%=%TIME_SET%
instead of             

        *FOR %MYTIME%=2003.JAN,2004.JAN,2005.JAN               

Therefore, users can execute script logic dynamically based on the passed data sets.

We will see how to use GET and FLD function and memory variable in the next post as the last topic.