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

Former Member
0 Likes
686

Hi All,

I want to know how to calculate the last date of the previous month if user enters any date.

Suppose i enter 10.04.2008 then i want last date of previous month i.e. 31.03.2008.

Please suggest me its urgent.

Regards,

Deepak.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
654

Hi,

Please refer the code below:



PARAMETER : sp_budat LIKE bsis-budat.

data : newdate like sy-datum,
      lastday like sy-datum.

CALL FUNCTION 'CCM_GO_BACK_MONTHS'
  EXPORTING
    currdate         = sp_budat
    backmonths       = '1'
 IMPORTING
   NEWDATE          = NEWDATE
          .

CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
  EXPORTING
    day_in                  = newdate
 IMPORTING
   LAST_DAY_OF_MONTH       = LASTDAY
* EXCEPTIONS
*   DAY_IN_NO_DATE          = 1
*   OTHERS                  = 2
          .
IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

write : lastday. 

Thanks,

Sriram Ponna.

8 REPLIES 8
Read only

Former Member
0 Likes
654

You can use FM 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'

Best Regards,

Vibha

Please mark all the helpful answers

Read only

Former Member
0 Likes
654

hi

u can do this for time being ,

take month from date entered like

10.04.2008 == &var+3(2)& it will take 04

then write IFELSE for all months

IF &var+3(2)& EQ '04'.

var2 = '31.03.2008'.

ELSEIF &var+3(2)& EQ '05'.

var2 = '30.04.2008'.

ENDIF.

REWARD IF HELPFUL.

Read only

Former Member
0 Likes
654

Hi,

try this code.


DATA:dat TYPE sy-datum.
CALL FUNCTION 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'
  EXPORTING
    I_DATE_OLD       = sy-datum"ur date
 IMPORTING
   E_DATE_NEW       = dat.

WRITE:/ dat.

rgds,

bharat.

Read only

Former Member
0 Likes
654

Hi,

This is pretty simple. Check this out.

code

first_day_of_curr_month = sy-datum.

first_day_of_curr_month+6(2) = '01'.

last_day_of_prev_month = first_day_of_curr_month - 1.

FunctionModules

RP_LAST_DAY_OF_MONTHS

SG_PS_GET_LAST_DAY_OF_MONTH

Regards,

Raj.

Read only

Former Member
0 Likes
654

When all else fails.. use a bigger hammer.


PARAMETERS: currdate LIKE sy-datum DEFAULT sy-datum MODIF ID new.
DATA: end_prv_mnth TYPE d.

end_prv_mnth = currdate.
WHILE end_prv_mnth+4(2) = currdate+4(2).
  end_prv_mnth = end_prv_mnth - 1.
ENDWHILE.

WRITE end_prv_mnth mm/dd/yyyy.

Read only

Former Member
0 Likes
655

Hi,

Please refer the code below:



PARAMETER : sp_budat LIKE bsis-budat.

data : newdate like sy-datum,
      lastday like sy-datum.

CALL FUNCTION 'CCM_GO_BACK_MONTHS'
  EXPORTING
    currdate         = sp_budat
    backmonths       = '1'
 IMPORTING
   NEWDATE          = NEWDATE
          .

CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
  EXPORTING
    day_in                  = newdate
 IMPORTING
   LAST_DAY_OF_MONTH       = LASTDAY
* EXCEPTIONS
*   DAY_IN_NO_DATE          = 1
*   OTHERS                  = 2
          .
IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

write : lastday. 

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
654

Hi,

Use the below code.

parameters: p_date type sy-datum obligatory.

data: i_periods like SLIM_S_DATE_RANGE occurs 0 with header line.

data: v_date like sy-datum.

CALL FUNCTION 'SLIM_GET_MONTHLY_PERIODS'

EXPORTING

SLIM_MEAS_DATE = p_date

TABLES

periods = i_periods.

v_date = i_periods-high.

write:/ 'Last date of previous month is = ', v_date.

Read only

Former Member
0 Likes
654

Deepak,

You can use FM's "CCM_GO_BACK_MONTHS" and "RP_LAST_DAY_OF_MONTHS". This will work perfectly.

Plz. reward points.

REgards,

Skumar.