IF ELSE statement / CMOD Code in BEX Query

Hi
I have a requirement in Inventory flow.
Material stock value at the end of each quarter has to be calculator based on cycle count indicator. I have all the values on my cube.
In the report, Calender year and quarter is on the selection screen.
When user enters 2014 and Q2, Data for April, May and June are displaying on the report. But user want data only for June.
At the end of quarter 2 is June, so he wants only Material stock value at the end of June.
If a material stock level is changed in April and May and not changed in June, not data is available for June in my Cube.
In this case for Quarter 2, if June data is missing, it has to look for May data. Even if MAY data is missing, it will have to look for April.
Even if April data is missing, it will have to look for March data.
The result should be
Plant    Q1    Q2    Q3   Q4
XYZ     100    100  100    100
If there is no change to stock level in April, May & June - at the end of Quarter 2, the stock value should be 100 as it was in end of Q1.
If no change was dont to stock level until December, the stock level should be 100.
Is there a way out using IF ELSE statements or through CMOD customer exit.
Regards,
Elango Murgesan

HI Elango,
the user input on CALQuarter always would be Single value??or can we expect ranges as well?
if single value,
then we can achieve it by having one more dummy KF.
lets say. user input is Q2. 
-> in your dummy KF, restrict the Calquarter/Calmonth to last quarter(i.e Q1)using customer exit and make the logic as you said above(last value based on calmonth).(make this KF hidden, as this is not required to display)
-> and in another KF restricted with Q2.Same logic, last value on Calmonth.((make this KF hidden, as this is not required to display)
and now you have 2 KFs in your report.  So in a formula, you can have condition-> if Q2 KF is blank, then Q1KF, else Q2 KF.
Hope you are getting my idea.. Please try this and let us know.
** if Q1 also null, then we can extend customer exit logic to may be last one year, and having last value on based on calendar month, we can still achieve i guess.
Regards,
Sakthi.

Similar Messages

  • Help using multiple if else statements & manual dynamic xml data input to trigger a goto and play.

    Below is code that has a timer countdown that reads off of the computer. Below in bold is code to read "if it reaches the date, go to and play frame (2).
    timer.removeEventListener(TimerEvent.TIMER, updateTime);
      timer.stop();
      gotoAndPlay(2);
    Below is code that is manual input-   I had set up a dynamic txt field in flash named it : raffle_tix_remain When loaded on to the host I can manulally update the xml code and the change will take effect.
    raffle_tix_remain.text = root.loaderInfo.parameters.raffle_tix_remain;
    My question:  Since the raffle_tix_remain is a manual input from a user to xml  Is there a way to tell flash once it refreshes and "raffle_ tix_ remain"  goes to (0) zero gotoAndPlay(2); and let it play like a "sold out" sign
    i guess that would be a  if else statement. 
    Code Below-----------------
    stop();
    var year:Number = 2011;
    var month:Number = 12;
    var day:Number = 30;
    var finalDate:Date = new Date(year,month-1,day);
    var timer:Timer = new Timer(100);
    timer.addEventListener(TimerEvent.TIMER, updateTime);
    timer.start();
    function updateTime(e:TimerEvent):void{
              var now:Date = new Date();
              var remainTime:Number = finalDate.getTime() - now.getTime();
              if (remainTime >0) {
                        var secs:Number = Math.floor(remainTime/1000);
                        var mins:Number = Math.floor(secs/60);
                        var hours:Number = Math.floor(mins/60);
                        var days:Number = Math.floor(hours/24);
                        var secsText:String = (secs%60).toString();
                        var minsText:String = (mins%60).toString();
                        var hoursText:String = (hours%24).toString();
                        var daysText:String = days.toString();
                        if (secsText.length < 2) {secsText = "0" + secsText;}
                        if (minsText.length < 2) {minsText = "0" + minsText;}
                        if (hoursText.length < 2) {hoursText = "0" + hoursText;}
                        if (daysText.length < 2) {daysText = "0" + daysText;}
                        day_txt.text = daysText;
                        hour_txt.text = hoursText;
                        min_txt.text = minsText;
                        sec_txt.text = secsText;
              else {
                        timer.removeEventListener(TimerEvent.TIMER, updateTime);
                        timer.stop();
                        gotoAndPlay(2);

    stop();
    var year:Number = 2011;
    var month:Number = 12;
    var day:Number = 30;
    var finalDate:Date = new Date(year,month-1,day);
      var now:Date = new Date();
    var timer:Timer = new Timer(1000);
    timer.addEventListener(TimerEvent.TIMER, updateTime);
    timer.start();
    function updateTime(e:TimerEvent):void{
             var remainTime:Number = finalDate.getTime() - now.getTime()-e.currentCount;
              if (remainTime >0 || raffle_tix_remain==0) {
                        var secs:Number = Math.floor(remainTime/1000);
                        var mins:Number = Math.floor(secs/60);
                        var hours:Number = Math.floor(mins/60);
                        var days:Number = Math.floor(hours/24);
                        var secsText:String = (secs%60).toString();
                        var minsText:String = (mins%60).toString();
                        var hoursText:String = (hours%24).toString();
                        var daysText:String = days.toString();
                        if (secsText.length < 2) {secsText = "0" + secsText;}
                        if (minsText.length < 2) {minsText = "0" + minsText;}
                        if (hoursText.length < 2) {hoursText = "0" + hoursText;}
                        if (daysText.length < 2) {daysText = "0" + daysText;}
                        day_txt.text = daysText;
                        hour_txt.text = hoursText;
                        min_txt.text = minsText;
                        sec_txt.text = secsText;
              else {
                        timer.removeEventListener(TimerEvent.TIMER, updateTime);
                        timer.stop();
                        gotoAndPlay(2);

  • IF ELSE Statement in BEx Query based on the results

    Hi experts,
    I want to realize the following IF/ELSE statement in a BEx Query in respect to the result values
    If the result of KF1 equals 0, than set the KF2 to 0, Else (KF1 NE 0) show the value of KF2
    Background: I want to report the order backlog. In the example above we have an incoming order value of 23.700,80 EUR in periode 12.2013 and an turnover of 22.370,80 EUR in periode 01.2014. The order backlog in ST (KF1) is 1 ST (12.2013) - 1 ST (01.2014) = 0 ST. The order backlog in EUR (KF2) is 23.700,80 EUR (12.2013) - 22.370,80 EUR (01.2014) = 1.330 EUR. The Order and Invoice is finished, but we have an positive order backlog in EUR (reason: less turnover as incoming order).
    For this case I want to realize the IF/Else statement to check if the oder backlog in ST = 0, if yes, than set the order backlog in EUR also to 0.
    Any best practices?
    Many thanks and best regards,
    Michael

    Hi Suman,
    thanks aigain for your reply!
    I have tried your proposal before you have posted it.
    In my special case the following if/else statement works successfully:
    CKF = calculated key figure
    Formula1 = (CKF1 == 0) * 0 + (CKF1 <> 0) * CKF2
    In my case the CKF2 is the result value from "Incoming Order value" - "Turnover"
    So I had to define a separate Formula (1:1 equals to CKF2) and then I was able to set "*CKF2" in the statement.
    The statement CKF2 = (CKF1 == 0) * 0 + CKF2 is not possible (because it´s not possible to calculate from CKF2 itself).
    Now it works
    Best regards,
    Michael

  • IF...ELSE.. STATEMENT in BEx Query Designer

    Hi,
    Why there is no IF, ELSE function in BEx Query Designer?
    Assuming I need to write the following logic, how can it be accomplished?
    IF (A=0 OR B=0)
        THEN 0
    ELSE IF ( B/A <0)
        THEN '       *'
    ELSE
        B/A * 100
    i.e.
    if A or B is equal to 0, then display the value of 0
    else if B is negative (as A is either 0 or positive), then display the following text: '         *'
    otherwise, display the value of  B/A * 100
    Thanks!

    Hi,
    You can achieve this by creating a new formula.
    You have to use the boolean operations and mathematical functions. But we cannot display *. u have to display some value for that.
    Khaja

  • Where to write IF THEN ELASE statements in BEX Query Designer

    Hi All,
    I need to write a formula in query designer...
    saying that to display the all Quantities in KGs.. Now articles are in Grams and KGs...
    So here i need to perform calculation like... if article is in KGs divide by 1, else if article is in Grams divide by 1000.
    where can i write this logic to perform calculation ...
    Thanks in advance..
    ravi.p

    hi chetan,
    No its not work.. why because i  need to convert the unit of measure in Masterdata Attribute values... that means ) ' 0grooss_wt'.  this is  attribute as a keyfigure of ' 0material' .. this ' 0gross_wt' values has to convert in KGs. at Present ' 0gross_wt' values are in KG and Grams...
    I can change these values in update rules by writting  Routine.. But I need to convert it in KGS at BEX Query Designer Level..
    I need calculate like this
    quantity sold * Gross Weight. 
    here Gross Weight is the formula variable which replacing the values of gross weight...
    i tried by creating conversion types in RSUOM t-code. but it works on keyfigures of infocube.. not on attribute values of master data...
    is there any solution to solve this Problem...

  • Looking for a best query for multiple IF Else statement in a single select

    Hi
    I want to run multiple IF Else statements in a single select SQL, each statement is one SQL operating on the same table, what is the best way to write this select SQL query ?
    If it is PL/SQL, when i get the result from the first IF statement I will skip the remaining execution, and so on... Can any one help me on this.
    Thanks in advance !!

    965818 wrote:
    I Apologize, the information i have given might not be enough.
    This is my scenario,
    I am selecting set of rows from the table for the employee id. After selecting those records,
    i need to go through the result list and check the condition 1, if it is met, i will return that employee record.
    If that condition 1 is not met, then i need to go through the condition 2. If that is met, i will return that record.
    Like wise, i have four conditions.
    I am trying to achieve this in a single sql. If i am not clear, please let me know.Not fully clear yet, but the picture is better already. The thing with SQL is that you should stop thinking procedurally. Instead think in data sets.
    For example if the task is:
    Find all managers that work in sales.
    Procedural thinking would work like this:
    pseudo code
    Loop over all employees that work in sales
       for each row
           check if it is a manager
               if manager
                  then return record
               else
                  do nothing
               end
    end loopThinking in datasets will result in a different logic
    pseudo code
    select all employees
    where department = SALES
    and job = MANAGERThis advantage here is that all the "Do nothing" loops are not needed. Those are already eliminated by the database.
    So what is needed to help you? Give the full picture. What is your task that you try to solve. From a business perspective.

  • How to use IF ELSE statement in one QUERY to MS ACCESS

    System.out.println("Enter Final Exam: ");
    int f = Integer.parseInt(input.readLine());
    command.executeUpdate("UPDATE Students SET Final_Exam='"+f+"',Raw_score=(QT+MT+Final_Exam)/3 WHERE stud_name='"+stdID+"'");
    command.executeUpdate("UPDATE Students SET Raw_score=(QT+MT+Final_Exam)/3 WHERE stud_ID='"+stdID+"'");
    if (rsf==100)
    command.executeUpdate("UPDATE Students SET Final_Grade=1.0 WHERE stud_ID='"+stdID+"'");
    else if(rsf < 100 && rsf > 90)
    command.executeUpdate("UPDATE Students SET Final_Grade=2.0 WHERE stud_ID='"+stdID+"'");
    else
    command.executeUpdate("UPDATE Students SET Final_Grade=5.0 WHERE stud_ID='"+stdID+"'");How can I shorten my code using a IF ELSE statement inside a single query or two? Or is it possible?
    Edited by: ivatanako on Sep 28, 2007 11:55 PM

    Sun has tutorial trail for JDBC, you might want to browse through that; you'll get more details and samples there than here. Here's the link to the section on PreparedStatement: http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • Bex Query- Use of ABAP code in Calculated Keyfigure/formula

    Dear Experts.
    I am wondering if there is any way to use ABAP in the formula editor of the Bex Query desinger.
    I have to build a report with very complex formulas (a lot of key figures, comporations, If then else ) an I think it would be easier to build all then in ABAP.
    So what I am looking for is any kind of user-exit/Badi that allows to calculate a Calculated Key figure/fomula in ABAP with the same data that is availabe in the fomula editor.
    If SAP is not providing this, this is clearlly a must for next releases.
    Thanks a lot and best regards,
    Alfonso.

    Dear Ananda.
    Thnaks for your reply, but could you please extend your answer a little bit more?
    As far as I know, Formula customer exit variables are only called once and they don´t provide the rest of the keyfigures and characteristic use in the drilldown level, so for my needs they are useless.
    Regarding IF-then-else statement in the formula, I already know about it. Actually what I am trying to avoid is to use them. In order to build my query I might need to build really big formulas with a lot of If-then-else, making it quite complex what the formula is doing. This is the reson I want to do it on ABAP.
    Please any other ideas?
    Thanks a lot.

  • IF and ABS condition statement in BEX query designer

    Hi,
    I would like to ask the best way for me to produce an acceptable result from Excel IF and ABS Condition statement.
    The condition statement that I have on my Excel file is
    =IF((A2-B2)>0,ABS(A2-B2),0)
    I'm trying multiple times to reproduce this in BEX Query designer, unfortunately I'm getting a bad result or unacceptable formula.
    Anyone who could help me with my issue?
    Thanks,
    Arnold

    Hi Arnold,
    Thank you,
    Nanda

  • Charactersitic values to be used in IFTHEN ELSE STATEMENT IN QUERY

    scenario: i need to use the characteristic values(not the attributes) to be used in an IF THEN ELSE STATEMENT in query. so i created a formula variable for the characteritic of processing type replacement path, replace with key.The values are not fetched in the result and is displayed as X.
    what should i replace with key,lable, constant or other options whereas  my requirement is the all the values present in the characteristc should be used.
    eg. if char name is xyz and has the values 1,2,3,4,5 till -
    20.
    then in a calculated key figure :(formulavariable =1)* kefig1keyfig2 +not(formulavariable =1)kef2keyfig3.
    this formula variable should have all the values of the characteristic values ie 1,2,3---20.
    2. how should i do get the values of characterstics values in the equation give me the steps in detail..
    3. i do not want to use the attributes, though i tried initally while creating the formual variable i replaced with attribute value, there is was an error and there were no reult.
    i tried to create char. variable  for the characteristic  of manual entr , not ready for input values and gave all the values 1,2,3 --20 as default values and then created formaul variable and repalce with the variable, however this characteristic variable is not at all displayed from the list of variables which will be displayed while creating the formula variable.
    help me out.
    Thanks

    hi srini,
    i have includedthe char in rows. i want you to explain in detail how to use these values in the if then else statement in query.
    i have created a calculated key figure 2= (formual variable =1 & keyfig a =0)* keyfig1kefig2 +not(formual variable =1 & keyfig a =0)keyfig2 *calculated keyfig1.
    so this formula variable of replacement path have ref. to then char. and with what value should it replace, key, name, external char or attribut etc so that i should get the values of the char from 1 to20.
    i donot to repalce with the attribute. i just want the char. values and not thier attributes (1. description 2. the second attribute has the values say abc1,efg2,ghi3 for respective charteristic values.
    ie
    char value               desc                 2nd attrib
    1                            hi                     abc1
    2                            bye                  defg2
    3                            ciao                  ghi3

  • IF-ELSE statement in BI  Query

    Hi guys i have a requirement where in i have condition as mention below...
    If  say X=0 then Y=0  and
        if    X>0  then y=1
      where X  is  key figure value...to be compared ..
    can any one suggest me the logic as to how i need to design this in the query..any option of using IF-ELSE statement...
    an in the result if  Y=0 then i should show as a * (star)..how can we do this in the query?
    can any one suggest me a solution for this please..
    Rgds
    Shilpa

    shipa,
    please check these links
    [Defining Exceptions|http://help.sap.com/SAPHELP_NW04S/helpdata/EN/43/21b4cd14cd06f4e10000000a422035/frameset.htm]
    [Defining and Changing Exceptions|http://help.sap.com/saphelp_nw04/helpdata/EN/c2/f6843b49f6a40de10000000a11402f/content.htm]

  • IF ELSE statement in BEX

    Hi all,
    I need to write a formula in a query using  IF ELSE statements. Here is my senario
    I need to write a IF ELSE statement to calculate a KF i.e., % variance of This year with last year sales (TY%LY) .Following are the conditions.
    IF LY<0 then TY % LY should be (TY-LY)/LY * (-100)
    IF LY>0 then TY% LY should be (TY-LY)/LY * (100)
    IF LY =0 then TY%LY should be 100
    IF LY=NULL (i.e., if store is closed last year we donu2019t pull record so LY will be empty) then TY%LY should be 100
    IF TY=0 or NULL then TY%LY should be -100
    So I tried writing as follow but getting errors
    (LY<0)(TY-LY)/LY(-100) + (NOT(LY<=0))((TY-LY)/LY)100  + (LY==0)100 + NODIM(LY)100 + (TY==0)(-100) + NODIM(TY)(-100)
    But it is giving errors. Can you please suggest me how to write that formula without effecting the current performance of the query.
    Thanks in Advance,
    Preethi

    Hi Preethi,
    I think that you can accomplish the desired results using the following formulas:
    KEY FIGURE = NOT(F1=0) * F5 + (F1=0) * -100
    F1 = NOERR(TY + 0)
    F2 = NOERR(LY + 0)
    F3 = NOERR( (F1-F2) / F2 ) * -100
    F4 = F3 * -1
    F5 = (F2<0) * F3 + (F2>0) * F4 + (F2=0) * 100
    I hope it helps you.
    Regards,
    Maximiliano

  • BEx Query Cell Definition (If ..then...else with AND)

    Hello Experts,
    I am struggling with a requirement which I need to define in the Cell definitions in Query designer. I have tried going through the numerous posts regarding this if..then...else in SCN but were of no help to me.
    My requirement is as follows:
    if expression1 then result1, else if (expression2 AND expression3) then result2, else (expression4 AND expression5) then result3
    I tried to define this in the cell as below:
    <expression1> * result1 + (<expression2> AND <expression3> ) * result2 + (<expression4> AND <expression5>) * result3
    but somehow it does not work.
    Any pointers of how to achieve this?
    Thanks.

    Hi,
    If you are getting 'X' then this may be related with the dimensions you use in comparing variables. Try the whole formula such as
    (nodim(var_1) > nodim(var_2) * nodim(kyf_1)
    "then try seperating the if else statements into different cells" : for example try adding a formula for
    each item in your formula (one for buchungsperiode, one for buchungsperiode ein gabe etc. I mean you can find the formula vaiable or key figure that causes 'X' in the results by seperating the formula into the items of the formula.
    Regards
    Yasemin...

  • Unable to debug/correct the CMOD code for a variable used in a query

    unable to debug/correct the CMOD code for a variable used in a query
    i am using the data in a DSO in a query and using a custom coding variable in that query , but this data not coming in that query ..
    can anyone suggest how to debug that cmod code for the variable?
    code is written in CMOD tocde for the variable.

    belowis the code that i have written for a custom coding for a variable
    *******Start***
    IF i_step = 2.
      CASE i_vnam.
        WHEN 'IC_COMPCD'.
         TYPES:       BEGIN OF gt_itab_DyAuthTable,
                           username  TYPE /bic/afiop_o1200-/BIC/IC_USER,
                           companycode TYPE /bic/afiop_o1200-COMP_CODE,
                      END OF gt_itab_DyAuthTable,
                      BEGIN OF gt_itab_Cocd_all,
                            companycode TYPE /BI0/MCOMP_CODE-COMP_CODE,
                      END OF gt_itab_Cocd_all.
          DATA: gi_itab_DyAuthTable TYPE STANDARD TABLE OF gt_itab_DyAuthTable,
                wa_itab_DyAuthTable TYPE gt_itab_DyAuthTable.
           DATA: gi_itab_Cocd_all TYPE STANDARD TABLE OF gt_itab_Cocd_all,
                wa_itab_Cocd_all TYPE gt_itab_Cocd_all.
          SELECT /BIC/IC_USER
                 COMP_CODE FROM /bic/afiop_o1200
            INTO CORRESPONDING FIELDS OF TABLE gi_itab_DyAuthTable
            WHERE /bic/ic_user = sy-uname.
          LOOP AT gi_itab_DyAuthTable INTO wa_itab_DyAuthTable.
            IF wa_itab_DyAuthTable-companycode EQ '*'
              OR
              wa_itab_DyAuthTable-companycode EQ ' '.
              SELECT COMP_CODE FROM /BI0/MCOMP_CODE
                  INTO CORRESPONDING FIELDS OF TABLE gi_itab_Cocd_all.
              LOOP AT gi_itab_Cocd_all INTO wa_itab_Cocd_all.
                l_s_range-low    = wa_itab_Cocd_all-companycode.
                l_s_range-sign   = 'I'.
                l_s_range-opt    = 'EQ'.
                APPEND l_s_range TO e_t_range.
              ENDLOOP.
          to exit the loop if any one value is */space/all for a user's compcode values
            EXIT.
            ENDIF.
          ENDLOOP.
           if control is here means, the comp codes values didnt have */space
              LOOP AT gi_itab_DyAuthTable INTO wa_itab_DyAuthTable.
                l_s_range-low    = wa_itab_DyAuthTable-companycode.
                l_s_range-sign   = 'I'.
                l_s_range-opt    = 'EQ'.
                APPEND l_s_range TO e_t_range.
              ENDLOOP.
      Endcase.
    Endif.

  • Need transaction code for opening Bex query designer?

    Hi ALL,
      Can anyone help me with the transaction code for opening Bex query designer?
      Like RRMX for Bex Analyzer similarly i want for Bex query designer.
    Thanks & Regards
    Sameer Khan

    THERE IS NO TCODE FOR QUERY DESIGNER. BUT THERE IS AN ALTERNATIVE..
    OPEN BEX ANALYSER THROUGH RRMX
    OPEN A QUERY
    CLICK ON TOOLS-> EDIT QUERY
    THIS OPENS QUERY DESIGNER AND YOU CAN USE IT NORMALLY..

Maybe you are looking for

  • Broken HTC Incredible and Verizon service update

    Here is what has went on. Sorry for the length. My first post: Great phone for the 22 hours it worked. I got my Incredible May 10th, it died May 11th. Then it stopped charging, the battery goes dead. Red charge light on, green battery icon on top of

  • Primary Key from Database Sequence

    Hi, I have a form that has a master block(single_record) and a child block(multi-record). I am using Database Sequence for primary key. And I am not using any toolbar, instead using the default from FORMS. I want to keep this primary key field invisi

  • Slow DNS resolution

    Folks; *I have Mac OS X Leopard 10.5.6 up to date and since few days, the DNS resolution is very slow, about 5 seconds to resolve names.* *For example :* # ping test.com *(wait 5 seconds)* PING test.com (205.178.152.103): 56 data bytes *Of course it

  • How to dynamically hide the Field Label in the overview page's form view?

    Hi Experts, How to dynamically hide, for certain condition, the Field Label in the overview page's form view? Please reply me. Regards, Vishal

  • The Apple Icon is much bigger during startup. So is the spinning wheel

    The Apple Icon is much bigger during startup. So is the spinning wheel is there any way to change this back to the normal size? thanks