Code: Alles auswählen.
REPORT zsumla.
TYPE-POOLS slis.
TABLES: lfa1, bseg, bkpf, bsik, bsak, zdlkz_t.
DATA: wa_lfa1 TYPE lfa1,
wa_zdlkz_t TYPE zdlkz_t,
wa_bkpf TYPE bkpf,
wa_bsak TYPE bsak,
wa_bsik TYPE bsik.
DATA: BEGIN OF itab_sumla OCCURS 10,
lifnr LIKE lfa1-lifnr,
land1 LIKE lfa1-land1,
diekz LIKE bsak-diekz,
belnr LIKE bsak-belnr,
zuonr LIKE bsak-zuonr,
blart LIKE bsak-blart,
bukrs LIKE bsak-bukrs,
monat LIKE bsak-monat,
gjahr LIKE bsak-gjahr,
shkzg LIKE bsak-shkzg,
dmbtr LIKE bsak-dmbtr,
wrbtr LIKE bsak-wrbtr,
zdlkz LIKE zdlkz_t-zdlkz,
bezeichnung LIKE zdlkz_t-bezeichnung,
END OF itab_sumla.
DATA: my_fieldcat TYPE slis_t_fieldcat_alv,
wa_layout TYPE slis_layout_alv,
wa_fieldcat LIKE LINE OF my_fieldcat,
repid TYPE sy-repid.
wa_layout-colwidth_optimize = 'X'.
SELECT-OPTIONS: so_land FOR lfa1-land1,
so_perio FOR bkpf-monat.
PARAMETERS pa_gj LIKE bseg-gjahr.
SELECT-OPTIONS: so_dlkz FOR zdlkz_t-zdlkz.
START-OF-SELECTION.
*##################
SELECT lifnr land1
FROM lfa1 INTO CORRESPONDING FIELDS OF wa_lfa1
WHERE land1 IN so_land.
MOVE-CORRESPONDING wa_lfa1 TO itab_sumla.
SELECT lifnr zuonr gjahr belnr monat blart diekz bukrs shkzg dmbtr
wrbtr
FROM bsak INTO CORRESPONDING FIELDS OF wa_bsak
WHERE lifnr = wa_lfa1-lifnr
AND gjahr = pa_gj
AND monat IN so_perio
AND bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3').
MOVE-CORRESPONDING wa_bsak TO itab_sumla.
SELECT lifnr zuonr gjahr belnr monat blart diekz bukrs shkzg dmbtr
wrbtr
FROM bsik INTO CORRESPONDING FIELDS OF wa_bsik
WHERE lifnr = wa_lfa1-lifnr
AND blart IN ('A1', 'A2', 'A3')
AND bukrs IN ('1001')
AND bukrs = wa_bsak-bukrs
AND monat IN so_perio
AND gjahr = pa_gj.
MOVE-CORRESPONDING wa_bsik TO itab_sumla.
SELECT zdlkz bezeichnung
FROM zdlkz_t INTO CORRESPONDING FIELDS OF wa_zdlkz_t
WHERE zdlkz IN so_dlkz.
* AND zdlkz IN ('2080', '2090', '2070').
MOVE-CORRESPONDING wa_zdlkz_t TO itab_sumla.
APPEND itab_sumla.
ENDSELECT.
ENDSELECT.
ENDSELECT.
CLEAR itab_sumla.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE i819(3f).
* Keine Daten im gewählten Zeitraum vorhanden
ENDIF.
repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_structure_name = 'ZMYSTRUKTUR'
CHANGING
ct_fieldcat = my_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE e707(69).
* Lesefehler
ENDIF.
DELETE my_fieldcat WHERE NOT ( fieldname = 'BLART'
OR fieldname = 'ZDLKZ'
OR fieldname = 'LAND1'
OR fieldname = 'GJAHR'
OR fieldname = 'SHKZG'
OR fieldname = 'DMBTR'
OR fieldname = 'WRBTR'
OR fieldname = 'MONAT').
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = wa_layout
it_fieldcat = my_fieldcat
TABLES
t_outtab = itab_sumla
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e707(69).
* Lesefehler
ENDIF.