ABAP-动态内表多行转一行

因为ABAP新语法支持标准SQL语法。所以可以使用case when直接内表取值实现转换
注意AS后的别名要跟动态内表内的动态字段名字保持一致,否则无法赋值

enab可直接更换为内表

select werks,
       matnr,
sum( case when lfdat = '20201028' then menge - bsmng end ) as D20201028,
sum( case when lfdat = '20201029' then menge - bsmng end ) as D20201029,
sum( case when lfdat = '20201030' then menge - bsmng end ) as D20201030,
sum( case when lfdat = '20201031' then menge - bsmng end ) as D20201031,
sum( case when lfdat <= '20201107' and lfdat >= '20201101' then menge - bsmng end ) as D20201101,
sum( case when lfdat <= '20201114' and lfdat >= '20201108' then menge - bsmng end ) as D20201108
from eban
where matnr <> ' '
and   werks = '1010'
and   loekz = ' '
group by werks,matnr
1605575974(1).jpg

1605576109(1).jpg

你可能感兴趣的:(ABAP-动态内表多行转一行)