Application Development 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: 

function Module for selecting date by day

Former Member
0 Kudos

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

Former Member
0 Kudos

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

FredericGirod
Active Contributor
0 Kudos

Can you give more example ?

Rgd

Frédéric

former_member181962
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

You can calculate it yourself...

Like...

data MYDATE type D.

MYDATE = SY-DATUM + 7.

write MYDATE.

abdul_hakim
Active Contributor
0 Kudos

Hi

This u can do it without FM.

For eg.

DATA date LIKE sy-datum.

date = sy-datum + 10.

WRITE date.

Regards,

Abdul

0 Kudos

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

0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

date_to_day

date_compute_day

Former Member
0 Kudos

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

0 Kudos

Hi,

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

It handles end of monthes . . .

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

.