FOR loop in script logic

Dear Gurus,
This is the logic I am working with:
*FOR %MONTH% = 2008.FEB,2008.MAR,2008.APR,2008.MAY,2008.JUN,2008.JUL,2008.AUG,2008.SEP
//CHECK IF THE VALUE OF THE ACCUMULATED DEPRECIATION IS GREATER THAN THE CAPITALIZED ASSET VALUE//
[ACCOUNT].[#AccumDepr] = (([ACCOUNT].[AccumDepr]+[ACCOUNT].[Depreciation])>[ACCOUNT].[EQUIPMENT1]? [ACCOUNT].[EQUIPMENT1] : ([ACCOUNT].[AccumDepr]+[ACCOUNT].[Depreciation]))
*NEXT
I am trying to execute the above script logic, but the system is throwing an error that says 
"Duplicate formula found:  [ACCOUNT].[#AccumDepr] = (([ACCOUNT].[AccumDepr]+......."
Any idea why this is happening?
Also, could you please suggest a better way of writing the above code?
Thanks,
Vijay.

As a testing scenario, I have calculated the depreciation in a different part of the same logic.  Here it is:
//This logic calculates the accumulated depreciation amount for the time period specified in the logic
//NOTE:  This logic is not very dynamic and is only valid for the accounts specified in the logic
//A FUTURE ENHANCEMENT TO THIS LOGIC WOULD BE TO MAKE THE "LIFE" OF THE ASSET A $DATAMANAGER VARIABLE$
//AND WRITE A CUSTOM SCRIPT LOGIC
//BEGIN SCRIPT LOGIC FILE//
//CONSTANTS
*XDIM_MEMBERSET CATEGORY=ACTUAL
*XDIM_MEMBERSET ACCOUNT=Depreciation,AccumDepr,NBV_EQUIPMENT1,EQUIPMENT1
*XDIM_MEMBERSET ENTITY=STORE1
*XDIM_MEMBERSET TIME=2008.JAN,2008.FEB,2008.MAR,2008.APR,2008.MAY,2008.JUN,2008.JUL,2008.AUG,2008.SEP
//BEGIN: POPULATE NET BOOK VALUE FROM CAPITALIZED ASSET VALUE //
*WHEN ACCOUNT
*IS EQUIPMENT1
     *WHEN TIME
     *IS 2008.JAN
          *REC(FACTOR=1,ACCOUNT="NBV_EQUIPMENT1")
     *ENDWHEN
*ENDWHEN
*COMMIT
//END: POPULATE NET BOOK VALUE FROM CAPITALIZED ASSET VALUE   //
//BEGIN: CALCULATE DEPRECIATION //
*WHEN ACCOUNT
*IS EQUIPMENT1
     *REC(EXPRESSION=(%VALUE%/6),ACCOUNT="Depreciation")
*ENDWHEN
*COMMIT
//END: CALCULATE DEPRECIATION   //
//BEGIN: CALCULATE ACCUMULATED DEPRECIATION AND NET BOOK VALUE //
*FOR %MONTH% = 2008.FEB,2008.MAR,2008.APR,2008.MAY,2008.JUN,2008.JUL,2008.AUG,2008.SEP
//CHECK IF THE VALUE OF THE ACCUMULATED DEPRECIATION IS GREATER THAN THE CAPITALIZED ASSET VALUE//
*WHEN CATEGORY
*IS ACTUAL
*REC(EXPRESSION=IIF((([ACCOUNT].[AccumDepr] + [ACCOUNT].[Depreciation])>[ACCOUNT].[EQUIPMENT1]), [ACCOUNT].[EQUIPMENT1], [ACCOUNT].[AccumDepr]+[ACCOUNT].[Depreciation]))
*ENDWHEN
*NEXT
//*FOR %MONTH% = 2008.FEB,2008.MAR,2008.APR,2008.MAY,2008.JUN,2008.JUL,2008.AUG,2008.SEP
//CHECK IF THE NET BOOK VALUE OF THE ASSET IS LESS THAN ZERO//
//*[ACCOUNT].[#NBV_EQUIPMENT1] = (([ACCOUNT].[NBV_EQUIPMENT1]-[ACCOUNT].[Depreciation])>0? ([ACCOUNT].[NBV_EQUIPMENT1]-[ACCOUNT].[Depreciation]) : 0)
//*NEXT
*COMMIT
//END: CALCULATE ACCUMULATED DEPRECIATION AND NET BOOK VALUE   //
//END SCRIPT LOGIC FILE//
Please let me know if there is a better way to write this code.
Thanks for all your help.

Similar Messages

  • Help in script logic - problem in FOR loop

    Hi Experts,
    We are using BPC 7.5 SP08. I have written a FOR loop in script logic default.lgf which is as follows:
    *FOR %TIM_MEM%=%TIME_SET%
    *XDIM_MEMBERSET TIME =%TIM_MEM%
    *WHEN P_ACCT2
    *IS "OSDU"
    REC(EXPRESSION=[P_ACCT2].[ASSTCAINVURO][P_ACCT2].[COGSUPRVIPSA]/[P_ACCT2].[ASSTUPRVTAQTY],P_ACCT2="COGSUIPSAO")
    *ENDWHEN
    *COMMIT
    *NEXT
    As per my requirement, all this members: [ASSTCAINVURO], [COGSUPRVIPSA], [ASSTUPRVTAQTY] exists for months September to next year's August. But in my input schedule, the months are from August to next year's July(which is the company's fiscal year). Consequently the loop runs for month August to next year's July while I need to run the loop 1 month late(i.e. September to next year's August). This was achieved earlier by hard-coding the time members which we cannot afford as this requires to update these hard-coded member IDs every year.
    We have also tried using the "NEXT" property of TIME dimension as follows:
    *XDIM_MEMBERSET TIME =%TIM_MEM%.NEXT
    but %TIM_MEM%.NEXT doesn't get the month in 'NEXT'.
    Please suggest if there is any way out to solve this problem.
    Thanks in advance.

    Hi Appu,
    Even if you restrict the scope using the XDIM statement, your script will just run the number of times as per the for loop. Actually, in reality, the same calculation is happening again and again, in your code; since your calculation is not based on the time member.
    To use the for loop effectively, you need to incorporate the time member in your calculation.
    Please look at the below sample code:
    *XDIM_MEMBERSET TIME = %TIME_SET%
    *FOR %TIM_MEM%=%TIME_SET%
       *WHEN P_ACCT2
       *IS "OSDU"
          *REC(EXPRESSION=<CALCULATION>,P_ACCT2="COGSUIPSAO")
       *ENDWHEN
    *NEXT
    And in your calculation, you can use statements like
    ([P_ACCT2].[ASSTCAINVURO],TMVL(1, [TIME].[%TIM_MEM%]))
    This will ensure that everytime (as per the for loop), the calculation works on separate set of data.
    Hope you got the idea.

  • Script Logic like a function

    Hi all,
    I want to execute a load of data from a year and actual version to year + 1 and budget version based in some assumptions filled in another input schedule. I thought that is possible using a script logic, so i create the script and i don´t know how to call it, Just from de the DEFAULT.LGF but is not my idea for this, cause every change in the data will execute this calculation....  Thats is the scenario:
    Input Schedule
    Time 2011.JAN
    ========== Budget
    Account%        5%
    Real data Query
    Time 2010.JAN
    ==========Actual
    Account1____100
    What i want
    Time 2011.JAN
    ============BUDGET
    ACCOUNT1        105
    There is another way to do that? I
    Thanks

    Hi,
    For executing a script logic, you need to follow few steps.
    1. Create an SSIS package to call your script logic in business intelligence development studio (BIDS) - (please refer to the SSIS package for currency conversion)
    2. Create a DM package to call the above SSIS package (please refer to the DM package for currency conversion)
    You can run the above DM package to execute your script.
    Hope this helps.

  • BPC 10.0 Script Logic: Combination of *FOR *WHEN *LOOKUP

    Hi experts,
    I'm working on a requirement to copy values from one model to another and aggregate to values.
    Basically my script looks like that:
    *LOOPUP OTHER_MODEL
    *DIM VERSION = VERSION
    *DIM TIME = TIME
    *FOR %LOOP_CST% = %COSTCENTER_SET%
    *DIM CST_%LOOP_CST%: COSTCENTER = %LOOP_CST%
    *NEXT
    *ENDLOOKUP
    *FOR %SEL_CST% = %COSTCENTER_SET%
         *WHEN COSTCENTER
         *IS = %SEL_KST%
              *WHEN COST_TYPE
              *IS = "CST_NA"
                   *REC(EXPRESSION = LOOKUP(%SEL_CST%), COSTCENTER = [COSTCENTER].AGGR_LEVEL, CURRENCY = "CURR_NA")
              *ELSE
                    *REC(EXPRESSION = LOOKUP(%SEL_CST%), COSTCENTER = [COSTCENTER].AGGR_LEVEL, CURRENCY = "EUR")
              *ENDWHEN
         *ENDWHEN
    *NEXT
    *COMMIT
    Unfortunately, this is not working.
    If I include the for-loop inside the when-loop it is working. However, the values are multiplied based on the number of records.
    Is there another possibility to solve this issue?
    Thanks in advance,
    Benjamin

    Good Morning.
    First of all thank for answering and sorry for the incomplete code.
    It was only a test, I was trying to do a more dificult script but given the error I tried to simplify as much as posible the code.
    The complete problem it's that I have two models (Contracts and Planning). In one of them (Contracts) the user have to introduce values in UNITS level of dimension TIME.
    An example of data would be:
    DIMENSION ACCOUNT_RS = PRICEM2
    DIMENSION TIME = 2014.UNITS
    With value = 50
    In another model (Planning) I have values for another member of dimension ACCOUNT_RS for example:
    DIMENSION ACCOUNT_RS = PERCENTAGEARENT
    DIMENSION TIME = 2014.JAN
    Value = 0.5
    DIMENSION ACCOUNT_RS = PERCENTAGEARENT
    DIMENSION TIME = 2014.FEB
    Value = 0.3
    DIMENSION ACCOUNT_RS = PERCENTAGEARENT
    DIMENSION TIME = 2014.MAR
    Value = 0.4
    What I am trying to do is to read from model Contracts the value for the dimension ACCOUNT.
    For doing this I tried to build a LOOKUP to the model Contracts in the following form:
    //JAN, FEB ...
    *SELECT(%MON_SEL%,MONTHNUM,TIME,LEVEL= MONTH) 
    //2014, 2015...
    *SELECT(%YEA_SEL%,YEAR,TIME,LEVEL = YEAR)
    *LOOKUP Contracts
      *FOR %YEA_ACT% = %YEA_SEL%
      *FOR %MON_ACT% = %MON_SEL%
      //TIM_2014.JAN, TIM_2014.FEB
      *DIM TIM_%YEA_ACT%.%MON_ACT%:TIME = %YEA_ACT%
      //ACS_2014.JAN, ACS_2014.FEB
      *DIM ACS_%YEA_ACT%.%MON_ACT%:ACCOUNT_RS = PRICEM2
      *NEXT
      *NEXT
    *ENDLOOKUP
    *WHEN ACCOUNT_RS
    *IS PERCENTAGEARENT
      *FOR %YEA_ACT% = %YEA_SEL%
      *FOR %MON_ACT% = %MON_SEL%
      *WHEN TIME
      *IS %YEA_ACT%.%MON_ACT%
      //2014.JAN ..
      *REC(EXPRESION = LOKKUP(ACS_%YEA_ACT%.%MON_ACT%) )
      *ENDWHEN
      *NEXT
      *NEXT
    *ENDWHEN

  • How To Set the Resultstate of Business Logic CO for Loop Decision Action

    Hi,
    I'm using a pre-conditional loop block in my GP process and using a Business Logic CO for the loop decision action. My expectation is the business logic CO should be executed at background and based on its resultstate the loop flow will happen. I've 2 resultstates in the loop decision (bus logic CO) - Continue and Break. I'm setting these two resultstates in the following way :
    Continue : BOOL(@currentLevel < @totalLevel)
    Break : !BOOL(@currentLevel < @totalLevel)
    currentLevel and totalLevel are the two input parameters (unsigned int type) of the business logic CO. If I test the CO it works fine and displays the correct resultstate. But at runtime the process gets paused at the loop decision action CO. I see the loop decision action link in my GP workcenter and UWL and on clicking of it nothing happens. If I refresh the screen still it's there as before.
    Anybody who can throw any light on this issue will be highly appreciated. And reward points guranteed for any help to solve the issue
    Thanks in advance,
    Dipankar

    Hi,
    Well I solved this issue myself ! After lot of research I found out that the resultstates should be in all small case <b>continue</b> and <b>break</b> and NOT Continue or Break.
    But now I've a different issue:
    I've an initial action under a sequential block. Then the pre-conditional loop block with a loop decision action and a loop body block(seq block).
    The expectation is initially the decision action should get the output param passed by the initial action and then in the iterations it will get the values passed by the output params of the loop body action. To achieve that I have mapped the output param of the initial action to the input param of the decision action and the input and output param of the loop body action. But it seems that the loop decision action though mapped to both the output of the initial action and the loop body action takes the value only from the initial action over the iterations and the values from the loop body action are not getting passed to the loop decision action. The context parameter value of the loop decision action remains static and it becomes an infinite loop.
    Any help to resolve this issue will be highly appreciated.
    Thanks,
    Dipankar

  • Logic error in for loop

    I have a JSP form which list modules that student can take. Some of these modules have prerequisite and some do not.
    In order to successfully register a student, I have a number of requirements e.g. must not be already register; the registration date must not have passed etc.
    My problem is in my code logic. For example, when a student selects a module, which does not have a prerequisite, and a module, which has a prerequisite and click on the Register button, an Error.jsp page is displayed because he has not satisfied the prerequisite for the second module.
    What the program does is that it registers the first module which dose not has a prerequisite and display the Error.jsp page.
    This is confusing for the user because they expect to do the process again and do not know that the first module has been register successfully.
    Here is my code
    private int enroll()throws SQLException,IOException
          // Get the check box values
          String checkboxNames[] = request.getParameterValues( "checkbox" );
          moduleVector = (Vector) session.getAttribute( "moduleVector" );
          //Get the student bean
          studentBean = (StudentBean) session.getAttribute( "studentBean" );
          boolean isEnrolled = false;
          String studentId = studentBean.getStudentId();
          int maxModule = Integer.parseInt(studentBean.getMaxModule());
          for (int i = 0; i < checkboxNames.length; i++) {
            String moduleId = checkboxNames;
    // First, make sure that this student is not already
    // enrolled for this module, and he/she has never
    // taken and passed the module before.
    isEnrolled = srsBean.isEnrolledIn( moduleId, studentId );
    if (isEnrolled){
    session.setAttribute("pre_enrolled", moduleId);
    return PREVIOUSLY_ENROLLED;
    // Now we make sure that the registration date has not
    // already passed
    Calendar rightNow = Calendar.getInstance();
    int rightNowMonth = rightNow.MONTH;
    int rightNowDay = rightNow.DAY_OF_MONTH;
    if ( rightNowMonth > Constants.REGISTER_DATE_MONTH ) {
    return PASSED_REGISTER_DATE;
    }else if( rightNowMonth == Constants.REGISTER_DATE_MONTH ) {
    if ( rightNowDay > Constants.REGISTER_DATE_DAY ) {
    return PASSED_REGISTER_DATE;
    int noModule = srsBean.noModuleEnrolledIn( studentId );
    // Now we make sure we don't erroll student on more
    // modules that the are allowed to do.
    if (!(noModule < maxModule)){
    // convert maxModule into string so we can use setAttribute
    String max = String.valueOf(maxModule);
    session.setAttribute("exceed_max_no", max);
    return EXCEEDED_MAX_NO_MODULE;
    // if there are any prerequisites for this module, check
    // to ensure that the student has completed them.
    if ( srsBean.hasPrerequisites(moduleId)) {
    Enumeration e = srsBean.getPrerequisites(moduleId);
    while ( e.hasMoreElements() ) {
    String pre = (String) e.nextElement();
    // See if the Student's Transcript reflects
    // successful completion of the prerequisite.
    if (!srsBean.verifyCompletion(moduleId, studentId)){
    session.setAttribute("prereq_not_sat", moduleId);
    return PREREQ_NOT_SATISFIED;
    // if we made it to here in the code, we're ready to
    // officially enroll the student.
    srsBean.enroll( studentId, moduleId );
    return SUCCESSFULLY_ENROLLED;
    How can i fix this problem ?

    1. well first check whether all modlues can be registered..
    2. you need to remove that in your for loop
    srsBean.enroll( studentId, moduleId );
    3. if all conditions are satisfied.
    for (int i = 0; i < checkboxNames.length; i++) {       
      String moduleId = checkboxNames<i>;
      srsBean.enroll( studentId, moduleId );
    }4. put the above code before
    return SUCCESSFULLY_ENROLLED;

  • Creating a loop for this working script

    I am successfully using this script I found to extract hyperlinks from RTF text:
    however I need to copy each file to the desktop and change the file name to do so.
    How can I add to the script the ability to
    1 - choose a folder
    2 - choose a destination folder
    3 - loop the script to process all files found in the folder?
    I am a new user and I have several students messages all with the same patterns. I will be very grateful to anyone.
    Thanks
    set filePath to (path to desktop folder as text) & "students.rtf"
    set startDelimiter to "{HYPERLINK \""
    set endDelimiter to "\"}}"
    set linkDelimiter to "Read this message"
    set rtfText to read file filePath
    set text item delimiters to startDelimiter
    set theItems to text items of rtfText
    if (count of theItems) is greater than 1 then
       repeat with i from 2 to count of theItems
           set text item delimiters to endDelimiter
           set a to text items of (item i of theItems)
           set theLink to item 1 of a
           set text item delimiters to linkDelimiter
           set b to text items of (item i of theItems)
           set text item delimiters to theLink
           set (item i of theItems) to b as text
       end repeat
    end if
    set text item delimiters to startDelimiter
    set adjustedText to theItems as text
    set text item delimiters to ""
    writeTo(adjustedText, filePath, false, string)
    (*==================== SUBROUTINES ===================*)
    on writeTo(this_data, target_file, append_data, mode) -- append_data is true or false, mode is string etc. (no quotes around either)
       try
           set target_file to target_file as text
           if target_file does not contain ":" then set target_file to POSIX file target_file as text
           set the open_target_file to open for access file target_file with write permission
           if append_data is false then set eof of the open_target_file to 0
           write this_data to the open_target_file starting at eof as mode
           close access the open_target_file
           return true
       on error
           try
               close access file open_target_file
           end try
           return false
       end try
    end writeTo

    etnad wrote:
    the script finds the folder
    chooses the destination folder
    Opens the file for writing
    But the result is always false
    I am really new to applescript .... maybe there is something missing in the actual writing part of the script?
    Thanks
    I just tried copy/paste the script, it works well here.
    Uses the "on error" in the script, and the history of the editor to know the error.
    like this
        on error tError
              log "Error : " & tError
              try
                   close access file open_target_file
             end try
             return false
        end try
    end writeTo
    In the "AppleScript Editor" :
    1- click on the tab "Event Log"
    2- Run the script
    3- Check the text in  "Event Log" to know the error.

  • Need Example for AVG() function in script logics...

    Hi Everyone,
                      I need to calculate average for all the account members ...
    so if anybody worked with this AVG() in Script logics please share with me...................

    What do you mean by calculate average? Average for the period or for some other parent or..? Where do you want to store this average? How do you want to use this average???

  • Can you give a document link for script logic for NW version7??

    Hi all,
        who can give a document link for script logic for nw version7??
        thanks in advance!!

    Hi Sheldon,
    I read through your "HOW to...Custom BADI for replicating Destination_App...." and it was great. However, Can this call also be used with WHEN/ENDWHEN statements? In the MS version, when using Destination_App, I was also able to map source accounts into the correct destination accounts as well as source E type dim to desination E type dim with the following script (the mapping to destination ID was stored as properties within the source dimensions).
    *INCLUDE SYSTEM_CONSTANTS.LGL     
    *SELECT(%OPACCT%, "[ID]", "OPACCOUNT", " [TRF_FPA] = 'Y'")
    *SKIP_DIM = COSTCTR
    *ADD_DIM = BRANDS
    *RENAME_DIM OPAccount = Account_F
    *RENAME_DIM CATEGORY = CATEGORY_F
    *RENAME_DIM ENTITY = MARKET
    *RENAME_DIM DATASRC = DATATYPE
    *XDIM_MEMBERSET ENTITY = %ENTITY_SET%
    *XDIM_MEMBERSET CATEGORY = %CATEGORY_SET%
    *XDIM_MEMBERSET TIME = %TIME_SET%     
    *XDIM_MEMBERSET OPACCOUNT = %OPACCT%
    *DESTINATION_APP = FPA
    *CLEAR_DESTINATION
    *DESTINATION OPACCOUNT = %OPACCT%
    *DESTINATION TIME = %TIME_SET%
    *DESTINATION CATEGORY = %CATEGORY_SET%
    *DESTINATION CURRENCY = LC,USD
    *WHEN ENTITY
    *IS %ENTITY_SET%
    *REC(ENTITY=COSTCTR.FPA_MKT,OPAccount=OPAccount.Consol_FPA)     
    *ENDWHEN     
    *COMMIT
    I have tried the following code in the NW version, and it won't validate. Do you know if there's a way to achieve this?
    *XDIM_MEMBERSET CATEGORY<>ACTUAL
    *XDIM_MEMBERSET ACCOUNTHR =BASE_ANNL_SAL,BONUS,BENEFITS_TAX
    *XDIM_MEMBERSET CURRENCY=LC
    *START_BADI DAPP
    DESTINATION_APP=CC_PLAN
    RENAME_DIM="ACCOUNTHR=ACCOUNTCC"
    WRITE=OFF
    *END_BADI
    *WHEN ACCOUNTHR
    *IS "BASE_ANNL_SAL","BONUS","BENEFITS_TAX"
    *REC(ACCOUNTCC=ACCOUNTHR.CCPLANACCT)     
    *ENDWHEN
    Regards,
    Karen

  • Script logic not working for GL account with Zero balance

    Dear Experts,
    I have a scenario where the GL account balance in ECC is 0  and when a script logic runs in BPC the same should capture a closing balance as "1".
    Though I have written the below logic, this is not getting executed and writing back the value as "1".
    Kindly help me on the same.
    *WHEN ENTITY
    *IS "ABC"
    *WHEN ACCOUNT
    *IS "20300000"
    *REC(EXPRESSION = 11, ACCOUNT = 20300000,FLOW = F99, ENTITY = ABC, PROFITCENTER  = 130010 ,  INTERCO = I_NONE , CONSOSCOPE = G_NONE, CURRENCY = LC ,CATEGORY = ACTUAL, AUDITID = INPUT)
    *ENDWHEN
    *ENDWHEN
    *COMMIT
    Regards,
    Shilpa

    Hello Vadim Kalinin,
    Thanks for the very swift help.
    Merger of the client happened in 2007. ECC is using the " 20300000- change in fair value " account to record both pre-acquisition and post-acquisition values.
    Since the treatment of pre-consolidation and post consolidation reserves is different the split of the amount between pre and post-acquisition values has to be done. For the same post acquisition value is reduced from this account using a script logic as below.
    WHEN FLOW
    *IS "F99"
    *WHEN ENTITY
    *IS "ABC"
    *REC(EXPRESSION = ([ACCOUNT].[20300000] -3258603),ACCOUNT = 20300000,FLOW = F99,  INTERCO = I_NONE , CONSOSCOPE = G_NONE ,CURRENCY = LC ,CATEGORY = ACTUAL )
    This logic worked when the account has a figure, but in July 2014 in ECC the account had a transaction and the balance has become Zero. Until this account has a figure this pre acquisition logic is not working.
    For making this work, I am trying to write a new logic to make the balance of this account as "1" in BPC through the script logic.
    Kindly suggest me on the same.
    Regards,
    Shilpa

  • Nested for loop logic

    I am trying to create a triangle with for loop. i wrote this codepublic class Test {
        public static void main(String[] args) {
            for(int x = 1; x <= 6; x++) {
                for(int y = 1; y <= (x*2-1); y++) {
                    System.out.print("x");
               System.out.println("");
    }and i got answer like this
    x
    xxx
    xxxxx
    xxxxxxx
    xxxxxxxxx
    xxxxxxxxxxx
    but what i am trying to do is that will strat showing the results from the middle.
    ___X___
    __XXX__
    something like that. Need some explaination or hint what i am missing. (underscores are not part of my program:))
    thanks

    So since the spaces look right now, lets step through the plus loop
    for(k = i; k <= i*2-1; k++)
                    System.out.print("+"); First time starting to go through the loop i is 0.
    So 0 is not <= -1 [0*2-1 = -1] so no pluses get printed on the first time through.
    the second time starting to go through the loop i is 1.
    So first time through 1 is <= 1 [1*2-1 = 1] so print a +.
    Second time through 2 is not <= 1, so we end with just one +.
    The third time starting the loop i is 2.
    So first time through 2 is <= 3 [2*2-1 = 3] so print a +.
    Second time through 3 is <= 3 so print another +.
    Third time through 4 is not <= 3 so we end with just two +s.
    Uh oh, we wanted three s not two s, where did we go wrong? Let's try one more and see if we can see it.
    The fourth time starting i is 3.
    So first time through 3 is <= 5 [3*2-1 = 5] so print a +.
    Second time through 4 is <= 5 so print another +.
    Third time through 5 is <= 5 so print another +.
    Fourth time through 6 is not <= 5 so we end with just three +s.
    Now we have a choice, we can get mad and start throwing stuff and screaming at the stupid computer for doing it all wrong, or we can realize the problem is somewhere in the code and we can find it and fix it.
    What do you think?
    JSG
    EDIT: Note: you actually have two problems displayed here, both should be obvious but one is slightly hidden in the output until you fix the other. Both should have made themselves clear if you had done a simple step through yourself. As i demonstrated it is really easy to do and something you better get real good at if you want to be a good programmer.
    Edited by: JustSomeGuy on Nov 24, 2008 11:22 AM

  • Script Logic: Using a property in MDX *REC statement (BPC NW)

    Hi,
    Is it possible to use a Property in an MDX statement without using  *LOOKUP() function? I have script successfully working but it takes 15 minutes to execute and would like to speed it up.
    I understand that [DIMENSION].[MEMBER].Property is not valid syntax, and do not believe NW has any other functions to resolve the issue, except *LOOKUP which takes a long time.
    Specific Example is below:
    I have a piece of script that successfully splits JV Expense by customers. A Profit Share planning driver determines the percentage that each customer is entitled to. Typically this will be 100%, but could be 50% between two customers.
    The PROFIT SHARE planning drivers records, and PARTNER_INCOME transactional records are below:
    ACCOUNT
    ENTITY
    PARTNER
    SIGNED DATA
    PROFIT_SHARE
    UK_001
    PARTNER_A
    0.5
    PROFIT_SHARE
    UK_001
    PARTNER_B
    0.5
    PROFIT_SHARE
    UK_002_PLANNING_DRIVERS
    PARTNER_B
    1.00
    PARTNER_INCOME
    UK_001
    NO_PARTNER
    $5,000
    PARTNER_INCOME
    UK_002
    NO_PARTNER
    $5,000
    UK_001 has two partners that are each entitled to 50% of the $5,000 NET PROFIT.
    For UK_002, one one single Partner is entitled to 100% of the $5,000 NET PROFIT.
    Using script logic, you can scope the Profit Share account (PROFIT_SHARE) - , and use a *REC statement to multiply this by the driver. It would look like:
    *XDIM_MEMBERSET ACCOUNT = PROFIT_SHARE
    *WHEN ACCOUNT
    IS *
    *REC (EXPRESSION = %VALUE% * ([ACCOUNT].[PROFIT_SHARE],[PARTNER].[NO_PARTNER]), ACCOUNT = PARTNER_PROFIT_SHARE)
    *ENDWHEN
    This wouldn't be a problem if the Planning Driver is always stored on the same Entity that the Income is stored on, but for UK_002, the planning driver is stored on another Entity - which is stored in a the PLAN_DRIVER_REF property of the entity. It should use UK_002_PLAN_DRIVERS
    ID (Entity)
    PLAN_DRIVER_REF
    UK_001
    UK_002
    UK_002_PLAN_DRIVERS
    UK_002_PLANNING_DRIVERS
    In this scenario, we need to switch out the Entity used in the MDX, however I do not believe you can use a property in MDX - can anyone confirm?
    I have currently implemented the *LOOKUP functionality to loop through, changing each *LOOKUP partner for each loop.
    Lookup:
    *LOOKUP PLANNING_JV_US
    *FOR %LOOP_ASLS% = %ASL_LOOKUP_LOOP_VARIABLE%        
      *DIM LOOK_%LOOP_PARTNERS%:ACCOUNT = "PROFIT_SHARE"
      *DIM LOOK_%LOOP_PARTNERS%:PARTNER= %LOOP_PARTNERS%
    *NEXT
    *DIM ENTITY = ENTITY.PLAN_DRIVER_REF                   //   Use PLAN_DRIVER_REF Property of Entity
    *ENDLOOKUP
    Scope and *REC:
    *XDIM_MEMBERSET ACCOUNT = PROFIT_SHARE
    *WHEN ACCOUNT
    IS *
    *FOR %LOOP_PARTNERS% = %PARTNER_LOOKUP_LOOP_VARIABLE%      // 1000 Partners
    *REC(EXPRESSION = %VALUE% * LOOKUP(LOOK_%LOOP_PARTNERS%), PARTNER= %LOOP_PARTNERS%, ACCOUNT = TCOJVSHAR_CALC, AUDIT_ID = PP_EXPENSE_BY_PARTNER)
    *NEXT
    *ENDWHEN
    The problem with the above, is that because the Lookup is being generated for every single Partner, there are significant numbers of loops.
    Does anyone know of another way this can be implemented in Script Logic? Otherwise we'll need to explore BAdI route.
    Thanks,
    Nick

    Hi Nick,
    Use property in LOOKUP - will dramatically speed up the calculation without FOR/NEXT.
    Vadim

  • Variable in  script logic

    Follow is the script code from previous post
    *XDIM_MEMBERSET ACCOUNT = ACC1
    *FOR %My_Var% = %ENTITY_DIM%
    *WHEN ENTITY
    *IS *
    *REC(EXPRESSION = (GET (ENTITY = %My_Var%.PROP1)), ENTITY = %My_Var%)
    *ENDWHEN
    *NEXT
    I understand that  both %My_Var% and %ENTITY_DIM% are variables, my question is how %My_Var% and %ENTITY_DIM% get the value during the process of the code, do we neeed to define the variable some where else before we use them? I remeber in FOX, we need to define the variable before we can use it.
    also is there a difference if I use $My_Var$ to replace %My_Var%?

    nilanjan,
    Thanks for the explanation,I have another question regarding to the variables.
    I need to get the YTD salary. in BPS the pseudocode code is as following:
    data YTD_salary type amount
    loop at each_month,
       YTD-Salary =  YTD-Salary  + current_month.
       if the  YTD-Salary  > FICA CAP.
       exit.
    Endloop
    How can we archive the same in BPC script logic with a variable to capture the YTD-Salary and pass it to next month?

  • Help in script logic

    Hi Experts,
    We are using SAP BPC 7.5 NW Version SP08. We are using a script logic that calculates the opening value of inventory(ASSTCAINVAMO) for each month except the 1st month of financial year for which the value is entered from an input schedule. The opening value of inventory of each subsequent months are calculated when the parameters for production(e.g. OSDA) are entered from a separate input schedule. The following script logic is written for the calculation:
    *FOR %TIM_MEM%=%TIME_SET%
    *XDIM_MEMBERSET TIME =%TIM_MEM%
    *WHEN P_ACCT2
    *IS "OSDA",
    REC(EXPRESSION=[P_ACCT2].[ASSTCAINVAMO]+[P_ACCT2].[RDPA][P_ACCT2].[EFFA][P_ACCT2].[OSDA]-[P_ACCT2].[CONVAMUR][P_ACCT2].[RDPU][P_ACCT2].[EFFU][P_ACCT2].[OSDU]-([P_ACCT2].[SALQAMBC]+[P_ACCT2].[SALQAMM]),P_ACCT2="ASSTCAINVAMO",TIME=TIME.NEXT)
    *ENDWHEN
    *COMMIT
    *NEXT
    The loop works fine, but it seems the list of time values are not coming in proper sequence. For example, the loop is running for 2011.NOV before it iterates for 2011.OCT. So when it iterates for 2011.NOV, it is not getting the opening value for the month and consequently 2011.DEC's opening value is calculated assuming 2011.NOV's opening value to be 0. In the input schedule the months are in proper sequence.
    Is there any way out so that the months come in proper sequence in the logic as well?
    Thanks in advance for any help.

    We had similar issue . we changed TIME members from Monthnames to numbers . i.e  changed 2011.JAN to 2011.01 . Then you get correct result  as you are expecting . Issue when using month names in combination of TMVL is that  , instead of getting 2011. MAY for TMVL(1,2011.APR) , it gets 2011.FEB . TMVL function some how takes alphabetical order instead of taking month order . Not sure if this behavior is with service pack . But never saw any thread reporting this issue .
    Anyways ,you can wait for other responses  as i am too curious to know if any one faced this issue and how did they resolve.

  • Condition in script logic.

    I need to copy the 'All Account'  % value in datasource 'A' to 'All Account' , All costcenters with in same data source.
    This I need to copy only for those cost centers, for  which transaction data exist in data source 'B' for this period
    How to achieve this in script logic.
    Appreciate input
    Regards,

    In such case you need to modify that script in the following way.
    Add
    *XDIM_MEMBERSET COSTCENTER = <source cost center>
    *SELECT(%ALL_CC%, ID, COSTCENTER, "[CALC] = 'N'")
    at the beginning and put the following loop around *REC statement.
    *FOR %ONE_CC% = %ALL_CC%
    *REC(EXPRESSION = [DATASRC].[A], DATASRC = B, COSTCENTER = %ONE_CC%)
    *NEXT

Maybe you are looking for