Application Development and Automation 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: 
Read only

Function Module (sap-abap)

Former Member
0 Likes
810

Hi,

Could anyone pls tell me a function module which gives date of previous month of input date ?

Thx and Regds,

Bapi bobby

6 REPLIES 6
Read only

Former Member
0 Likes
771

Please try with FM: <b>RE_ADD_MONTH_TO_DATE</b>

Below code might help you understand in using the same:

parameters: p_date type datum.
CALL FUNCTION 'RE_ADD_MONTH_TO_DATE'
  EXPORTING
    MONTHS        = '-1'
    OLDDATE       = p_date
 IMPORTING
   NEWDATE       = p_date.
write:/ p_date.

Regards

Eswar

Read only

0 Likes
771
data: date like sy-datum,
      date1 like sy-datum.
 
date = sy-datum.   " here pass ur i/p 
 
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
  EXPORTING
    date            = date
    days            = 00       
    months          = 01
   SIGNUM           = '-'      "add(+) or substract(-) 
    years           = 00
 IMPORTING
   CALC_DATE       = date1. " new date
 
 
write:/ 'new date',  date1

.
Read only

Former Member
0 Likes
771

Hi,

Use this FM

CALCULATE_DATE.

and pass month parameter as

CALL FUNCTION 'CALCULATE_DATE'

EXPORTING

  • DAYS = '0'

MONTHS = '-1'

  • START_DATE = SY-DATUM

IMPORTING

RESULT_DATE = lv_date.

write lv_date

Rgds,

Prakash

Read only

Former Member
0 Likes
771

Hi Bobby,

Following FM will definitely solve your purpose.

<b>RP_CALC_DATE_IN_INTERVAL</b>

Just provide <b>date </b>(any date), <b>Signum</b>(<b>-</b>) and <b>month</b>(<b>1</b>). and execute.

It will give you date of previous month of input date

Code:

<b>CALL FUNCTION </b>'<b>RP_CALC_DATE_IN_INTERVAL</b>'

<b>EXPORTING</b>

date = date

days = 00

months = 01

SIGNUM = '-'

years = 00

<b>IMPORTING</b>

CALC_DATE = prev_date.

Hope this helps,

Pragya

null

Read only

Former Member
0 Likes
771

Thanks a lot,

One last question, how can I get a date wich is the last day of the month of a

given date??

Read only

0 Likes
771

FM : RP_LAST_DAY_OF_MONTHS