Formula variable to compute number of Months

Hi Guyz,
I have created a formula variable( Custom exit)  to compute the number of months, and the field used is 0CALMONTH, below is the code, but am not getting the required value.
The scenario is : 0CALMONTH: if the range entered is 022010 042010
ZAVERAGE value should 2, but the value is showing as 0 , Please help .
When 'ZAVERAGE'.
clear l_s_range.
*call function 'MONTHS_BETWEEN_TWO_DATES '
if i_step = 2 .
data: yrd(2)  ,
       mmd(2).
Read table i_t_var_range into loc_t_var_range with key vnam = '0I_CALZ1'.
yrd = loc_t_var_range-high3(4) - loc_t_var_range-low3(4).
yrd = yrd * 12.
mmd = loc_t_var_range-high(2) - loc_t_var_range-low(2).
mmd = mmd + yrd.
if i_vnam = 'ZAVERAGE'.
*if sy-subrc = 0 .
. l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
l_s_range-low = mmd.
. append l_s_range to e_t_range.
ENDLOOP.
Regards,
Ravi

Hi,
You need to have two variables created. One for entering the month ranges and other for storing the "number of months" value. Please refer to the link below for further details.
Derive Number of months from variable entry
I hope it helps.
Thanks.
Regards,
Samruddhi.

