cancel
Showing results for 
Search instead for 
Did you mean: 

code to get past months

Former Member
0 Kudos

Hi,

The foll. is the code from the sdn posting for calculating past 12 months from a given date.

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.

if i want to try out the code that is above to understand how it works, can i just copy paste in se38 and just change the olddate as parameter , so that i can enter a date, will it work or how should i test. can anyone help me here.

Thanks

Ravi

Message was edited by: ravi raj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ravi

This code will not get the past twelve months . This code will just return a date which is twelve months back.

I.e. say if you pass 01-OCT-2005 it will return 01-OCT-2004.

To get past 12 months you can check for answer in that same earlier post . There is no function you have to write abap. However you can cut / paste and see how this code works.

<b>parameter pdate like sy-datum.

data: olddate like sy-datum,

newdate like sy-datum.

clear: olddate, newdate.

olddate = pdate.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

months = '-12'

olddate = olddate

IMPORTING

NEWDATE = newdate.

write 😕 newdate.</b>

Cheers

Message was edited by: Sanjay Sinha

Former Member
0 Kudos

thanks sanjay. let me try it in se38 an update u.

Former Member
0 Kudos

sanjay,

i tried ur code in the original posting and it worked. just wanted to try this code but it returns only previous date with yr, not all 12 months. thanks.

Answers (0)