2011 Aug 16 12:29 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
<<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
2011 Aug 16 3:48 AM
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
2011 Aug 16 5:41 AM
Thanks for your response Diwakar! Is there a class & method that I can use instead of the function module?
2011 Aug 16 6:38 AM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |