sap-abap-銷售訂單的訂貨,生產,存貨,發貨情況統計報表
阿新 • • 發佈:2019-01-08
這裡是在另一臺oracle伺服器連線 sap 的資料庫寫的檢視,zsdvbap_ex 是個自定義表,儲存了訂單行的文字及可配置物料的特性值,其它均為 sap 標準表.
create or replace view V_SALESORDER_TRACKING_ABC
as
select
ltrim(vk.kunnr,'0') kunnr,--客戶
kv.klabc,--ABC等級
ltrim(vp.vbeln,'0') vbeln,--訂單
ltrim(vp.posnr,'0') posnr,--行
ltrim(vp.matnr,'0') matnr,--物料
mt.MAKTX,--物料描述
ve.EDATU,--交期
vp.KWMENG,--訂貨量(訂貨單位)
vp.VRKME,--訂貨單位
vp.UMVKZ * vp.KWMENG / vp.UMVKN KLMENG, --訂貨量(基本單位)
nvl(va.RFMNG,0) RFMNG,--已出貨數量
nvl(mk.kalab,0) kalab, --庫存數量
vp.UMVKZ * vp.KWMENG / vp.UMVKN - nvl(mk.kalab,0) - nvl(va.RFMNG,0) PLMENG, --欠貨數量
vp.MEINS, --基本單位
ma.MATKL, --"物料組
t23.WGBEZ, --"物料組描敘
ma.SPART, --"產品組
tat.VTEXT, --"產品組描敘
vp.ERDAT, --建立日期
ex.ITMTXT1
|| ex.ITMTXT2
|| ex.ITMTXT3 ITMTXT,--行文字
ex.ATWTB1,
ex.ATWTB2,
ex.ATWTB3,
ex.ATWTB4,--特性
pa.SNAME -- 僱員名稱
from [email protected] kv
LEFT JOIN [email protected] kp ON kp.KUNNR = kv.KUNNR AND kp.VKORG = kv.VKORG AND kp.PARVW = 'ZM'
INNER JOIN [email protected] pa ON pa.PERNR = kp.PERNR
inner join [email protected] vk on vk.kunnr=kv.kunnr and vk.vkorg=kv.vkorg
inner join [email protected] vp on vp.vbeln=vk.vbeln
INNER JOIN [email protected] mt ON mt.matnr = vp.matnr AND mt.spras = '1'
INNER JOIN [email protected] ve ON ve.VBELN = vp.VBELN AND ve.POSNR = vp.POSNR AND ve.ETENR = 1
INNER JOIN [email protected] ma ON ma.MATNR = vp.MATNR
left Join [email protected] t23 On t23.MATKL = ma.MATKL and t23.SpRAS = '1'
Left Join [email protected] tat on tat.SPART = ma.SPART and tat.spRAs = '1'
LEFT JOIN
(SELECT VBELN,
POSNR,
SUM( KALAB ) kalab --訂單庫存
FROM [email protected]
group by VBELN, POSNR
) mk ON mk.vbeln = vp.vbeln AND mk.posnr = vp.posnr
LEFT JOIN
(select --取訂單行的已發貨數量
vp2.vbeln,
vp2.posnr,
sum(va2.RFMNG)rfmng
from [email protected] vp2
inner join [email protected] va2 ON va2.VBELV = vp2.vbeln AND va2.POSNV = vp2.posnr and ( va2.VBTYP_N = 'T' or va2.VBTYP_N = 'J' )
inner join [email protected] vu on vu.vbeln = va2.VBELN and vu.posnr = va2.POSNN and vu.WBSTA = 'C'
group by vp2.vbeln, vp2.posnr
) va ON va.vbeln = vp.vbeln AND va.posnr = vp.posnr
LEFT JOIN [email protected] ex
ON ex.vbeln = vp.vbeln
AND ex.posnr = vp.posnr
where loevm=' ' --沒有刪除標記的
and vp.ABGRU=' '
order by ve.edatu,vp.ERDAT;