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 for date

Former Member
0 Likes
573

Hi

Can someone pls help me with this.I need a function module which gets t last day of the week(Sun) date for a date range entered. For eg if i enter 3sep2007to 6th sep 2007 it should fetch me the sunday of that week ie 9 th sep.Also if i enter the range as a few months it should be able t fetch all t sun for t date entered.

4 REPLIES 4
Read only

Former Member
0 Likes
544

hii

for example if ur select option is s_date and if u provide s_date-high as parameter to the function module 'GET_WEEK_INFO_BASED_ON_DATE' u wil get the week starting and week ending i.e prev sunday and 9 th sep monday. try it out if u have any dbts pls revert back

Read only

Former Member
0 Likes
544

Hi KB,

As you have mentioned 2 Requirments,

First: Get Last day of the week for a given date range.

Give the last date in FM GET_WEEK_INFO_BASED_ON_DATE you get the sunday.

Second: Get Last day for the given Month.

We hava a function module to find all the sunday in a Year. I think that should be ok for you.

FM: TSTR_PERIODS_AMERICAN_WEEKS

Try and Let me know if you have any issues.

*Dont forget to reward points if useful,

Lijo Joseph

Read only

varma_narayana
Active Contributor
0 Likes
544

Hi..

Use this FM

WEEK_GET_FIRST_DAY – take input as YYYYWW and it gives first day of the week.

As per ur req you can use it.

<b>reward if Helpful</b>

Read only

Former Member
0 Likes
544

Hi KB,

The below code will satisfy your requirement 100%.

SELECT-OPTIONS: s_date FOR sy-datum NO-EXTENSION.

DATA: BEGIN OF it_sun_dates OCCURS 0,

date TYPE sy-datum,

END OF it_sun_dates.

DATA: v_sun_date TYPE sy-datum.

DATA: v_high_date TYPE sy-datum.

DATA: v_wotnr TYPE p.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF screen-name = 'S_DATE-LOW' OR

screen-name = 'S_DATE-HIGH'.

screen-required = 1.

ENDIF.

MODIFY SCREEN.

ENDLOOP.

START-OF-SELECTION.

v_high_date = s_date-high.

WHILE s_date-low LE s_date-high.

IF NOT v_sun_date IS INITIAL.

EXIT.

ENDIF.

CALL FUNCTION 'DAY_IN_WEEK'

EXPORTING

datum = s_date-low

IMPORTING

wotnr = v_wotnr.

IF v_wotnr = 7.

v_sun_date = s_date-low.

ENDIF.

s_date-low = s_date-low + 1.

ENDWHILE.

IF NOT v_sun_date IS INITIAL.

WHILE v_sun_date LE v_high_date.

it_sun_dates-date = v_sun_date.

APPEND it_sun_dates.

v_sun_date = v_sun_date + 7.

ENDWHILE.

CALL FUNCTION 'DAY_IN_WEEK'

EXPORTING

datum = v_high_date

IMPORTING

wotnr = v_wotnr.

v_wotnr = 7 - v_wotnr.

it_sun_dates-date = v_high_date + v_wotnr.

APPEND it_sun_dates.

ELSE.

CALL FUNCTION 'DAY_IN_WEEK'

EXPORTING

datum = v_high_date

IMPORTING

wotnr = v_wotnr.

v_wotnr = 7 - v_wotnr.

it_sun_dates-date = v_high_date + v_wotnr.

APPEND it_sun_dates.

ENDIF.

WRITE:/5 'The list of Sundays in the range'.

SKIP.

if not it_sun_dates[] is initial.

sort it_sun_dates by date.

delete adjacent duplicates from it_sun_dates comparing date.

endif.

LOOP AT it_sun_dates.

WRITE:/5 it_sun_dates-date.

ENDLOOP.