FM to get only Previous Month

Hi All,
        I need to calculate the average billing doc from this fiscal year .
But My user is also calucaltaing the number of billing doc created in last previous month as well as also the average billing doc per month from the document type.
So is there any function module which can calculate the previous month from the sy-datum.
Moderator message: date calculation questions = FAQ, please search before posting.
locked by: Thomas Zloch on Sep 29, 2010 1:20 PM

Hi,
Use the FM: RP_CALC_DATE_IN_INTERVAL
DATA:date1 TYPE sy-datum.
START-OF-SELECTION.
  CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
    EXPORTING
      date      = sy-datum
      days      = '00'
      months    = '04'
      signum    = '-'
      years     = '00'
    IMPORTING
      calc_date = date1.
  WRITE date1.

Similar Messages

  • Sample ABAP routine code to load only previous month data in INFOPACKAGE

    Hi all,
    I want to create one ABAP routine in InfoPackage (Variables change to selection values with background processing) for 0CALMONTH ( Calender year month) so that whenever this infopackage is executed it should fetch only previous month data.
    Can anyone please provide any sample code for that.
    Thanks in advance.
    Uday shankar.

    Hi
    Please check with below code, hope this will resolve your issue
    WHEN: 'ZLASTP'.
         CLEAR: h_period, h_gjahr.
         CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
           EXPORTING
             i_date               = sy-datum
       I_MONMIT             = 00
             i_periv              = 'AF'
          IMPORTING
            e_buper              = h_period
            e_gjahr              = h_gjahr
    EXCEPTIONS
       INPUT_FALSE          = 1
       T009_NOTFOUND        = 2
       T009B_NOTFOUND       = 3
       OTHERS               = 4
         IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
         ENDIF.
         IF h_period = '001'.
           h_gjahr = h_gjahr - 1.
           h_period = '012'.
         ELSE.
           h_period = h_period - 1.
         ENDIF.
         CLEAR l_s_range.
         CONCATENATE h_gjahr h_period INTO l_s_range-low.
         l_s_range-sign = 'I'.
         l_s_range-opt  = 'EQ'.
         APPEND l_s_range TO e_t_range.

  • MDX dimension formula in BPC to get the previous month failed with parents

    Hi,
    I'm working on a proof of concept and I need to create a formula with the following requirement:
    Requirement               
    Account2 = Account2 (Previous Month) + Account 1               
    Accounts -Jan-Feb-Mar-Q1
    Account1_____15___25___45____85
    Account2_____15___40___85___140     <== OK
    Now, I was thinking of applying this formula within Dimension, using MDX. Then I tried with these two examples, but they didn't work when rolling up to parents. I mean, the calculation for every month works fine, but, the Total Quarter or the Total Year are wrong:
    Attempt 1:
    Account2.Formula = (ParallelPeriod([Time].[Month], 1, [Time].CurrentMember), Account2) + Account1
    Accounts -Jan-Feb-Mar-Q1
    Account1_____15___25___45____85
    Account2_____15___40___85____85     <== WRONG
    Attempt 2:
    Account2.Formula = (Account2,[Time].PrevMember) + Account1
    Accounts -Jan-Feb-Mar-Q1
    Account1_____15___25___45____85
    Account2_____15___40___85____85     <== WRONG
    How can I solve this ? Should I use Script logic instead of MDX to perform this calculation ?
    Thanks!
    Diego.

    DON'T use MDX script logic.  It does not perform well under high data volumes or concurrency.
    You're calculation can be done easy enough in SQL logic provided you scope the code correctly.  Based on what you have given as requirements, the basic code would be something like:
    *XDIM_ADDMEMBERSET TIME = PRIOR
    *XDIM_ADDMEMBERSET ACCOUNT=A2
    *WHEN ACCOUNT
    *IS "A1"
        *REC(EXPRESSION=%VALUE%+GET(ACCOUNT="A2",TIME=PRIOR),ACCOUNT=A2)
    *ENDWHEN
    *COMMIT
    The first two lines make sure you have the prior period values for A2 in the scope of exection.  Then when a record for A1 comes through, it would take that value and add it to A2's prior value for the exact same intersection of all other dimensions.  You would separately have to deal with moving forward values of A2 if there were cases where you could have a value for A2 in a prior period but not have a value in A1 for the current period.
    Edited by: James Sharrett on Apr 14, 2008 9:51 AM

  • How to get the previous month and year accordingly

    Hi friends,
    I wanted to select month as number like 4 and year as 2011
    but I want to select the previous month as of sysdate
    like if the sysdate is 10-jun-2011
    it should give me 5 as month and
    in the year it should give as 2011
    if the sysdate is 01-jan-2012
    the month should be as 12 and year should be as 2011
    thanks

    Hi,
    776317 wrote:
    thanks a lot I just dont need the 0 being prefixed... can you pls tell how to avoid that as well pls
    TO_CHAR ( ADD_MONTHS (SYSDATE, -1)
            , 'FMmm yyyy'
           )For details about how the FM modifier works, wee the SQL Language manual:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/sql_elements004.htm#sthref456

  • HT4098 i paid 14.99 usd for one month but i get only one month how can i acces again

    hai
    ipaid for yalo 14.99usd thats for one month unlimited freecall but now only 10 days my account is suspended
    why my account has suspended?

    We are fellow users here on these user-to-user forums, you're not talking to iTunes Support nor Apple, we won't know.
    Do you mean that you iTunes account is disabled ? If you do then you might be able to re-enable it via this page : http://appleid.apple.com, then 'reset your password'.  You might then need to log out and back into your account on your phone.
    Or that your account with that app is 'suspended' ? If you do then have you contacted the app's developer ?

  • Upload of chellan details, getting only two months

    Hi SAP Gurus
    We have been traing to upload the chellana details.  all most employees are getting chellan details in form 16 except two three employees. here we find that which ever TDS is reflecting in F24 for those months details we are getting.  pls suggest me its an urgent issue. this is going to escalete. pls suggest.
    Regards
    Suresh

    done

  • Getting previous month

    could you please tell me how to get previous month?
    using sysdate gives me current date. from that i can get current month using to_char function. But how can I get the previous month?

    All you ned to remember is that there are two date units, days and months. Everything else is a multiple/fraction of these.
    To increment
    n days:    SYSDATE + n
    n hours:   SYSDATE + n/24
    n minutes: SYSDATE + n/24/60
    n seconds: SYSDATE + n/24/60/60
    n weeks:   SYSDATE + n*7
    n months:  ADD_MONTHS(SYSDATE,n)
    n years:   ADD_MONTHS(SYSDATE,12*n)

  • Calculating receipts from previous month based on the sales of current mont

    Hi Gurus,
    I have a requirement where i need to display sales for a quarter and need to display receipts from the previous quarter. For example consider that i am displaying sales from week1-Aug to Week4-October, I need to display receipts ( R_Net_RCPTS) from Week1-july to Week4-September. In that way If i select Wk1-Aug for sales it should display Wk1-july receipts. i need to do this in Webi by creating appropriate variables.
    I have got prompts on year and Fiscal Week
    I have given year as 2011 and The "08: Fiscal Week From:" as "Wk1-Aug" to "08: Fiscal Week To:" as "Wk4-Oct"
    I HAVE GONE THROUGH ALMOST ALL RELATED THREADS, BUT COULDN'T FIND ANY SOLUTION. ITS REALLY URGENT. PLEASE HELP ME AND I WILL FOR SURE GIFT POINTS.

    HI
    Your explanation is not clear whether u want to display current quarter data or you would like to see only previous month data ?
    Which dimension you are taking for week ? how data would be like ?
    Edited by: K.sunil on Nov 21, 2011 9:14 AM

  • ABAP routin for geeting previous month

    Hello.......
    I want to writ an ABAP routin at the infopackage level.
    I want to get the previous month ( period ).
    example : if sy-datum is 2007.01.01
    output : 2006.12.01.
    reply.
    Thanks in advance.

    Hi,
    Write this in the start routine of infosource or update rules...
    Try this:
      DATA: L_DATE LIKE SY-DATUM.
      DATA: L_YEAR TYPE I.
      DATA: L_MONTH TYPE I.
      L_DATE = (Here enter your input).
      MOVE '01' TO L_DATE+6(2).
      MOVE L_DATE(4) TO L_YEAR.
      MOVE L_DATE+4(2) TO L_MONTH.
      L_MONTH = L_MONTH - 1.
      IF L_MONTH LT 1.
        L_YEAR = L_YEAR - 1.
        L_MONTH = 12.
      ENDIF.
      MOVE L_YEAR TO L_DATE(4).
      MOVE L_MONTH TO L_DATE+4(2).
      MOVE:  L_DATE TO P_DATE.
    Hope this helps
    PB

  • Previous Month Data

    Hi Friends,
          Good day,
    I want to get the previous month balance.
    Here is the my business scenario. I am going to enter the month and year then i can get the values corresponding to this month and year, but in this i want previous month data for one object or one measure.In that query i set the two filter
    Enter Month Name:
    Enter the Year:
    Say for ex, if i enter August means i need all august month data plus i need previous month balance for balance object.if i suppose enter January and year is 2008 means. I need December month data for year 2007 for the balance object and for remaining i need January month Year 2008 data.
    Any Suggestions,
    Thanks lot,
    Regards,
    -B-

    Hi Balaji,
    You are a lucky guy, that's why getting these much reply. Congratulations friends for your good replys. I also find a solution with access database and  if and mod operation.
    temp.Yr ; =  @prompt('Enter Year:','A','Time period\Year',Mono,Free,Persistent,,User:0)
        AND
    temp.Mth ; = @prompt('Enter Month:','N','Time period\Month',Mono,Free,Persistent,,User:0)
       OR
    temp.Yr ; = @prompt('Enter Year:','A','Time period\Year',Mono,Free,Persistent,,User:0) - (IIF(@prompt('Enter Month:','N','Time period\Month',Mono,Free,Persistent,,User:0)=1,1,0))
    AND
    temp.Mth ; =( (@prompt('Enter Month:','N','Time period\Month',Mono,Free,Persistent,,User:1)+10)mod 12)+1
    The filter contain...
    ............year equal to @year
    ........and
    ............month equal to @month
    or
    ............year equal to @year
    ........and
    ............month equal to @month
    Regards
    Eldose

  • How to Get Previous Month Salary for a particular employee?

    Hi
    I am developing a report to get the Net Pay Difference from Previous month.
    I am using logical database pnp.
    My question is how can we get the last month (Previous from current selected month) salary of perticular employee. I read the thread which is related to this but I can't understand the reply's. I think it is due to that I am new in ABAP and my experience in only 22 days. If someone reply with code example then it will more helpful for me.
    Also If you can tell me the table name from where we can get the salary of particular month of particular employee then it will also helpful for me.
    Regards
    Iftikhar

    Hi,
    Payroll data is stored in cluster tables.
    You can either use macro for retrieving the data or Function module.
    1. Use FM -CU_READ_RGDIR for getting the RG directory values.Pass  
      employee Number and molga.You will get all the sequence Numbers from this
      FM.
        The last record will be the latest  one.
    2.  Then Use FM - PYXX_READ_PAYROLL_RESULT for getting the payroll  
         results table.Pass cluster ID- 'IN'  ,pernr ,sequence number for which period
          you want (In your case ,current period minus   1) and
          READ_ONLY_INTERNATIONAL            = 'X',
    3. You will get all the results from PAYROLL_RESULT                     = it_result
      Then you can loop this internal table like LOOP at it_result-inter-rt into wa..
    Get the net pay value(/560 wage type)
    Reward points if helpful.
    Regards,
    Manoj.

  • Display current and previous months records only

    Hello gang,
    My selection criteria looks like this:
    not ({HRDEPBEN.PLAN_CODE} startswith ["C", "EAP", "HMIL", "V", "W"]) and
    (month({hrdepben.Creation_date}) = month(currentdate)) and
    {HRDEPBEN.PLAN_TYPE} = "HL"
    I modified it to this in order to pull in previous month's data too:
    {HRDEPBEN.PLAN_TYPE} = "HL" and
    not ({HRDEPBEN.PLAN_CODE} startswith ["C", "EAP", "HMIL", "V", "W"]) and
    (month({hrdepben.Creation_date}) = month(currentdate) or month ({hrdepben.Creation_Date})= month (currentdate)-1)
    However, it's still pulls the same record count and only January records, not Decembers'.
    Where am I going wrong?
    Thanks

    Looks like you're reporting against Lawson?  What database are you using?
    There are a few issues with the record selection criteria as it's written:
    1)  Month(CurrentMonth) - 1 = 0 when the current month is January.  That's why your not getting any records from December.
    2)  The  monthly criteria won't be passed to the database for processing, which is a huge performance issue when you're reporting against a system like Lawson.  You're basically telling the report to bring back all records that don't start with an array of values, irrespective of the date.  Only after all the possible records are returned across the network will the extraneous records be filtered out on the client side.  That's bad.
    3)  It's easy to use StartsWith or Like, but it's also pretty inefficient, since it forces a full table scan of the underlying table
    Personally, I'd do one of two things in order to both fix the query and optimize it:
    1)  Write the underlying query in SQL as either a View or SQL Command object
    or
    2)  Keep the current report, but make use of SQL Expression fields in order to optimize the query.
    Here are some examples of SQL Expression fields against Oracle (PL/SQL) that could be useful:
    /*{%PLANCODES}*/
    /*This SQL Expression evaluates whether or not a Plan Code starts with the specified values*/
    /*"HRDEPBEN"."PLAN_CODE" is selected directly from the Field Tree in the SQL Expression Editor*/
    CASE
      WHEN SUBSTR("HRDEPBEN"."PLAN_CODE",1) IN ('C','V','W') THEN 'Y'
      WHEN SUBSTR("HRDEPBEN"."PLAN_CODE",3) = 'EAP' THEN 'Y'
      WHEN SUBSTR("HRDEPBEN"."PLAN_CODE",4) = 'HMIL' THEN 'Y'
      ELSE 'N'
    END
    /*{&CREATEDATEMONTH}*/
    /*This SQL Expression returns the month of the Creation Date field*/
    /*"HRDEPBEN"."CREATION_DATE" is selected directly from the Field Tree in the SQL Expression Editor*/
    TO_NUMBER(TO_CHAR("HRDEPBEN"."CREATION_DATE",'mm'))
    You could also create formula to return the Month value for last month and then use it in your record selection:
    //{@LASTMONTH}
    //This formula returns the Month value for Last Month
    //IIF statements can be passed to the database for processing
    IIF(Month(CurrentDate) = 1, 12, Month(CurrentDate) - 1)
    With expressions and formulas like these in place (this code is Oracle and DB2 compatible, it would be different for T-SQL), you could then modify your record selection criteria to be something simpler, like this:
    {HRDEPBEN.PLAN_TYPE} = "HL" and
    {%PLANCODES} = 'N' and
    {%CREATEDATEMONTH} IN {@LASTMONTH} TO MONTH(CURRENTDATE)// MONTH(CURRENTDATE) is passed to the DB
    By laying the groundwork, you'll have a much more efficient report and, in the case of the @LastMonth, more accurate! Hope this helps!
    p.s. a disclaimer on using SQL Expressions in this manner - it's not officially supported, although it's worked since Version 7 (when SQL Expressions were introduced) and there will be support for them in various 2011 versions. As such, they'll work for years. I use them all the time and they're fantastic for optimizing reports.

  • How to get the first 3 characters from the previous month?

    Hi,
    I need to get in a View Column only the first 3 characters of the previous month of data from the bellow query.
    SELECT ID, Department, Capital_Project_Number, 
    Capital_Site_Number, 
    Funding_Source, Milestone, 
    Account, Year, Month, Data
    FROM  Table
    Where Month = DATENAME(Month, DATEADD(Month, - 1, GETDATE())) and (Year = YEAR(GETDATE()));
    Go

     Left(DATENAME(Month, DATEADD(Month, - 1, GETDATE())),3)
    --Or
     convert( varchar(3), DATEADD(Month, - 1, GETDATE()),100)

  • Use a filter to get previous months results

    Hello,
    I want to put a filter on a new report that will only pull information from the last month. I know I can use a timestamp calculation to get 30 days back...but this will pull info 30 days back from when the report is run.
    I want one that will pull Octobers info if run anytime in November, for example.
    The filter will be on the "created date" field.
    Thanks!

    Hi,
    I am facing a similar issue.
    In the report, I have 3 columns to display data for -> Current Month, Current Month - 1 & Current Month - 2.
    The formula that I am using is something like this:
    CASE WHEN (Condition A AND Condition B) THEN (Expression X) ELSE (Expression Y) END
    Here the Condition B is:
    MONTH(Activity."Planned Start Time") = (MONTH(CURRENT_DATE)) for the Current Month
    MONTH(Activity."Planned Start Time") = (MONTH(CURRENT_DATE)-1) for the Previous Month &
    MONTH(Activity."Planned Start Time") = (MONTH(CURRENT_DATE)-2) for Previous to Previous Month
    This works ok for months from March to Dec, however for Jan and Feb, the data for Nov & Dec is not visible.
    How can I remedy this? Is there any variable to represent LAST_MONTH?
    (I tried to used embedded CASE statement to check the condition that if (for Current Month - 1), Month = 1, then Start Time = 12 & Year = Year(current_date) -1 , but that did not work.)
    Ady

  • Getting data in a query on last date of all previous months

    Dear Experts,
    I need your help with a query.
    I am trying to create a query which when run should pick the number of Open Sales Order on the last date of all the previous months from the start of company.
    I could create the query for fetching the required data on last day of the previous month, say today is 25th June 2014, so my query only fetches data for May 31st 2014 but I need data for all previous month, May 31st 2014, April 30th 2014, March 31st 2014 & so on.
    Please advise how to achieve this is SQL query.
    Thanks & regards,
    Nitin

    Hi,
    Try this:
    Select *
    from(
    SELECT T0.[DocNum] as #,t0.cardcode as C, t0.docdate
    FROM ORDR T0
    WHERE T0.[DocStatus] = 'o' and T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-1,0)),10) OR T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-2,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-3,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-4,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-5,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-6,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-7,0)),10)
    group by t0.cardcode,docdate,T0.[DocNum]) S
    pivot
    (count(#) for c in([cvt01],[cvt02],[cvt03],[cvt04],[cvt05],[cvt06],[cvt07],[cvt08],[cvt12])) P
    Note: Replace Cvt01,02...with your customer code.
    Thanks & Regards,
    Nagarajan

Maybe you are looking for