Code: Alles auswählen.
lv_first_day = sy-datum.
TRY.
CALL METHOD cl_bs_period_toolset_basics=>get_last_day_in_month
EXPORTING
iv_date = lv_first_day
RECEIVING
rv_date = lv_last_day.
CATCH cx_bs_period_toolset_basics.
ENDTRY.
CLEAR lt_rdate.
ls_rdate-sign = 'I'.
ls_rdate-option = 'BT'.
ls_rdate-low = lv_first_day.
ls_rdate-high = lv_last_day.
APPEND ls_rdate TO lt_rdate.
DO.
CLEAR lv_first_day.
lv_first_day = lv_last_day + 1.
TRY.
CALL METHOD cl_bs_period_toolset_basics=>get_last_day_in_month
EXPORTING
iv_date = lv_first_day
RECEIVING
rv_date = lv_last_day.
CATCH cx_bs_period_toolset_basics.
ENDTRY.
ls_rdate-sign = 'I'.
ls_rdate-option = 'BT'.
ls_rdate-low = lv_first_day.
ls_rdate-high = lv_last_day.
APPEND ls_rdate TO lt_rdate.
IF sy-tabix = p_pdate.
EXIT.
ENDIF.
ENDDO.
LOOP AT lt_test INTO ls_test.
SELECT SINGLE * FROM mdkp INTO ls_mdkp
WHERE matnr = ls_test-matnr
AND plwrk = ls_test-werks.
lv_dtnum = ls_mdkp-dtnum.
PERFORM calculate_plumi.
ls_test-lv_requr = lv_requr.
ls_test-lv_aquis = lv_aquis.
INSERT ls_test INTO lt_test.
ENDLOOP.
SORT lt_test BY date.
SORT lt_test BY matnr.
FORM calculate_plumi.
SELECT * INTO TABLE lt_mdtb
FROM mdtb
WHERE dtnum = lv_dtnum
AND dat01 IN lt_rdate.
IF sy-subrc = 0.
LOOP AT lt_mdtb INTO ls_mdtb.
CASE ls_mdtb-plumi.
WHEN '+'.
lv_aquis = lv_aquis + ls_mdtb-mng01.
WHEN '-'.
lv_requr = lv_requr + ls_mdtb-mng01.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
ENDIF.
ENDFORM.
Code: Alles auswählen.
SELECT mdkp~matnr, mdkp~plwrk, mdtb~dat01,
SUM( CASE mdtb~plumi WHEN '+' THEN mdtb~mng01 ELSE 0 END ) AS aquis,
SUM( CASE mdtb~plumi WHEN '-' THEN mdtb~mng01 ELSE 0 END ) AS requr
FROM mdkp INNER JOIN mdtb
ON mdkp~dtnum EQ mdtb~dtnum
INTO TABLE @DATA(lt_result)
WHERE mdkp~matnr IN @lt_matnr
AND mdkp~plwrk IN @lt_werks
AND mdtb~dat01 IN @lt_rdate
GROUP BY mdkp~matnr, mdkp~plwrk, mdtb~dat01.
Code: Alles auswählen.
SELECT mdkp~matnr, mdkp~plwrk, substring( mdtb~dat01, 5, 2 ) AS month,
SUM( CASE mdtb~plumi WHEN '+' THEN mdtb~mng01 ELSE 0 END ) AS aquis,
SUM( CASE mdtb~plumi WHEN '-' THEN mdtb~mng01 ELSE 0 END ) AS requr
FROM mdkp INNER JOIN mdtb
ON mdkp~dtnum EQ mdtb~dtnum
WHERE mdkp~matnr IN @lt_matnr
AND mdkp~plwrk IN @lt_werks
AND mdtb~dat01 IN @lt_rdate
GROUP BY mdkp~matnr, mdkp~plwrk, substring( mdtb~dat01, 5, 2 )
INTO TABLE @DATA(lt_result).
Code: Alles auswählen.
DATA:
lt_rdate TYPE RANGE OF d,
lt_matnr TYPE RANGE OF matnr,
lt_werks TYPE RANGE OF werks_d.
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
abap_frischling
Code: Alles auswählen.
substring( mdtb~dat01, 1, 6 )
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
abap_frischling