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 selecting date by day

Former Member
0 Likes
1,710

Is there any function module to choose date by day. for example if I give today's date the FM should give me next thursday's date.

Thanks

Tharani

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,661

this works good........

&----


*& Report YCHATEST *

*& *

&----


*& *

*& *

&----


REPORT YCHATEST

.

data:day like DTRESR-WEEKDAY.

parameters:curr_dat like sy-datum default sy-datum.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

DATE = CURR_DAT

IMPORTING

WEEKDAY = day.

write : / day.

case day.

when 'Monday'.

CURR_DAT = CURR_DAT + 3.

when 'Tuesday'.

CURR_DAT = CURR_DAT + 2.

when 'Wed.'.

CURR_DAT = CURR_DAT + 1.

when 'Thursday'.

CURR_DAT = CURR_DAT + 7.

when 'Friday'.

CURR_DAT = CURR_DAT + 6.

when 'Sat.'.

CURR_DAT = CURR_DAT + 5.

when 'Sunday'.

CURR_DAT = CURR_DAT + 4.

endcase.

write 😕 CURR_DAT.

.

12 REPLIES 12
Read only

FredericGirod
Active Contributor
0 Likes
1,661

Can you give more example ?

Rgd

Frédéric

Read only

Former Member
0 Likes
1,661

Hi Tharani,

can you explain it more clearly?

In general you can add the number of days directly to date fields, like

date after ten days = sy-datum + 10.

Read only

Former Member
0 Likes
1,661

You can calculate it yourself...

Like...

data MYDATE type D.

MYDATE = SY-DATUM + 7.

write MYDATE.

Read only

abdul_hakim
Active Contributor
0 Likes
1,661

Hi

This u can do it without FM.

For eg.

DATA date LIKE sy-datum.

date = sy-datum + 10.

WRITE date.

Regards,

Abdul

Read only

0 Likes
1,661

hI

Thing is the input date will be dynamic. the current date would be given as input. I have to choose the next Thurday's Date based on my input date.

Thanks

Tharani

Read only

0 Likes
1,661

Hi,

Use FM date_to_day to find the sy-datum.

Then in your program,design the logic,such that

case 'Monday'.

v_date = v_date + 10.

case 'Tuesday'.

v_date = v_date + 9.

....

case 'Sunday'.

..

endcase.

KIndly reward points by clicking the star on the left of reply,if it helps.

Read only

Former Member
0 Likes
1,661

Hi Tharani,

You can use FM <b>WDKAL_DATE_ADD_FKDAYS</b>.

Pass the date, number of days to add and factory calendar, you will get the date according to factory calendar and days entered.

For eg:

date: 01/18/2006

no.of.days: 5

fact. calendar: IN

Will return: 01/25/2006

Regards,

Raj

Read only

Former Member
0 Likes
1,661

May the foll. FM will solves your probs by adding some logic

date_to_day

date_compute_day

Read only

Former Member
0 Likes
1,661

Hi Tharani,

For your requirement you can use FM <b>FIMA_DATE_SHIFT_WITH_WEEKDAY</b>

Pass any date, give I_WEEKDAY as 4,

It will return the date of coming thursday.

Regards,

Raj

Read only

0 Likes
1,661

Hi,

You can use arythmetic operation for field that have sydatum type!

It handles end of monthes . . .

Read only

Former Member
0 Likes
1,661

Hi Tharani,

Here is the code

parameters: p_date like sy-datum.

data:v_day like SCAL-INDICATOR,

v_date type sy-datum.

CALL FUNCTION 'DATE_COMPUTE_DAY'

EXPORTING

date = p_date

IMPORTING

DAY = v_day

.

case v_day.

when '1'.

v_date = p_date + 3.

when '2'.

v_date = p_date + 2.

when '3'.

v_date = p_date + 1.

when '4'.

v_date = p_date + 7.

when '5'.

v_date = p_date + 6.

when '6'.

v_date = p_date + 5.

when '7'.

v_date = p_date + 4.

endcase.

write: v_date.

Best of luck.

Thanks

Eswar

Read only

Former Member
0 Likes
1,662

this works good........

&----


*& Report YCHATEST *

*& *

&----


*& *

*& *

&----


REPORT YCHATEST

.

data:day like DTRESR-WEEKDAY.

parameters:curr_dat like sy-datum default sy-datum.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

DATE = CURR_DAT

IMPORTING

WEEKDAY = day.

write : / day.

case day.

when 'Monday'.

CURR_DAT = CURR_DAT + 3.

when 'Tuesday'.

CURR_DAT = CURR_DAT + 2.

when 'Wed.'.

CURR_DAT = CURR_DAT + 1.

when 'Thursday'.

CURR_DAT = CURR_DAT + 7.

when 'Friday'.

CURR_DAT = CURR_DAT + 6.

when 'Sat.'.

CURR_DAT = CURR_DAT + 5.

when 'Sunday'.

CURR_DAT = CURR_DAT + 4.

endcase.

write 😕 CURR_DAT.

.