Using method get_current_year
of class cl_hcmfab_reporting_utility
you can get BEGDA and ENDDA of the current year, e.g. 01.01.2025 and 31.12.2025
CALL METHOD cl_hcmfab_reporting_utility=>get_current_year
EXPORTING
iv_date = sy-datlo
IMPORTING
ev_begda = DATA(begda)
ev_endda = DATA(endda).
I couldn’t find a similar method to get the same for the last year. But I could solve the problem with three simple lines.
DATA(last_year) = conv d( sy-datlo - 365 ).
DATA(begda) = last_year(4) && '0101'.
DATA(endda) = last_year(4) && '1231'.
After that, I asked Perplexity and it gave me a similar result.
DATA(lv_last_year) = sy-datum+0(4) - 1.
DATA(lv_begda) = |{ lv_last_year }0101|.
DATA(lv_endda) = |{ lv_last_year }1231|.
Using this method, you could even reduce it to two lines, and it would still be easy to read.
DATA(begda) = |{ sy-datum(4) - 1 }0101|.
DATA(endda) = |{ sy-datum(4) - 1 }1231|.