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

ABAP Classes for date & day computation

Former Member
0 Likes
2,928

<<Date questions have been asked so many times that they are not permitted in the ABAP forums>>

Hello, I have a requirement to get the date of last 2 thursdays. Can somebody please help with the class I should use for the purpose?

Thanks!

Edited by: Matt on Aug 16, 2011 11:50 AM

<<Date questions have been asked so many times that they are not permitted in the ABAP forums>>

Hello, I have a requirement to get the date of last 2 thursdays. Can somebody please help with the class I should use for the purpose?

Thanks!

Edited by: Matt on Aug 16, 2011 11:50 AM

3 REPLIES 3
Read only

Former Member
0 Likes
2,051

Hey,

DATE_COMPUTE_DAY will give you DAY number for any date, with day number 1 as Monday .....4 as Thursday....and 7 as Sunday.

SO, you can use ..


data: lv_day type SCAL-INDICATOR,
      lv_diff type i,
      lv_thurs1 type sy-datum,
      lv_thurs2 type sy-datum.

PARAMETERS: p_date type datum DEFAULT sy-datum.

CALL FUNCTION 'DATE_COMPUTE_DAY'
  EXPORTING
    date          = p_date
  IMPORTING
    DAY           = lv_day
          .

lv_diff = lv_day - 4.         "since Thursday is 4

if lv_diff GT 0.
  lv_thurs1 = p_date - lv_diff.
else.
  lv_thurs1 = p_date - 7 - lv_diff.
endif.

  lv_thurs2 = lv_thurs1 - 7.

  write:/ lv_thurs1, lv_thurs2.

I have not included today's date if it is Thursday, if you want to include it, change 'GT' to 'GE'.

BR,

Diwakar

Edited by: Diwakar Aggarwal on Aug 16, 2011 10:49 AM

Read only

0 Likes
2,051

Thanks for your response Diwakar! Is there a class & method that I can use instead of the function module?

Read only

0 Likes
2,051

Hey,

Able to find a class CL_HRPAD_DATE_COMPUTATIONS, method GET_WEEKDAY_NUMBER.

Just use it instead of function and rest remains same.

BR,

Diwakar