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: 

correction of date subsequently

Former Member
0 Kudos

Hello Abap-Experts!

How can this requirement being implemented ?

Existing fields:

select-options s_date FOR ccihs_ialhiot-evdat.

PARAMETERS p_week TYPE bkk_kdate_week.

User selects any date at s_date.

He enters now a weekday at p_week.

And the goal is now in respect of privous given date

to correct the date according to the weekday.

Example:

entered date = 20080422

entered weekday = 4

and now date must be corrected to 20080424

because the fourth day of the week is Thursday.

Regards

ertas

1 ACCEPTED SOLUTION

naveen1241
Participant
0 Kudos

hi.....

try this way....

PARAMETERS: date TYPE sy-datum,

day1 TYPE i.

DATA: day TYPE dtresr-weekday,

day2 TYPE i,

diff TYPE i.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

date = date

IMPORTING

weekday = day.

TRANSLATE day TO UPPER CASE.

CASE day.

WHEN 'MONDAY'.

day2 = 1.

WHEN 'TUESDAY'.

day2 = 2.

WHEN 'WEDNESDAY'.

day2 = 3.

WHEN 'THURSDAY'.

day2 = 4.

WHEN 'FRIDAY'.

day2 = 5.

WHEN 'SATURDAY'.

day2 = 6.

WHEN 'SUNDAY'.

day2 = 7.

ENDCASE.

diff = day2 - day1.

date = date - diff.

WRITE date.

Regards,

Naveen Natarajan

3 REPLIES 3

Former Member
0 Kudos

There are several options all involving function modules.

I did a search in SE37 for WEEKDAY and got several function modules.

1. BWSO_DATE_GET_FIRST_WEEKDAY you give it a date, in this case 22.04.2008 and it returns the first day of the week, 21.04.2008 then you could add 4 to get your desired date.

2. FIMA_DATE_SHIFT_WITH_WEEKDAY you give it a date and a weekday, in this case 22.04.2008 and 4. It returns the date of the 4th day in the week, 24.04.2008

If these are not ideal, try searching in SE37 for WEEKDAY or WEEKDAY* or DAY.

Hope this helps.

Gill

naveen1241
Participant
0 Kudos

hi.....

try this way....

PARAMETERS: date TYPE sy-datum,

day1 TYPE i.

DATA: day TYPE dtresr-weekday,

day2 TYPE i,

diff TYPE i.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

date = date

IMPORTING

weekday = day.

TRANSLATE day TO UPPER CASE.

CASE day.

WHEN 'MONDAY'.

day2 = 1.

WHEN 'TUESDAY'.

day2 = 2.

WHEN 'WEDNESDAY'.

day2 = 3.

WHEN 'THURSDAY'.

day2 = 4.

WHEN 'FRIDAY'.

day2 = 5.

WHEN 'SATURDAY'.

day2 = 6.

WHEN 'SUNDAY'.

day2 = 7.

ENDCASE.

diff = day2 - day1.

date = date - diff.

WRITE date.

Regards,

Naveen Natarajan

Former Member
0 Kudos

Hi,

Use the below code.

parameters: p_date type sy-datum,

p_day type c.

data: v_week type SCAL-WEEK,

v_date type sy-datum.

CALL FUNCTION 'DATE_GET_WEEK'

EXPORTING

DATE = p_date

IMPORTING

WEEK = v_WEEK

EXCEPTIONS

DATE_INVALID = 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.

CALL FUNCTION 'WEEK_GET_FIRST_DAY'

EXPORTING

WEEK = v_week

IMPORTING

DATE = v_date

EXCEPTIONS

WEEK_INVALID = 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.

case p_day.

when '1'.

p_date = v_date.

when '2'.

p_date = v_date + 1.

when '3'.

p_date = v_date + 2.

when '4'.

p_date = v_date + 3.

when '5'.

p_date = v_date + 4.

when '6'.

p_date = v_date + 5.

when '6'.

p_date = v_date + 6.

when others.

endcase.

write:/ p_date.