Skip to Content

BPC Script logic for Dummies? (Part 5)

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.

You must be Logged on to comment or reply to a post.
  • Hi James,

    Thanks for the informative blog again. Question on the BPC Netweaver version: Does this version support nested *FOR/*NEXT loops?

    I don't think it did a year ago, but I haven't checked in some time, so want to make sure. The documentation for the Netweaver version doesn't mention this as an option.


    • Hi Ethan,

      Unfortunately, NW doesn't support it.
      (I should have put a note. I will change it.)

      I didn't check version 10 but as I know it is same as version 7.5.

      Even though NW version doesn't support some functionality of Logic script, it can be supported using BADI which doesn't exist in BPC MS.

      Thank you for the good comment.

      James Lim

    • Hi Ethan,

      I just checked NW 7.5 and it worked.
      I had tested before I answered previous comment with NW 7.5 but there was a problem with my system so I posted wrong answer.

      Nested For - Next is supporting in BPC NW 7.5 and 10.

      Thank you.
      James Lim

      • Hi James,

        Great, thanks for testing! It would be nice to get the updated with this information. Do you have any pull there? 😉


        • Ethan,

          Good suggestion!
          I will ask it to document team.
          It will be updated so please check it later.

          Thank you.
          James Lim