‎2008 May 12 12:05 PM
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.
‎2008 May 12 12:36 PM
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.
‎2008 May 12 12:13 PM
You can use FM 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'
Best Regards,
Vibha
Please mark all the helpful answers
‎2008 May 12 12:17 PM
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.
‎2008 May 12 12:22 PM
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.
‎2008 May 12 12:22 PM
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.
‎2008 May 12 12:32 PM
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.
‎2008 May 12 12:36 PM
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.
‎2008 May 12 12:48 PM
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.
‎2008 May 12 1:06 PM
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.