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: 

one month back date from the current date

Former Member
0 Kudos

Hi,

My requirement is if i enter current date, then system should return a date which is one month back date.

Is there a function module which will calculate accordingly and subtract 30 and 31 days

PLZ HELP!

6 REPLIES 6

Former Member

hi use this...

parameters: date type sy-datum.

data: output type sy-datum.

output = sy-datum - 30 .

write:/ output .

regards,

venkat

Former Member
0 Kudos

use FM : CCM_GO_BACK_MONTHS

Former Member
0 Kudos

Hi,

If the date field is has a data type for date, the calculation is handled automatically by the runtime. For example.

data: datum type sy-datum.

datum = sy-datum.

datum = datum - 30.

You can simply subtract 30 days from it, it will work. If will rollback thru the last month and th last year with no problem.

Or

Try the FUnction module 'CCM_GO_BACK_MONTHS'

Regards

Kiran Sure

Former Member
0 Kudos

Hi,

There is FM in IS-OIL. Pasting the FM code and interface. you can create your own Z FM using following details

IMPORT PARAMETERS :

1. DATE LIKE SY-DATUM.

2. MONTHS

EXPORT PARAMETERS : DATE_E LIKE SY-DATUM (pass by value checked)

Exception : DATE_ERROR

SOURCE CODE :

FUNCTION OIL_DATE_SUBTRACT_MONTH.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(DATE) LIKE SY-DATUM

*" REFERENCE(MONTHS)

*" EXPORTING

*" VALUE(DATE_E) LIKE SY-DATUM

*" EXCEPTIONS

*" DATE_ERROR

*"----


  • 46C RL 11.03.2002 FM OIU_DATE_SUBTRACT_MONTH copied to current FM

  • copied from PRA to Oil Cross

data: year type i.

data: month type i.

data: month_sub type i.

data: year_sub type i.

year = date(4).

month = date+4(2).

year_sub = months div 12.

month_sub = months mod 12.

year = year - year_sub.

if month_sub >= month.

year = year - 1.

if month_sub = month.

month = 12.

else.

month = ( 12 - month_sub ) + month.

endif.

elseif month_sub > 0.

month = month - month_sub.

endif.

if year <= 0.

message e154(o0) raising date_error. "copied from 154(OIUCM)

endif.

date_e = date.

date_e(4) = year.

date_e+4(2) = month.

ENDFUNCTION.

Regards,

Mohaiyuddin

Former Member
0 Kudos

REPORT ychatest MESSAGE-ID zz.

data : date1 like sy-datum,

backmonths type numc3,

date2 like sy-datum.

date1 = sy-datum.

backmonths = '1'.

CALL FUNCTION 'CCM_GO_BACK_MONTHS'

EXPORTING

currdate = date1

backmonths = backmonths

IMPORTING

NEWDATE = date2.

write : / date2.

Former Member
0 Kudos

Hi,

data: v_curr type sy-datum,

v_next type sy-datum.

v_curr = sy-datum.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

DATE = v_curr

DAYS = '0'

MONTHS = '1'

SIGNUM = '-'

YEARS = '0'

IMPORTING

CALC_DATE = v_next.

write:/5 'Current date', v_curr.

write:/5 'Previous date', v_next.