Skip to Content
author's profile photo
Former Member

GET THE PAST 12 MONTHS

Hello, Im Jason.. I just want to ask if there is existing function module that given a year and month, it will get the past 12 months starting from the given year/period going back to the 12th month of the given year and stores it in a table or a range?.. Thanks a lot!

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • Best Answer
    author's profile photo
    Former Member
    Sep 30, 2005 at 09:19 AM

    There is no fuction that exactly suits your need. Why not try this simple ABAP-

    data : begin of itab occurs 0,

    SPMON type SPMON,

    END OF ITAB.

    parameters pspmon type spmon.

    initialization .

    pspmon = sy-datum(6).

    start-of-selection.

    itab-spmon = pspmon.

    do 12 times.

    If itab-spmon+4(2) = '00'.

    itab-spmon+4(2) = '12'.

    itab-spmon(4) = itab-spmon(4) - 1.

    endif.

    append itab .

    itab-spmon = itab-spmon - 1.

    enddo.

    loop at itab .

    write :/ itab-spmon.

    endloop.

    Cheers

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Sep 30, 2005 at 08:11 AM

    Hi Jason,

    Please refer to this post:

    date-function

    and

    daysbetweentwodays

    Sudha

    Message was edited by: Sudha Mohan

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Sep 30, 2005 at 08:34 AM

    Hi,

    Use the finction module<b>"MONTH_PLUS_DETERMINE"</b>.

    In the MONTHS Parameter give the value -12.

    The Parameter NEWDATE contains the result.

    This should help you.

    Please reward points if this explanation is useful.

    Regards,

    Siva

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Sep 30, 2005 at 09:24 AM

    Hi,

    Try this -

    data:

    olddate like sy-datum,

    newdate like sy-datum.

    clear: olddate, newdate.

    now pass given year/period to olddate, then use below function module.

    CALL FUNCTION 'MONTH_PLUS_DETERMINE'

    EXPORTING

    months = '-12'

    olddate = olddate

    IMPORTING

    NEWDATE = newdate.

    newdate will carry the 12 months past date.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 01, 2005 at 03:14 AM

    Thanks for all those who responded quickly... They are all really helpful....

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      rajeev,

      if i want to try out the code that u gave can i just copy paste in se38 and just change the old data as parameter , so that i can enter date, will it work or how should i test. can anyone help me here.