Code: Alles auswählen.
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,
bschl LIKE bsak-bschl,
dmbtr LIKE bsak-dmbtr,
wrbtr LIKE bsak-wrbtr,
zdlkz LIKE zdlkz_t-zdlkz,
bezeichnung LIKE zdlkz_t-bezeichnung,
soha TYPE p DECIMALS 2,
soll TYPE p DECIMALS 2,
haben TYPE p DECIMALS 2,
zahler TYPE i,
END OF itab_sumla.
DATA: wa_soha LIKE LINE 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.
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 zdlkz bezeichnung
FROM zdlkz_t INTO CORRESPONDING FIELDS OF wa_zdlkz_t
WHERE zdlkz IN so_dlkz.
MOVE-CORRESPONDING wa_zdlkz_t TO itab_sumla.
APPEND itab_sumla.
ENDSELECT.
SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat
b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr
INTO TABLE itab_sumla
FROM ( lfa1 AS a
INNER JOIN bsak AS b
ON a~lifnr = b~lifnr )
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND land1 IN so_land
OR land1 = space
AND gjahr = pa_gj
OR gjahr = space
AND monat IN so_perio
OR monat = space.
APPEND itab_sumla.
SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat
b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr
INTO TABLE itab_sumla
FROM ( lfa1 AS a
INNER JOIN bsik AS b
ON a~lifnr = b~lifnr )
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND land1 IN so_land
OR land1 = space
AND gjahr = pa_gj
OR gjahr = space
AND monat IN so_perio
OR monat = space.
IF sy-subrc <> 0.
MESSAGE i819(3f).
* Keine Daten im gewählten Zeitraum vorhanden
ENDIF.
* wa_soha-.... weil durch DATA Deklaration wa_soha
LOOP AT itab_sumla INTO wa_soha.
IF wa_soha-shkzg = 'H'.
wa_soha-haben = wa_soha-dmbtr.
ELSE.
wa_soha-soll = wa_soha-dmbtr.
ENDIF.
wa_soha-soha = wa_soha-haben - wa_soha-soll.
IF wa_soha-zuonr = space. " wird wa_soha-zdlkz!!
wa_soha-zahler = 1.
ELSE.
wa_soha-zahler = 0.
ENDIF.
IF wa_soha-zuonr = wa_soha-zdlkz.
wa_soha-zdlkz = wa_soha-zuonr.
ELSE.
wa_soha-zdlkz = space.
ENDIF.
MODIFY itab_sumla FROM wa_soha TRANSPORTING soll.
MODIFY itab_sumla FROM wa_soha TRANSPORTING haben.
MODIFY itab_sumla FROM wa_soha TRANSPORTING soha.
MODIFY itab_sumla FROM wa_soha TRANSPORTING zahler.
MODIFY itab_sumla FROM wa_soha TRANSPORTING zdlkz.
ENDLOOP.
Warum 5 MODIFY-Anweisungen statt einer?robin1at hat geschrieben:Code: Alles auswählen.
MODIFY itab_sumla FROM wa_soha TRANSPORTING soll. MODIFY itab_sumla FROM wa_soha TRANSPORTING haben. MODIFY itab_sumla FROM wa_soha TRANSPORTING soha. MODIFY itab_sumla FROM wa_soha TRANSPORTING zahler. MODIFY itab_sumla FROM wa_soha TRANSPORTING zdlkz.
Code: Alles auswählen.
IF wa_soha-zuonr = wa_soha-zdlkz.
wa_soha-zdlkz = wa_soha-zuonr.
ELSE.
wa_soha-zdlkz = space.
ENDIF.
Code: Alles auswählen.
IF wa_soha-zuonr <> wa_soha-zdlkz.
wa_soha-zdlkz = space.
ENDIF.
Code: Alles auswählen.
START-OF-SELECTION.
*##################
SELECT zdlkz bezeichnung
FROM zdlkz_t INTO CORRESPONDING FIELDS OF TABLE itab_sumla
WHERE zdlkz IN so_dlkz
OR zdlkz = space.
APPEND itab_sumla.
SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat
b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr
INTO TABLE itab_sumla
FROM ( lfa1 AS a
INNER JOIN bsak AS b
ON a~lifnr = b~lifnr )
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND land1 IN so_land
OR land1 = space
AND gjahr = pa_gj
OR gjahr = space
AND monat IN so_perio
OR monat = space.
APPEND itab_sumla.
SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat
b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr
INTO TABLE itab_sumla
FROM ( lfa1 AS a
INNER JOIN bsik AS b
ON a~lifnr = b~lifnr )
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND land1 IN so_land
OR land1 = space
AND gjahr = pa_gj
OR gjahr = space
AND monat IN so_perio
OR monat = space.
IF sy-subrc <> 0.
MESSAGE i819(3f).
* Keine Daten im gewählten Zeitraum vorhanden
ENDIF.
das ist gemeint damit:robin1at hat geschrieben: Was hast Du gemeint mit Klammersetzung bei AND / OR ?
SEHR GENAU AUF "AND" UND "OR" ACHTEN!
Bei Mathe gilt "Punkt vor Strich",
bei SQL gilt "AND vor OR"!
Code: Alles auswählen.
SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat
b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr
INTO CORRESPONDING FIELDS OF TABLE itab_sumla
FROM ( lfa1 AS a
INNER JOIN bsak AS b
ON a~lifnr = b~lifnr )
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND land1 IN so_land
OR land1 = space
AND gjahr = pa_gj
OR gjahr = space
AND monat IN so_perio
OR monat = space.
APPEND itab_sumla.
Code: Alles auswählen.
START-OF-SELECTION.
*##################
SELECT zdlkz bezeichnung
FROM zdlkz_t INTO CORRESPONDING FIELDS OF TABLE itab_sumla
WHERE zdlkz IN so_dlkz
OR zdlkz = space.
APPEND itab_sumla.
SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat
b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr
INTO CORRESPONDING FIELDS OF TABLE itab_sumla
FROM ( lfa1 AS a
INNER JOIN bsak AS b
ON a~lifnr = b~lifnr )
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND land1 IN so_land
OR land1 = space
AND gjahr = pa_gj
OR gjahr = space
AND monat IN so_perio
OR monat = space.
APPEND itab_sumla.
SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat
b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr
INTO CORRESPONDING FIELDS OF TABLE itab_sumla
FROM ( lfa1 AS a
INNER JOIN bsik AS b
ON a~lifnr = b~lifnr )
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND land1 IN so_land
OR land1 = space
AND gjahr = pa_gj
OR gjahr = space
AND monat IN so_perio
OR monat = space.
IF sy-subrc <> 0.
MESSAGE i819(3f).
* Keine Daten im gewählten Zeitraum vorhanden
ENDIF.
Code: Alles auswählen.
START-OF-SELECTION.
*##################
SELECT zdlkz bezeichnung
FROM zdlkz_t INTO CORRESPONDING FIELDS OF TABLE itab_sumla
WHERE zdlkz IN so_dlkz
OR zdlkz = space.
* ---> APPEND itab_sumla. überflüssig
SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat
b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr
* INTO CORRESPONDING FIELDS OF TABLE itab_sumla
APPENDING CORRESPONDING FIELDS OF TABLE itab_sumla
FROM ( lfa1 AS a
INNER JOIN bsak AS b
ON a~lifnr = b~lifnr )
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND land1 IN so_land
OR land1 = space
AND gjahr = pa_gj
OR gjahr = space
AND monat IN so_perio
OR monat = space.
* ---> APPEND itab_sumla. überflüssig
SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat
b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr
* INTO CORRESPONDING FIELDS OF TABLE itab_sumla
APPENDING CORRESPONDING FIELDS OF TABLE itab_sumla
FROM ( lfa1 AS a
INNER JOIN bsik AS b
ON a~lifnr = b~lifnr )
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND land1 IN so_land
OR land1 = space
AND gjahr = pa_gj
OR gjahr = space
AND monat IN so_perio
OR monat = space.
IF sy-subrc <> 0.
MESSAGE i819(3f).
* Keine Daten im gewählten Zeitraum vorhanden
ENDIF.
Code: Alles auswählen.
WHERE bukrs IN ('1001')
AND blart IN ('A1', 'A2', 'A3')
AND ( land1 IN so_land OR
land1 = space )
AND ( gjahr = pa_gj OR
gjahr = space )
AND ( monat IN so_perio OR
monat = space ).
olli-x hat geschrieben:By the way: Die F1-Hilfe ist hier recht anschaulichCode: Alles auswählen.
START-OF-SELECTION. *################## SELECT zdlkz bezeichnung FROM zdlkz_t INTO CORRESPONDING FIELDS OF TABLE itab_sumla WHERE zdlkz IN so_dlkz OR zdlkz = space. * ---> APPEND itab_sumla. überflüssig SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr * INTO CORRESPONDING FIELDS OF TABLE itab_sumla APPENDING CORRESPONDING FIELDS OF TABLE itab_sumla FROM ( lfa1 AS a INNER JOIN bsak AS b ON a~lifnr = b~lifnr ) WHERE bukrs IN ('1001') AND blart IN ('A1', 'A2', 'A3') AND land1 IN so_land OR land1 = space AND gjahr = pa_gj OR gjahr = space AND monat IN so_perio OR monat = space. * ---> APPEND itab_sumla. überflüssig SELECT a~lifnr a~land1 b~diekz b~belnr b~zuonr b~blart b~bukrs b~monat b~gjahr b~shkzg b~bschl b~dmbtr b~wrbtr * INTO CORRESPONDING FIELDS OF TABLE itab_sumla APPENDING CORRESPONDING FIELDS OF TABLE itab_sumla FROM ( lfa1 AS a INNER JOIN bsik AS b ON a~lifnr = b~lifnr ) WHERE bukrs IN ('1001') AND blart IN ('A1', 'A2', 'A3') AND land1 IN so_land OR land1 = space AND gjahr = pa_gj OR gjahr = space AND monat IN so_perio OR monat = space. IF sy-subrc <> 0. MESSAGE i819(3f). * Keine Daten im gewählten Zeitraum vorhanden ENDIF.
Gruß,
Olli