Similar Messages

  • BEx Analyzer: Formula Variable with Replacement path change Month with Day

    Hi experts I'm facing this issue in BEx Analyzer.
    I need to have some dates in format DD/MM/YYYY in Index Structure, in order to do this I've created a formula variable with replacement path referenced to 0CALDAY characteristic.
    The formula works but it behaves in a strange way:
    if the day is higher than 12 the displaied result is correct (DD/MM/YYYY)
    if the day is lower or equal 12 the displaied result is wrong (MM/DD/YYYY)
    I'm on BW 7.01 SP6 and BEx Analyzer 7.10 SP12, excel 2007.
    anybody has faced this issue before?
    any help will be appreciated
    Daniele Cortopassi

    Hi Daniele,
    This seems pretty strange. Pls. redo validation with the dump data, as being a flat struture BEx does not apply any logic changes. May be it might have been MM/DD/YYYY format as in workbooks. Else you may change the property of 0calday display as "Text". Business Explorer > Display > KeyMaster Data/Texts > Texts (Plese check this option). If you are using some text table you may maintain the same using BI0/TCALDAY (Similar to BI0/TCALMONTH2). Guess it should be an excel based issue; if not you may try the same in WAD/Report designer to verify the nature of the issue. If you don't face these inconsistencies in WAD/RD then you may change excel formatting options. Lastly, please let us know if the infoobject has some predefined settings in RSA1 > Infoobject > (BEx) Properites.
    Thanks,
    Arun Bala

  • Formula Variable issue

    Hi,
    Can someone help me with the following issue as my client wants it quick.
    I have created a formula variable called "Enter number for formula" for number and used this formula variable  in a calculated key figure. When I run the query, it will ask me to enter a number in the formula variable and this number will be used in the calculated key figure to get the results for the calculated key figure in the report.
    Now the point here is that customer has to enter either 5 or 6 or 7 only in this formula variable and should not allow other numbers in the formula variable and more over we should have a selection option with only these 3 values and when customer pressses F4, he should get an option of selecting any one from these 3 values.
    Is this requirement feasible? If So can any one help me with an example.
    Advance Thanks for your help.
    Kishore

    Hi Aby,
    I have a quick question. My first priority is that, is selection option can be enabled for formula variable i,e when ever customer executes a query and presses F4 he should get 5 or 6 or 7 and has to select any one out of three.
    I can give the formula variable description "Enter either 5 or 6 or 7" but this can be worked out only if I have less values but if I have to select some numbers from 1 to 100 then definitely I need a selection option,
    and is the reason we are looking for selection option with the required values.
    Can you please help me with this.
    Thanks,
    Kishore

  • Formula variable is a user entry ??

    Hi All,
    I have created formula variable as a number and how i can use this formula variable is a user entry variable
    Please help me this
    Regards,
    Ravi

    Thank you very much I have used this formula variable in condition so I was missing some Key figure values, now I am getting total Key figure values 
    I appreciate your help
    Regards,
    Ravi

  • User Exit Formula Variable - to calculate #days of any month

    Hello Team,
    I need a column in my report layout which shows the #days of any month entered by the user. User entry 01.2014 to 03.2014 report should have 31 28 & 31 according to the Calendar month in the rows.
    To achieve this I'm using a user exit formula variable in my local calculation. An Optional Interval User Entry variable on CALMONTH is also put in at the filter section.
    I created a CLASS with 2 methods CONSTRUCTOR( vNam = 'ZC2C_DSONWDAYS') & GET_VALUES. We may also use FM /OSP/GET_DAYS_IN_MONTH but i need the code because I failed terribly.
    GET_VALUES method code:
    if i_step = 2.
       DATA: wa like line of i_t_var_range[].
       DATA: L_V_INDICATOR TYPE SCAL-INDICATOR.
       data: begin of ccrange ,
               iobjnm(30) type c,
                 sign(1),
                  opt(2),
                  low(7) type c,
                 high(7) type c,
             end of ccrange.
      data: l_s_range type rrrangesid,
            no_of_wrkdays type i value 0,
            startdate     type d,
            enddate       type d,
            startmth(2)   type c,
            endmth(2)     type c,
            startyr(4)    type c,
            endyr(4)      type c,
            endday(2)     type c,
            leapyear      type i value 0,
            dayofmth      type syst-datum.
    DATA:  day           type SCAL-INDICATOR.
      loop at i_t_var_range into wa.
        if wa-iobjnm = '0CALMONTH'.
           ccrange-sign = wa-sign.
           ccrange-opt = wa-opt.
           ccrange-low = wa-low.
           ccrange-high = wa-high.
           exit.
        endif.
      endloop.
      startyr  = ccrange-low+0(4).
      startmth = ccrange-low+4(2).
      endyr    = ccrange-high+0(4).
      endmth   = ccrange-high+4(2).
      concatenate startyr startmth '01' into startdate.
    * determine last day of the end month
      if endmth = '02'.
         leapyear = endyr mod 4.
         if leapyear = 0.
            endday = '29'.
         else.
            endday = '28'.
         endif.
      elseif ( endmth = '04' or endmth = '06' or endmth = '09' or endmth = '11' ).
           endday = '30'.
      else.
           endday = '31'.
      endif.
      concatenate endyr endmth endday into enddate.
      dayofmth = startdate.
    IF startmth <= endmth.
       startmth = startmth+1.
    ENDIF.
    * do it for all days in space of time
       WHILE dayofmth <= enddate.     "to date
         CALL FUNCTION '/OSP/GET_DAYS_IN_MONTH'
         EXPORTING
           input = startmth
         IMPORTING
           output = no_of_wrkdays.
           CLEAR l_s_range.
           l_s_range-sign = 'I'.
           l_s_range-opt = 'EQ'.
           l_s_range-low = no_of_wrkdays.
       append l_s_range to e_t_range.
           startmth = startmth + 1.
           CONCATENATE startyr startmth '01' into dayofmth.
        ENDWHILE.
    endif.
    endmethod.

    Hi Vasavi,
    1)  Create a FV to calculate no.of days  like below, with calmonth in ref characteristics :
    2. If you see number of days is an attribute of calmonth. Please enter that as below :
    3. Create a formula with above variable and make sure calmonth is added in the row.
    Its giving output like this :
    I hope this will help you.
    Thanks,

  • Derive Number of months from variable entry

    I have a requirement to calculate the average sales qty using the number of months entered in the variable entry and not the actual number of months the product was sold. For example Variable cal month entered as the range 01/2009 - 03/2009. The average needs to be calculated with the 3 month range even if sales only occurred in months 01 and 02. I understand I need to create a formula variable type customer exit, but I need assistance in creating the formula that would count the number of months from the variable entry.
    Any help would be appreciated.
    Craig

    Hi,
    Yes you can replace the variable and use if the code has been declared in such a way. Use i_t_var_range instead of It_var_range. This is a table which should been defined in your existing code.
    I have modified the code. Hope this helps
    WHEN 'FORMULAVARIABLE'.
    IF I_step = 2.
    CLEAR l_s_var_range.
    LOOP AT l_t_var_range INTO l_s_var_range WHERE vnam = 'MONTH_VARIABLE'.
    CLEAR l_s_range.
    l_s_range-low = l_s_var_range-high4(2) - l_s_var_range-low4(2) + 1
    IF l_s_range-low < 0.
    l_s_range-low = l_s_range-low + 12
    endif.
    l_s_range-sign = 'I'.
    l_s_range-opt = 'EQ'.
    APPEND l_s_range TO e_t_range.
    CLEAR l_s_range.
    ENDLOOP.
    endif.
    Regards
    Akhan

  • User Exit Variable for Calculating number of days in a month

    I need a query to calulate the number of days in a particular month upto the current date. For example if i give 26 Feb it should reutrn 25, if i enter 30march it should return 29 for any specific year. I have gone through some posts and understood that i need to create a formula variable (under calculated KF's) and then go to CMOD, create a project, then enancement Assignment RSAP0001 then EXIT_SAPLRSAP_001 and include a code in INCLUDE ZXRSAU01. But i have any clue of coding. Could someone give me the entire code and how to connect it to the formula variable KF in created. The technical name of the key figure is ZMDAYS. If i have made any mistakes or if there is another eaier alternative please let me know. I thankyou all for the help.

    Hi Uday,
    I have a few modifications in the code
    Data: xdate type d,
          ip_year(4) type N,
          ip_month(2) type N.
    Types : Begin of ty_month_days,
           month(2) type N,
           days(2) type N,
           End of ty_month_days.
    Data : it_month_days type ty_month_days occurs 0 with header line.
    ip_year = 2006.
    ip_month = 01.
    do 12 times.
        CONCATENATE ip_year ip_month '01' INTO xdate.
        xdate = xdate + 33.       "this date is in the next month
        xdate+6(2) = '01'.        "first day of next month
        xdate = xdate - 1.        "last day of xmonth
        it_month_days-month = xdate+4(2).       "number of days of xmonth.
        it_month_days-days = xdate+6(2).
        append it_month_days.
        ip_month = ip_month + 1.
    enddo.
    This code stores Month and No. of days in the internal table it_month_days.
    You can access this internal table for your calculations
    This should help.
    Regards,
    Praveen.
    Message was edited by: praveen mathew

  • Finding no. of days in a month in formula variable

    Hi all
    I wanted to find out no. of days in a month in formula variable customer exit at bex. I did the following code, which returning X value. Can anybody helps here.
    WHEN 'ZFV_NO_DAYS_MONTH'.
         IF I_STEP = 2.
           CLEAR L_S_RANGE.
           READ TABLE I_T_VAR_RANGE INTO XTAB WITH KEY VNAM = 'zdate1'.
           V_DATE = XTAB-LOW.
           P_DATE = V_DATE+6(2).
           CALL FUNCTION 'HR_E_NUM_OF_DAYS_OF_MONTH'
             EXPORTING
               P_FECHA        = V_DATE
             IMPORTING
               NUMBER_OF_DAYS = V_DATE1.
           V_RES = V_DATE1 - P_DATE.
           L_S_RANGE-LOW = V_RES.
           APPEND L_S_RANGE TO E_T_RANGE.
         ENDIF.
    Regrds
    swetha

    Hi Swetha
    in your code itself just change something as mentioned below
    VDATE1 type as integer.
    WHEN 'ZFV_NO_DAYS_MONTH'.
         IF I_STEP = 2.
           CLEAR L_S_RANGE.
           READ TABLE I_T_VAR_RANGE INTO XTAB WITH KEY VNAM = 'zdate1'.
           V_DATE = XTAB-LOW.
        *Hide No need***   P_DATE = V_DATE+6(2).
           CALL FUNCTION 'HR_E_NUM_OF_DAYS_OF_MONTH'
             EXPORTING
               P_FECHA        = V_DATE
             IMPORTING
               NUMBER_OF_DAYS = V_DATE1.
       *hide**    V_RES = V_DATE1 - P_DATE.
       *hide**     L_S_RANGE-LOW = V_RES.
    *Add the below new line
    L_S_RANGE-LOW = V_DATE1.
           APPEND L_S_RANGE TO E_T_RANGE.
         ENDIF.
    Regards
    Sureshkumar C

  • Trying to install Lightroom CC on second computer ( I have monthly paid account for CC)- when launching get asked for serial number - what do I do next?

    Trying to install Lightroom CC on second computer ( I have monthly paid account for CC)- when launching get asked for serial number - what do I do next?

    Ask for serial number http://helpx.adobe.com/creative-cloud/kb/ccm-prompt-serial-number.html

  • Formula variable / Replacement path issue

    Hi Experts,
    I have a Field which has different status description.
    I want to bring the count of only one preferred description.
    Model Status
    A1     New
    A2     Open
    A3     New
    B1     Closed
    B2      Pending
    B3     New
    I want to view only the closed count of models
    Model Count of Closed
    A1     0
    A2     0
    A3     0
    B1     1
    B2      0
    B3     0
    I tried doing this using the formula variable and Replacement path with Status Field.
    But I'm unsuccessful in selection the desired status.
    Please help me to over come this.
    Thanks

    Hi Dear Prasad,
    I can't restrict the characterstic to Closed. If I do so the output will be only for Closed.
    But here I want to bring every model with value as 0 and 1 for model with closed status.
    Hi Dear Raju,
    The requirement what I have here is more complex. like, the result will be for 6 month displaying every single cal/day.
    and also I have to find out percentage of closed for every cal/day based on number of model we got.
    i have only asked a small portion of it, with this input i will manage to build the percentage etc....
    I  cannot bring counter inside. My report is already too wide to be displayed.
    I have tried similar kind of thing, using CKF, Formula Variable and Replacement path with the Char - InfoObj.
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/009819ab-c96e-2910-bbb2-c85f7bdec04a&overridelayout=true
    But I'm not very sure how do I get only count of the my desired status.
    Please help.
    Thanks

  • Formula variable using Replacement path not working

    Dear All,
    I am using a query to calculate YTD values in the report. I am using a formula variable to calculate the number of months. Formula is
    Month To - Month From+1
    When I am giving the range from 001 to 006 for period in th evariable screen,
    I am gettung Month To as 6 and Month From as 6 with total no . of months as 1.
    I think Month From is not being caculated properly. I created another formul variable using Replacement path, for characteristic Posting period, replace with a Key and dimension ID as number with out any offset.
    Still not working.
    Any suggestions.
    Thanks and Regards,
    Srini
    Edited by: Srinivas on Apr 24, 2008 11:13 AM

    Hello,
    I have seen this document already. It is slightly different from what I am trying to do here than what the post shows. How ever,  I did everything right, atleast seems to be and don´t know why I am not getting the From value from the posting period selected. To value variable is coming right.
    Any more sugegstions.?
    Thanks and Regards,
    Srini

  • Question on Variant configure - Calculate Number of Month Range

    Hi,
    I'm a new learner for BI module. I have a question on calculate the number of month. Hope I can get answer from you. Thanks.
    According to below description, I get wrong display of number of month in Analyer.
    =============================
    Description:
    To list the number of months in the interval in the report, define a new calculated key figure on query level named Number of Month using a new formula variable:
    a) From the context menu for the Key Figure structure, choose New Formula.
    Then choose Edit from the context menu of the new formula. Enter the description Number of Month.
    b) In the Available Operands field, from the context menu for Formula Variables, choose New Variable. Then choose Edit from the context menu of the new variable.
    c) On the General tab page, enter:
    Description: GR## Number of Months
    Variable name: BW513Q##
    Processing by: Replacement Path
    Ref. Characteristic: Cal. year/month
    d) On the Replacement Path tab page, select:
    Replace Variable With: InfoObject
    Variable Represents: Key
    Use Interval: Difference
    e) On the Currency/Unit tab page, the Dimension is set as Number.
    f) Choose OK.
    After configure when I input 2001/06 - 2001/07, in the Analyzer it shows 200107.0000000 rather than 2. May I know where is wrong?
    ============================
    Number of Months
    200,107.0000000
    200,107.0000000
    200,107.0000000
    200,107.0000000
    ============================
    Regards,
    Leon

    Hi Mayank,
    Thanks for your help. This is the way to get the number but weird thing is in below sdn link we can found one example that shows the number can be got from an interval of January to March. ?
    Link:
    http://help.sap.com/saphelp_nw04/helpdata/en/03/6ba03cc24efd1de10000000a114084/frameset.htm
    For Intervals Use
    ·        From-value
    ·        To-value
    ·        Difference
    If the replacement value called is an interval, you use this setting to specify whether the lower interval limit (from value) or the upper interval limit (to value) is used as the replacement value.
    For formula variable, you can also choose the interval difference as the replacement value. Using this setting, you can easily calculate the difference of period boundaries. The interval difference is the from value minus the to value plus 1. For example, the period January to March gives a result of 3 (the to value 3, minus the from value 1, plus 1)
    Hope anyone could give me an answer.
    Thanks,
    Leon

  • Formula Variables in Report Painter- Syntac error in formula

    Dear Experts,
    I'm creating the report where I need to calculate annualized P&L. The formula is as follows : (P&L account/Period(variable ))*12
    I need to capture the From_period, which is entered by the user on the selection screen when running the report and use it as a variable in the formula above. Example: If User insert From Period 3, then the formula should be *P&L accoun / 3 * 12*
    I have tried so many different way but nothing seems to work. one of the ways i tried was:
    In the general selection Im using set variable 6P-S-PERIOVB.CCSS for period which consists of variable V_PERIO and B_PERIO.
    So Im trying to create a folowing formula:
    IF 1 >= u2018PER_FRu2019 AND 1 <= u2018PER_TOu2019 THEN 1 ELSE 16
    IF 2 >= u2018PER_FRu2019 AND 2 <= u2018PER_TOu2019 THEN 1 ELSE 16
    Unfortunately I keep getting Syntac error in formula. Please help me I'm really desperate to solve this issue after 5 days of unlucky research.
    Thank you in advance
    Regards
    Ernesta

    so, I would use parameters.....
    P_fr_MO(2) TYPE N DEFAULT '01',
    p_fr_yr(4) type n default '2011'.
    Then, to set my range, i would do something like....
    data: lv_to_mon(2) type n,
             lv_to_yr(4) type n.
    if p_fr_mo eq '01'.
      lv_to_yr = p_fr_yr.  "12th month, same year...
    else.
    lv_to_yr = p_fr_yr + 1.  "any other month puts us into next year.
    endif.
    case p_fr_mo.
      when '01'.
       lv_to_mon = 12.  "always for 12 month period...
    when others.
       lv_to_mon = p_fo_no - 1.  '''example 10/2010 to 09/2011.
    endcase.
    then concatenate the from and to variables into what format is needed to read the data...
    on the other hand, if the user gives us from and to, we have a different problem....one then has to calculate what part of a year they have and create a factor for multiplying any data values....
    for instance if user says Jan (01) to (03) March, then I know that to month - from month + 1 is the number of months I have....
    then 12 / that number is the factor to multiply the results by....
    example...
    data : factor(5) type p decimals 2
              months(3) type n.
    if p_to < p_from.  "adjust if I cross a year boundary....Oct to Jan becomes 13 - 10 + 1 or 4 months.
    p_to = p_to + 12.
    endif.
    months = p_to - p_from + 1.
    factor  = 12 / months.  " factor   12 /4 months = 3 times the values obtained  = 1 year.
    something like this....hope this is helpful to you.
    Edited by: DaveL on Oct 18, 2011 6:24 PM

  • Formula variable using date char - unable to use conditions

    Hello Experts,
    I am sure I am making a silly mistake here - but after spending lot of time I am unable to rectify this - please help if you can:
    I basically want the report to show only latest employee actions for a selected period (usually month).
    1. I am using formula variable that is based on 0CALDAY and defined as number.
    2. A calculated keyfigure uses this formula variable. Both calculated keyfigure and CALDAY char are included in the report / navigation.
    3. There is a condition defined using calculated keyfigure. No matter what logic I use, I just cannot use calculated keyfigure to filter records on the report. My original idea was to use Top N - 1 with char combination as 'Employee' to get me the latest employee records for each employee.
    Can anyone help spot where I am going wrong?
    Thanks.

    I haven't looked at that, but as a first guess idea- why not use the picker to get a date, then save it as a number of seconds from a given date?
    See:
    dateWithTimeIntervalSince1970:
    Creates and returns an NSDate object set to the given number of seconds from the first instant of 1 January 1970, GMT.
    + (id)dateWithTimeIntervalSince1970:(NSTimeInterval)seconds
    Or you could store it as a string, but I think the number would be easier.

  • BW - problem with formula variable (date format)

    Hi,
    (sorry if I'm using different term than yours.. this is my 2nd query.. still new with BW)
    I need to create 1 query: Support Message Aging Report.
    Basically it will have 5 columns: Not Due, 0 Day, 1 Day, 2-10 Days, >10 Days.
    and 1 input selection is: key date.
    the formula is: number of aging day = key date - due date.
    I have no issue on the 1st and 2nd column. For that I just create 1 customer exit.
    My problem is on how to separate the over due support message by day (due date < key date).
    I tried create 2 formula variable for key date and due date. Then from these 2 vars, I can get the number of days.
    Problem comes when the calculation is cross month/year. I suspect maybe because the return from the formula var is in number format and not date... yyyymmdd. Then, I change the dimensions from number to date.. it is working for key date.. dd.mm.yyyy.
    but for the due date, I got problem... it keeps give me warning saying: value 'D' invalid for property dimension of element etc.///
    below are details for both formula variable.. please advice which area should I fix or maybe you can suggest any good idea for my query.. thanks so much
    1. ZKEYDATE - customer exit (value  input data) - dimensions date - NO ISSUE (OUTPUT: dd.mm.yyyy)
    2. ZDUEDATE - replacement path (ref char ZBW02C08) - replacement rule: infoobject, key - dimension date - GOT WARNING...
    ZBW02C08: contains due date and the type is date: yyyymmdd

    If I were you, I'd try two things:
    best way - have the infoprovider changed to have a new key figure for the number of days difference
    - to do this with formulae (especially crossing months and years - what about leap years) is hard to maintain and develop
    other way - make a virtual key figure - i did this once but I forget how exactly. There's a userexit or BADI somewhere which can be used for this.
    Either of these ways allows the calculation to be done in ABAP itself where date1 - date2 gives you the number of days difference.
    By the way though, this is in the wrong forum. I'd bet if this was in a BI forum, you'd have an answer already.

Maybe you are looking for

  • Remote front panel licence?

    I'm building an application that will run on a industrial computer without a monitor or keyboard. The engineers at the site need to be able to view my front panel on there office computers to monitor the line. The ideal way to do this would be to jus

  • HP printer assistant not working or showing up on Desktop or menue

    Hi. My HP printer assistant not available on desktop. I uninstalled and reinstalled software, but assistant does not show in  HP 8600 or in all programs menue. Im using vista 32bit. Reinstalling does not solve the problem. I uninstalled via control p

  • What about session memory when using BEA Weblogic connection pooling?

    Hi, consider a web application, allowing database connections via a BEA Weblogic 8.1 application server. The app-server is pooling the oracle connections. The oracle database is running in dedicated server mode. How are the database requests from the

  • Error in ar_receipt_api_pub.create_and_apply

    Hi All, Trying to create and apply a receipt using api ar_receipt_api_pub.create_and_apply and running into following error. Error at line 1 ORA-06502: PL/SQL: numeric or value error ORA-06512: at "APPS.AR_MO_GLOBAL_CACHE", line 55 ORA-06512: at "APP

  • Is it possible to install OS X Tiger onto the latest iMac 24" 2.8GHz?

    I just bought an iMac 24" 2.8GHz, the latest model released this year. It came with 10.5.2. I am wondering if I can install 10.4.x on this machine because I have to use Xcode 2.x for some reason. 10.5 requires XCode 3.x. Thank you for your comments i