2005 Sep 30 9:03 AM
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!
2005 Sep 30 10: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
2005 Sep 30 9:11 AM
2005 Sep 30 9: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
2005 Sep 30 10: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
2005 Sep 30 10: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.
2005 Oct 01 4:14 AM
Thanks for all those who responded quickly... They are all really helpful....
2005 Oct 01 7:17 AM
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.
2025 Jan 07 11:35 AM
parameter: lv_date type sy-datum.
data : lv_date1 like sy-datum,
lv_date2 like sy-datum.
CALL FUNCTION 'MONTH_PLUS_DETERMINE'
EXPORTING
months = '-12'
olddate = lv_date
IMPORTING
NEWDATE = lv_date1.
.
CALL FUNCTION 'MONTH_PLUS_DETERMINE'
EXPORTING
months = '+11'
olddate = lv_date1
IMPORTING
NEWDATE = lv_date2.
write: lv_date1,lv_date2.