Variable Exit - Last Three months date range based on Sy-datum

Hi
I have a requirement to filter last 3months data based on sy-datum. I have a variable filter on Posting Date.
For e.g. Today is 20110622
I have to determine below range: When users run the report prompt should be auto filled with below date range.
From Value: 20110301
To Value     : 20110531
From sy-datum I can find the first day of the current month - In this scenario 20110601 (I'll replace last 2 characters with "01").
If I subtract "-1" I'll get the To Value: 20110531
Question is to get the "From Value". If I subtract 90days from To value, it will work for few months.
For e.g. If my To value is Feb 28th and if I subtract 90days, I may get a different answer.
Is there any better approach to determine this date range?
Thanks for your help.
Best Regards,
Sree

Hi Sree,
  Pleae find this approach and compare
data : l_date type sy-datum,
l_startdate type sy-datum,
l_endate type sy-datum,
l_startmonth(6) type c,
l_endmonth(6) type c,
l_date = sy-datum.   say "20110622
l_endmonth = sydatum(6)   "201106
Pass year month and get previous month using this standard .
          CALL METHOD cl_rs_time_service=>shift_year_month
            EXPORTING
              i_year_month = l_endmonth
              i_shift      =  -1
            RECEIVING
              r_year_month = l_endmonth
            EXCEPTIONS
              failed       = 1
              OTHERS       = 2.
"l_endmonth = 201105.
          CALL METHOD cl_rs_time_service=>shift_year_month
            EXPORTING
              i_year_month = l_endmonth
              i_shift      =  -2
            RECEIVING
              r_year_month = l_startmonth
            EXCEPTIONS
              failed       = 1
              OTHERS       = 2.
"l_startmonth = 201103
l_startdate(6) = l_startmonth.
l_startdate+6(2) = '01'.
"l_startdate = 20110301
We got startdate in and we want to get enddate , but we got endmonth ...
now we need to get last date of the endmonth.
Use this function module SLS_MISC_GET_LAST_DAY_OF_MONTH  and u can get it. Input should be date.
so put l_enddate+6(2) = '01'.
l_enddate(6) = l_endmonth.
now pass end date to the  Function module and this will return the end date of the month.
So you get l_startdate and l_enddate as you require. This will work for leap years or feb 28 days what ever...
Regards
vamsi
Edited by: vamsi talluri on Jun 22, 2011 10:06 PM

Similar Messages

  • Last three month data

    Hi,
    Requirement:
    Want to show last three months data dynamicaly based month value seleted in prompt. ex: When Septemper is selected report should show, Sep, Aug, Jul
    tried using ago function but i want to use three measure columns. So is there way using single measure column and achieving.
    Thanks,
    Satheesh

    Satheesh Kumar  wrote:
    Hi,
    Requirement:
    Want to show last three months data dynamicaly based month value seleted in prompt. ex: When Septemper is selected report should show, Sep, Aug, Jul
    tried using ago function but i want to use three measure columns. So is there way using single measure column and achieving.
    Thanks,
    SatheeshSatheesh, I have a question for you. It is the same as the comment left on the article in the link that @user gave you. Like that link -- which doesn't work for all scenarios, how are you accounting for say the month of January? Without a "year" included, you cannot always "subtract 3" to get "3 months ago." Does "month" always correspond to the current year?
    Finally, what are the values of the column the filter is to be applied? All these are important to know if you want help on this. Try again. Thanks.

  • Showing last n months data based on prompt

    Hi,
    I have a "reporting month" prompt like Mar'13 .The report should return last 12 months data for all the measures based on "Reporting Month" prompt and my result will look like below:
    Measures  Mar' 13 Feb 13 Jan 13 ....
    CORP        1345     1444     1555
    ERP           675       877       5678
    I have used a pivot view to get the table view like this but i am not sure how to use the logic for showing all Months .Kindly suggest.

    Hi,
    You can achive this at answers level with the help of presentation variable using "Last N months(Rolling months) data By year-month prompt in OBIEE".
    pl follow the below post.
    http://shivabizint.wordpress.com/2008/09/19/rolling-months-data-for-year-month-prompt-in-obiee/
    thanks

  • Creation of a Query to show the values for the current month and the last 12 months data.

    Dear All,
    Good day!
    I have to create a Query with the below requirement.
    I have to create a Query to show the values for the current month and the last 12 months data.
    Can you please guide me how to achieve this ??
    thank you,
    Regards,
    Hema

    Hema
    explain the exact problem..? as you mentioned you want to create query to show values for current month and last 12 months.. so I think you want to show values for 12 months from current data.. you can achive this by multiple way..
    you can have selection screen and field with date .. and restrict based on system current date and 12 months before or you can handle this at your target.. .. I mean there are multiple ways to restrict data by date range..
    for some more hints..
    http://www.forumtopics.com/busobj/viewtopic.php?t=34393&sid=7fba465d0463bf7ff5ec46c128754ed6
    http://businessintelligence.ittoolbox.com/groups/technical-functional/cognos8-l/how-to-display-last-12-months-in-report-based-on-todays-date-3231850
    http://scn.sap.com/thread/3217381
    search on SDN you will get many other ways..
    Thanks,
    Bhupesh

  • How to get last 24 months data (if user not enter any kind of information)

    Hi all,
    I am want a report such that
    1. if user does not enter months he has to get last 24 months data(from current month)
    eg1.
    Sales
    currentmonth     300
    currentmonth-1  400
    currentmonth-20 500
    2. if user  enter months he has to get required months data(from current month)
    eg1.assume that user entered the interval of last two months.
    Sales
    currentmonth     300
    currentmonth-1  400.
    friends please me in desinging this query.
    It's very urgent,waiting for responses.
    Thanks,
    James.

    Hi james,
    1. if user does not enter months he has to get last 24 months data(from current month)
    ANS: U have to create variable Of  Currentmonth with The following
             Process Type: SAP Exit
             Variable Represent: Single value
            Variable Entry: Optional
    Check chekboxes for <b>Ready for Input</b> & Can be change in Query navigation.
    b) After this u have to give offsets by restricting this variable
    2. if user enter months he has to get required months data(from current month)
    ANS:
    For this U have to use Process Type: User-exit( User Entry)
    & After that specify the offsets by restriction.
    Thanks,
    kiran.
    Message was edited by:
            kiran manyam

  • How to convert Date,month,date range row to column

    hi experts
    i have a requirement like
    i want to change date, month and if user key in date range (01-04-2010 to 31-04-2010) then o/p like below
    1st-o/p-format
    d1 d2 d31
    01-04-2010 02-04-2010 ------------------------------- 31-04-2010
    2nd-o/p-format -based on transaction month
    d1 d2 d31
    jan feb ------------------------------------------ mar
    3rd-o/p-format date range based on transaction date
    d1 d2 d31
    01-04-2008 02-04-2010 -------------------------------31-04-2009
    Note :Basically i want to display these formate in Oracle Forms then based these dates i want to fetch record like below:
    d1 d2 d31
    jan feb dec
    count sales amt avgsales count sales amt avgsales ------------------ count sales amt avgsales
    so can anyone tell me what approach i shouls apply..
    Thanks
    abhishek

    This forum is titled "Certification" - pl post in the PL/SQL or Database General forums for a better/faster response.
    HTH
    Srini

  • Hi loading last 2 months data using abap routine

    we are planning to write a routine in infopackage level,
    using the option 6-ABAP routine, to select the last 2 month data ,
    we have the time characteristics 0CALMONTH, At present we managing the load by manually changing the selection for last 2 month every time ,
    It would be a great help if anybody can show a sample code to select last 2 month data,
    Thanks,

    Hi,
    data: l_idx like sy-tabix.
    DATA: lv_calmonth LIKE /BI0/SCALMONTH-CALMONTH.
    DATA: lv_day TYPE DATS.
    "previous month
    lv_day = SY-DATUM.
    lv_day+6(2) = '01'.
    lv_day = lv_day - 1.
    lv_calmonth = lv_day(6).
    READ TABLE l_t_range with key fieldname = 'CALMONTH'.
    l_idx = sy-tabix.
    MOVE lv_calmonth TO l_t_range-low.
    MODIFY l_t_range INDEX l_idx.
    "previous month - 1
    lv_day+6(2) = '01'.
    lv_day = lv_day - 1.
    lv_calmonth = lv_day(6).
    MOVE lv_calmonth TO l_t_range-low.
    APPEND l_t_range.
    p_subrc = 0.
    let me know if this works.... not sure about the last append.
    Olivier.

  • How do I retrieve the last three months of diary info stored on my iPad, it has mysteriously dissappearedplease?

    How do I retrieve the last three months diary stuff as my iPad appears to have wiped the info off please help.

    Check Settings > Mail, Contacts, Calendars > [scroll way down to] Sync Events ...
    Set the time period as you wish.

  • [MDX] Define date range based on user selection

    Hi All,
    I'm trying to define date range (of 3 months) using mdx based on user selection.
    This is what I'm trying to do:
    - If user select 2013, I would like range to be: from
    1 Oct 2013 to 31 Dec 2013
    - If user select Aug 2013, I would like range to be: from
    1 Jun 2013 to 31 Aug 2013
    - If user select 15 Sep 2013, I would like range to be : from
    15 Jul 2013 to 15 Sep 2013
    It is not a problem to get the upper bound of the range like this:
    ClosingPeriod(
    [Date].[Calendar].[Date],
    [Date].[Calendar].CurrentMember
    But I'm not able to get the lower bound of the range:
    OpeningPeriod(
    [Date].[Calendar].[Date],
    ParallelPeriod(
    [Date].[Calendar].[Month Number],
    2,
    ClosingPeriod(
    [Date].[Calendar].[Date],
    [Date].[Calendar].CurrentMember
    Error:If user selection is
    15 Aug 2013, I get
    14 Jun 2013
    If user selection is Apr 2013, I get
    (null)
    And even more strange, if user selection is
    2013, I get 28 Oct 2013
    Any idea of how to solve this ?
    Thanks,
    Guillaume

    Hello Guillaume,
    Can you please check if the following works for you? By the way, the performance will suffer due to all these IIF, the solution is very complex in order to avoid null in ParallelPeriod.
    with member measures.high as MemberToStr(ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    member measures.low as
    MemberToStr(
    iif(ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    ) IS ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    ).Parent.LastChild  --last date of the month
    OpeningPeriod(
       [Date].[Calendar].[Date],
    Ancestor(ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    ), [Date].[Calendar].[Month]).lag(2)
    iif([Date].[Calendar].CurrentMember.level is
    [Date].[Calendar].[Date]
    and
    Right(CSTR([Date].[Calendar].CurrentMember.Properties("KEY0")),4)="0429" --take care of 4/29
    OpeningPeriod(
       [Date].[Calendar].[Date],
    Ancestor(ClosingPeriod(
       [Date].[Calendar].[Date],
       [Date].[Calendar].CurrentMember
    ), [Date].[Calendar].[Month]).lag(2)
    OpeningPeriod(
       [Date].[Calendar].[Date],
       ParallelPeriod(
          [Date].[Calendar].[Month],
          2,
          ClosingPeriod(
             [Date].[Calendar].[Date],
             [Date].[Calendar].CurrentMember
    select  {measures.low,measures.high } on 0
    from [Adventure Works]
    where
    --[Date].[Calendar].[Date].&[20070815]
    --get [Date].[Calendar].[Date].&[20070615]
    --[Date].[Calendar].[Date].&[20070530]
    --get[Date].[Calendar].[Date].&[20070330]
    --[Date].[Calendar].[Date].&[20070429]
    --get [Date].[Calendar].[Date].&[20070201]
    --[Date].[Calendar].[Calendar Year].&[2007]
    --get [Date].[Calendar].[Date].&[20071001]
    --[Date].[Calendar].[Month].&[2007]&[4]
    --get [Date].[Calendar].[Date].&[20070201]
    --[Date].[Calendar].[Month].&[2007]&[5]
    --get [Date].[Calendar].[Date].&[20070301]
    --[Date].[Calendar].[Date].&[20070228]
    --get [Date].[Calendar].[Date].&[20061201]
    --[Date].[Calendar].[Date].&[20070831]
    --get [Date].[Calendar].[Date].&[20070601]
    If this does not work for you, I would suggest opening a ticket with Microsoft Support, with an advisory type of request.
    Hope this helps.
    Thanks.
    Meer Al - MSFT

  • How to display three months data in ALV grid control

    Hi
    Thanks for all.I have tried now it is working but as per requirement month name and cumulative total will display like this format.cumulative total means month1amount+ month2amount+month3amount.And one more thing month range will change some times means sometimes i will give January date to march date and sometimes i will give July date to October date. but date range is same means between dates range is three months.
    please tell me how to display.
    GAS PRESSURE WELDING COST EFFECTIVENESS                                        Dec-11                         Cummulativetotal
    Sr. No             Item             Unit           Rate          Qty           Amount             
    GAS PRESSURE WELDING COST EFFECTIVENESS                                      Jan-12
    Sr. No             Item             Unit           Rate          Qty           Amount             
    GAS PRESSURE WELDING COST EFFECTIVENESS                                     Feb-12
    Sr. No             Item             Unit           Rate          Qty           Amount             
    Thanks & Regards,
    Vasu.
    Moderator message: only one thread per issue, please.
    Edited by: Thomas Zloch on Feb 20, 2012

    Hi
    Thanks for all.I have tried now it is working but as per requirement month name and cumulative total will display like this format.cumulative total means month1amount+ month2amount+month3amount.And one more thing month range will change some times means sometimes i will give January date to march date and sometimes i will give July date to October date. but date range is same means between dates range is three months.
    please tell me how to display.
    GAS PRESSURE WELDING COST EFFECTIVENESS                                        Dec-11                         Cummulativetotal
    Sr. No             Item             Unit           Rate          Qty           Amount             
    GAS PRESSURE WELDING COST EFFECTIVENESS                                      Jan-12
    Sr. No             Item             Unit           Rate          Qty           Amount             
    GAS PRESSURE WELDING COST EFFECTIVENESS                                     Feb-12
    Sr. No             Item             Unit           Rate          Qty           Amount             
    Thanks & Regards,
    Vasu.
    Moderator message: only one thread per issue, please.
    Edited by: Thomas Zloch on Feb 20, 2012

  • Formula variable to add three char. date value together?

    We've been struggling to use formula variable (Replacement Path), but never been sucessful!
    We have three row date type of char which are c1, c2, and c3.  Now users would like to see a summation of the three date char.  We believe we will have to use Replacement Path formula variable for each of the char., but somehow the formula variable always show "X" in column.
    Any idea?
    Thanks!

    Hello Kevin,
    you can not summ characteristics but only key figures.
    if you want to see the summ of a key figure for certain characteristic values you need a restricted key figure (with aggregation type sum) and a selection for your characteristic for the 3 values.
    regards
    Cornelia

  • I have purchased an IMac in the last three months. Three days ago it started and will not let me open photo images on CDs. Says I do not have permission to view files.

    I have purchased an IMac three months ago. A few days ago when I tried to view photo images on CD an error message said I do not have permission to view the files. Have not been able to view any photo images or text files on CDs since: Again says do not have permission to view.

    Mount one of the CD/Right Click:Get Info/Sharing & Permissions. If the the CD is a CD-R, they should look something like this:

  • Date Range based on print date

    What would be the formula for a date range that references the most recent 7am-7am period from the print date?

    What would be the formula for a date range that references the most recent 7am-7am period from the print date?
    Assuming the print date is todays date, then this should work
      in DateTime  currentdate -1 +time (07, 00, 00)  to DateTime currentdate +time (07, 00, 00)

  • Display last 12 months data in column chart

    Hi All,
    I have one  dashbord  requirement in list box i have (example:):  "oct-11" i need to display previous 12 mnth data in column chart anybody help in excel formula how to display last 12 mnths based on list box selection.
    example:  if i select oct-11 from list box i need to display in chart like
    nov-10 dec-10 nov-10...................................oct-11
    please provide how to write in logic in excel

    Hi Shankar,
    Try this formula in excel : DATE(YEAR(A1),MONTH(A1)-1,DAY(A1))
    A1 will be your cell which is the destination of your List box. & then drag it till 12 months.
    If you are not having day from your list box then manually enter 1 in any cell and map that cell in place of A1 for day.
    HTH.
    Neeraj..

  • Oracle SQl query to find date range based on another cloumn value

    Hi Folks,
    I want to extract records for the employees who have consecutive vacation/leave from a table. If an emp has vacation of 3 days (MON-WED), the table contains 3 distinct records for him,
    e.g. My table contains records as shown below.
    EmpName Paycode ApplyDate Amt. of Hrs
    emp1 vacation 5/1/2010 8
    emp1 vacation 5/2/2010 8
    emp1 vacation 5/3/2010 8
    I am trying to get the output like this...
    Emp Name Paycode Leave Start Date Leave End Date TotalHrs
    emp1 vacation 5/1/2010 5/3/2010 24
    Note: If the smae emp has sets of vacation in another month, that should come as a separate record with start date and end date(last date of vacation for that set).
    I have a query which does not return any rows. Any help to repair this query or any better one would be of great help.
    ==================================================================
    WITH vpt AS (
    select personnum as empname, paycodename as paycode, applydate, timeinseconds/3600 as numhours from VP_TOTALS
    where applydate between to_date('05/01/2010','MM/DD/YYYY') AND to_date('12/31/2010','MM/DD/YYYY')
    AND paycodename in ('US-Vacation','US-Bereavement','US-Sick','US-Jury Duty')
    select
    empname,
    paycode,
    min(applydate) as startdate,
    max(applydate) as enddate,
    sum(numhours) as totalhours
    from (
    select
    empname,
    paycode,
    applydate,
    numhours,
    -- number the blocks sequentially
    sum(is_block_start) over (partition by empname, paycode order by applydate) as block_num
    from (
    select
    empname,
    paycode,
    applydate,
    numhours,
    -- Mark the start of each block
    case
    when applydate = prev_applydate + 1 then 0 else 1 end as is_block_start
    from (
    select
    empname,
    paycode,
    applydate,
    numhours,
    lag (applydate) over (partition by empname, paycode order by applydate) prev_applydate
    from vpt
    group by empname, paycode, block_num
    ===================================================================
    Thanks,
    Maha

    Hi Dear,
    Can I do reverse I mean I can get output as your question from your output as below:
    I have this table
    FID      STARTD ATE END DATE
    1 01-MAY-10 03-MAY-10
    1 09-MAY-10 11-MAY-10
    1 03-JUN-10 04-JUN-10
    2 03-JUN-10 04-JUN-10
    2 04-AUG-10 04-AUG-10
    2 06-AUG-10 06-AUG-10
    I want like this.
    FID FDATE
    1 01-MAY-10
    1 02-MAY-10
    1 03-MAY-10
    1 09-MAY-10
    1 10-MAY-10
    1 11-MAY-10
    1 03-JUN-10
    1 04-JUN-10
    2 03-JUN-10
    2 04-JUN-10
    2 04-AUG-10
    2 06-AUG-10
    And:
    How can i get date wise entry from Joining date to relieving date like..
    FID      START DATE END DATE
    1 01-MAY-10 03-MAY-12
    1 09-MAY-10 11-MAY-11
    2 04-AUG-10 04-AUG-11
    I want like this.
    FID FDATE
    1 01-MAY-10
    1 03-MAY-10
    1 04-MAY-10
    1 05-MAY-10
    1 16-MAY-10
    1 17-MAY-10
    1 08-May-10
    1 09-May-10
    1 03-May-12
    Can you please help me.
    Thanks,
    Edited by: 978452 on Dec 24, 2012 12:02 AM

Maybe you are looking for