Code: Alles auswählen.
SELECT kb~menge kulab bk~bwart INTO TABLE beleg
FROM ( ( mseg AS kb INNER JOIN mseg AS bk
ON bk~kunnr = kb~kunnr AND bk~matnr = kb~matnr )
INNER JOIN mkpf AS mk
ON mk~mblnr = bk~mblnr )
INNER JOIN msku AS ku
ON ku~kunnr = kb~kunnr AND ku~matnr = kb~matnr
WHERE kb~mblnr = wa-mblnr
AND ( bk~bwart = '201' OR bk~bwart = '202' )
AND cpudt = sdatum.
Code: Alles auswählen.
SELECT mblnr matnr kunnr menge
INTO TABLE mseg_tab
FROM mseg
WHERE mblnr = wa-mblnr.
LOOP AT mseg_tab.
beleg-menge = mseg_tab-menge.
SELECT seg~bwart seg~matnr seg~kunnr
INTO (beleg-bwart, tmp_matnr, tmp_kunnr)
FROM mseg AS seg INNER JOIN mkpf AS kpf
ON kpf~mblnr = seg~mblnr
WHERE seg~bwart IN ('201', '202')
AND seg~matnr = mseg_tab-matnr
AND seg~kunnr = mseg_tab-kunnr
AND kpf~cpudt = sdatum.
SELECT kulab
INTO beleg-kulab
FROM msku
WHERE kunnr = tmp_kunnr
AND matnr = tmp_matnr.
APPEND beleg.
CLEAR: beleg-kulab.
ENDSELECT.
CLEAR: tmp_kunnr, tmp_matnr, beleg-bwart.
ENDSELECT.
ENDLOOP.
Code: Alles auswählen.
...
SELECT mblnr matnr kunnr menge
INTO TABLE mseg_tab
FROM mseg
WHERE mblnr = wa-mblnr.
* Mit der Matnr und der Kunnr aus diesem Mseg eintrag werden
* weitere Einträge gesucht...
LOOP AT mseg_tab.
SELECT bwart matnr kunnr
INTO (beleg-bwart, tmp_matnr, tmp_kunnr)
FROM mseg
WHERE bwart IN ('201', '202')
AND matnr = mseg_tab-matnr
AND kunnr = mseg_tab-kunnr.
...