Vor kurzem ereilte mich die Anforderung einer monatsabhängigen Auswertung. Da kam die Frage auf, wie man für einen Zeitraum die darin erhaltenen Monatsperioden einfach ermitteln kann. Im Standard habe ich auf die Schnelle nichts passendes gefunden, daher habe ich ein Testprogramm mit der entsprechenden Logik umgesetzt, dass für meinen Fall passend funktioniert. Dies wird nun in das OO-Konstrukt eingebaut.
REPORT zr_test_sascha.
PARAMETERS p_beg TYPE datum.
PARAMETERS p_end TYPE datum.
TYPES: BEGIN OF ty_periods,
datv TYPE dats,
datb TYPE dats,
monat_jahr TYPE text25,
END OF ty_periods.
TYPES tty_periods TYPE STANDARD TABLE OF ty_periods.
DATA lv_counter TYPE i.
DATA ls_ttstr LIKE ttstr.
DATA lt_gensegtab TYPE tstr_gensegyeartab.
DATA lt_periods TYPE tty_periods.
DATA lv_monat TYPE fcltx.
DATA lt_years TYPE STANDARD TABLE OF tstr_year.
*--- CUT THE YEAR OF THE DATE FOR THE TIMESTREAM
DATA(lv_year_from) = p_beg+0(4).
DATA(lv_year_to) = p_end+0(4).
DATA(lv_year) = lv_year_from.
IF lv_year_from = lv_year_to.
APPEND lv_year TO lt_years.
ELSE.
APPEND lv_year TO lt_years.
DO.
IF lv_year >= lv_year_to.
EXIT.
ENDIF.
ADD 1 TO lv_year.
APPEND lv_year TO lt_years.
ENDDO.
ENDIF.
CALL FUNCTION 'TSTR_PERIODS_MONTHS'
EXPORTING
it_yeartab = lt_years
is_ttstr = ls_ttstr
IMPORTING
et_gensegtab = lt_gensegtab
EXCEPTIONS
OTHERS = 0.
LOOP AT lt_gensegtab INTO DATA(ls_gensegwa).
LOOP AT ls_gensegwa-gensegtab INTO DATA(ls_genseg).
CHECK ( ls_genseg-begin_date <= p_beg AND
ls_genseg-end_date >= p_beg ) OR
( ls_genseg-begin_date >= p_beg AND
ls_genseg-end_date <= p_end ) OR
( ls_genseg-begin_date <= p_end AND
ls_genseg-end_date >= p_end ).
"Endedatum anpassen
lt_periods = VALUE #( BASE lt_periods ( datv = ls_genseg-begin_date datb = ls_genseg-end_date - 1 ) ).
ENDLOOP.
ENDLOOP.
IF lines( lt_periods ) > 0.
lt_periods[ 1 ]-datv = p_beg.
lt_periods[ lines( lt_periods ) ]-datb = p_end.
ENDIF.
"Monatsnamen
LOOP AT lt_periods ASSIGNING FIELD-SYMBOL(<ls_periods>).
CALL FUNCTION 'ISP_GET_MONTH_NAME'
EXPORTING
date = <ls_periods>-datv
language = sy-langu " gewünschte Sprache für den Namen des Wochentages
IMPORTING
longtext = lv_monat " Langtext 20-stellig
EXCEPTIONS
calendar_id = 1
date_error = 2
not_found = 3
wrong_input = 4
OTHERS = 5.
<ls_periods>-monat_jahr = |{ lv_monat }/{ <ls_periods>-datv(4) }|.
ENDLOOP.
cl_salv_table=>factory(
IMPORTING
r_salv_table = DATA(lo_salv)
CHANGING
t_table = lt_periods
).
lo_salv->display( ).
Sei der Erste der einen Kommentar abgibt