Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

GET THE PAST 12 MONTHS

Former Member
0 Kudos

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!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

6 REPLIES 6

Former Member
0 Kudos

Hi Jason,

Please refer to this post:

and

Sudha

Message was edited by: Sudha Mohan

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

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.