Tuesday, 4 October 2016

Custom function module to get the dates of last Friday/any day of given number of months and date

Purpose:

Purpose of this document is to develop a custom function module to get the dates of last Friday/any day of given number of months and date.

FM code:

Please maintain mentioned input parameters to the custom FM.

Custom function module to get the dates of last Friday/any day of given number of months and date

And also maintain the below mentioned Export parameter.

Custom function module to get the dates of last Friday/any day of given number of months and date

Please find the below source code to get the dates of last day/Friday of given number of months.

DATA : lv_last_date TYPE sy-datum,
lv_tmp_date TYPE sy-datum,
lv_week_day TYPE week_day.

*loop IV_MONTHS no of times to get the required dates

DO iv_months TIMES." 
CLEAR : lv_last_date,lv_tmp_date.

*Use this function module to get the last day of the month

CALL FUNCTION 'OIL_MONTH_GET_FIRST_LAST'
EXPORTING
i_date    = iv_date
IMPORTING
e_last_day = lv_last_date 
EXCEPTIONS
wrong_date = 1
OTHERS    = 2.
IF sy-subrc = 0.
lv_tmp_date = lv_last_date.

DO .
*Use the FM to get Day of given Date.

CALL FUNCTION 'DATE_TO_DAY'
EXPORTING
date    = lv_tmp_date
IMPORTING
weekday = lv_week_day.
IF lv_week_day CS iv_day+0(3).
APPEND lv_tmp_date TO et_date.
EXIT.
ELSE.
lv_tmp_date = lv_tmp_date - 1.
ENDIF.
ENDDO.
ENDIF.

*Increment month
IF iv_date+4(2) <= '11'.
iv_date+4(2) = iv_date+4(2) + 1.
ELSE.
CLEAR iv_date+4(2).
iv_date+0(4) = iv_date+0(4) + 1.
iv_date+4(2) = iv_date+4(2) + 1.
ENDIF.
ENDDO.

ENDFUNCTION.

Results of custom FM:

            Here, I would   like to get the dates of last Friday of next 3 months (Sep, Oct and Nov) and giving input as today’s date 30.09.2016.
Test Input:

Custom function module to get the dates of last Friday/any day of given number of months and date

Output of FM:

Custom function module to get the dates of last Friday/any day of given number of months and date

Please find the dates of last Fridays for Sep, Oct and Nov in Calendar.
Custom function module to get the dates of last Friday/any day of given number of months and date
Custom function module to get the dates of last Friday/any day of given number of months and date

Custom function module to get the dates of last Friday/any day of given number of months and date

1 comment:

  1. Great work Ms Sabrina P. Got a requirement almost the same but to get the next 'FRIDAY' of any given date. Cheers!

    ReplyDelete