이상하게 길고 복잡하단 말이지
SELECT matnr,
werks,
lgort,
charg,
lfgja,
lfmon,
clabs
FROM mchb
INTO TABLE @DATA(lt_mchb)
WHERE werks EQ werks
AND matnr EQ matnr
AND lgort EQ lgort
AND charg EQ charg
AND ( ( lfgja = @sy-datum(4) AND lfmon <= @sy-datum+4(2) )
OR lfgja < @sy-datum(4) )
AND ( clabs <> 0 OR cinsm <> 0 OR cspem <> 0 ).
SELECT matnr,
werks,
lgort,
charg,
lfgja,
lfmon,
clabs
FROM mchbh
APPENDING CORRESPONDING FIELDS OF TABLE @lt_mchb
WHERE werks EQ werks
AND matnr EQ matnr
AND lgort EQ lgort
AND charg EQ charg
AND ( ( lfgja = @sy-datum(4) AND lfmon >= @sy-datum+4(2) )
OR lfgja > @sy-datum(4) ).
SORT lt_mchb BY matnr werks lgort charg lfgja lfmon.
DELETE: ADJACENT DUPLICATES FROM lt_mchb COMPARING matnr werks lgort charg,
lt_mchb WHERE clabs = 0.
**************************************************************************************
SELECT werks,
matnr,
lgort,
labst,
insme,
speme,
lfgja,
lfmon
INTO TABLE @DATA(lt_mard)
FROM mard
WHERE werks EQ werks
AND matnr EQ matnr
AND lgort EQ lgort
AND ( ( lfgja = @sy-datum(4) AND lfmon <= @sy-datum+4(2) )
OR lfgja < @sy-datum(4) )
AND ( labst <> 0 OR insme <> 0 OR speme <> 0 ).
SELECT werks,
matnr,
lgort,
labst,
insme,
speme,
lfgja,
lfmon
APPENDING CORRESPONDING FIELDS OF TABLE @lt_mard
FROM mardh
WHERE werks EQ werks
AND matnr EQ matnr
AND lgort EQ lgort
AND ( ( lfgja = @sy-datum(4) AND lfmon >= @sy-datum+4(2) )
OR lfgja > @sy-datum(4) ).
SORT lt_mard BY matnr werks lgort lfgja lfmon.
DELETE ADJACENT DUPLICATES FROM lt_mard
COMPARING matnr werks lgort.
DELETE lt_mard WHERE labst = 0
AND insme = 0
AND speme = 0.