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: 

Previous month last date

Former Member
0 Kudos

Hi folks...

Is there any straight FM to get the last date of the previous month. For eg if current date is 04/30/2006 then i should get 03/31/2006. <b>NOT</b> 03/30/2006.

The same can be achieved by using 2 FM's. But I am looking for a single FM to suffice this requirement.

Early response is appreciated.

Regards,

Bhanu

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

How about no function module at all?




data: last_month_last_day type sy-datum.

last_month_last_day = sy-datum.
last_month_last_day+6(2) = '01'.
last_month_last_day = last_month_last_day - 1.

write:/ last_month_last_day.

Yes, it works, all the time. Even in January.

Regards,

Rich Heilman

4 REPLIES 4

ferry_lianto
Active Contributor
0 Kudos

Hi,

You can use FM RP_LAST_DAY_OF_MONTHS.

DATA: WA_DATE  LIKE SY-DATUM,
      WA_LDATE LIKE SY-DATUM.
                                                                        
WA_DATE = SY-DATUM - 30.
                                                                        
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
  EXPORTING
    DAY_IN                  = WA_DATE
  IMPORTING
    LAST_DAY_OF_MONTH       = WA_LDATE
  EXCEPTIONS
    DAY_IN_NO_DATE          = 1
    OTHERS                  = 2.
                                                                        
WRITE: / WA_LDATE.

Regards,

Ferry Lianto

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

How about no function module at all?




data: last_month_last_day type sy-datum.

last_month_last_day = sy-datum.
last_month_last_day+6(2) = '01'.
last_month_last_day = last_month_last_day - 1.

write:/ last_month_last_day.

Yes, it works, all the time. Even in January.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi bhanu ,

try this fm ..

parameters : date1 like sy-datum.

CALL FUNCTION 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'

EXPORTING

I_DATE_OLD = date1

IMPORTING

E_DATE_NEW = date1 .

write:/ date1.

just check if this fm is present in ur verison.

hope this helps .

regards,

Vijay.

yeah got it

use this fm ...

RS_VARI_V_L_LAST_MONTH

pass this as default in ur fm

S OP LOW HIGH

I EQ 0 0

the output is last day of previous month .

regards,

Vijay.

Message was edited by: Vijay

Former Member
0 Kudos

Hi Bhanu ,

just execute this.

data :date like sy-datum.

data :begin of it occurs 0.

include structure RSINTRANGE.

data: end of it.

CALL FUNCTION 'RS_VARI_V_L_LAST_MONTH'

IMPORTING

P_DATE = date

TABLES

p_intrange = it.

write 😕 date.

regards,

Vijay