How to get first and last date week ABAP? This question we will resolve in this article with using function modules for work with dates in SAP.
Get week number ABAP in SAP
How to get week number in SAP ABAP? For task getting week number SAP you can use function module DATE_GET_WEEK. If you need to plan some weekly activities or check some result by week it can be useful for you. Simple example using function module DATE_GET_WEEK in SAP program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
" Date from parameters, for example DATA(iv_date) = sy-datum. IF iv_date IS NOT SUPPLIED. DATA(lv_date) = sy-datum. ELSE. lv_date = iv_date. ENDIF. CALL FUNCTION 'DATE_GET_WEEK' EXPORTING date = lv_date IMPORTING week = lv_week EXCEPTIONS OTHERS = 2. IF sy-subrc <> 0. "ERROR ENDIF. |
Function module don’t have a lot of parameters, but add for understanding types and exceptions:

First week day ABAP in SAP
How to get first week day in SAP ABAP? Task getting first week day SAP you can resolve with function module WEEK_GET_FIRST_DAY. But more often this FM use with DATE_GET_WEEK for getting week. Example how to get week you can see above. Simple example how get first day week SAP:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
DATA(lv_week) = CONV kweek( 12 ). DATA(lv_start) = CONV datum( 0 ). CALL FUNCTION 'WEEK_GET_FIRST_DAY' EXPORTING week = lv_week IMPORTING date = lv_start EXCEPTIONS OTHERS = 2. IF sy-subrc <> 0. "ERROR ENDIF. |
Function module WEEK_GET_FIRST_DAY don’t have a lot of parameters, but put this for understanding types and exceptions:

How get first and last days week in ABAP program?
Code template:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
DATA(iv_date) = sy-datum. " Date from parameters, for example *---------------------------------- IF iv_date IS INITIAL. DATA(lv_date) = sy-datum. ELSE. lv_date = iv_date. ENDIF. DATA(lv_week) = CONV kweek( 0 ). CALL FUNCTION 'DATE_GET_WEEK' EXPORTING date = lv_date IMPORTING week = lv_week EXCEPTIONS OTHERS = 2. IF sy-subrc <> 0. "ERROR ENDIF. DATA(lv_start) = CONV datum( 0 ). CALL FUNCTION 'WEEK_GET_FIRST_DAY' EXPORTING week = lv_week IMPORTING date = lv_start EXCEPTIONS OTHERS = 4. IF sy-subrc <> 0. "ERROR ENDIF. DATA(lv_end) = CONV datum( 0 ). IF lv_start <= '99991225'. lv_end = lv_start + 6. ELSE. lv_end = '99991231'. ENDIF. |
In this case, for example for LV_DATE = ‘20241018’ after FM DATE_GET_WEEK variable LV_WEEK = ‘202442’.
After function module WEEK_GET_FIRST_DAY LV_START = ‘20241014’.
When we add 6 days to LV_START = ‘20241014’ it will be LV_END = ‘20241020’ .