select WERKS, MATNR,
sum( case when SHKZG = 'S' then MENGE when SHKZG = 'H' then ( MENGE * -1 ) end )
as MENGE
from MSEG into corresponding fields of table @LT_MSEGS
where MATNR in @SO_MATNR
and WERKS in @SO_WERKS
and BUDAT_MKPF in @R_FDAY
and BWART in ('101','102','161','162','122','123')
group by WERKS,MATNR order by WERKS,MATNR
来源:https://www.cnblogs.com/eagle-dtq/p/11803963.html