每个公司都会有自己的销售报表,
一般来说VA05的都满足不了客户的定制化需求。
所以都要进行自定义报表的开发,
在开发的过程中,也会有未清销售订单和已清销售订单的区分
一开始我的想法是,根据销售订单去找交货单累计已交货的数量,
然后再用销售订单的数量减去已交货的数量,
但是这种计算方法,程序的运行效率就会比较低,
我就用了ST05去debug VA05的 open so的计算方法
具体sql 如下
SELECT
DISTINCT VBAK.AUART, VBAK.AUDAT, COALESCE( VBKD.BSTKD , VBKD_HEAD.BSTKD ),
VBAK.KUNNR, VBAP.KWMENG, VBAP.MATNR, VBAP.POSNR, VBAK.SPART, VBAP.NETWR,
VBAK.VBELN, VBAK.VKORG, VBAP.VRKME, VBAK.VTWEG, VBAK.WAERK
FROM
VBAK INNER JOIN VBAP ON VBAP.MANDT = '200' AND VBAP.VBELN = VBAK.VBELN
INNER JOIN VBKD VBKD_HEAD ON VBKD_HEAD.MANDT = '200' AND VBKD_HEAD.VBELN =
VBAK.VBELN AND VBKD_HEAD.POSNR = '000000' LEFT OUTER JOIN VBKD ON VBKD.
MANDT = '200' AND VBKD.VBELN = VBAP.VBELN AND VBKD.POSNR = VBAP.POSNR
WHERE
VBAK.MANDT = '200' AND VBAK.TRVOG = '0' AND ( VBAK.ERDAT BETWEEN
'20240301' AND '20240315') AND ((VBAK.GBSTK IN ('A','B') OR VBAK.LFGSK IN
('A','B')) OR (VBAP.GBSTA IN ('A','B') OR VBAP.LFGSA IN ('A','B'))) AND ((
VBAK.GBSTK IN ('A','B') OR VBAK.LFGSK IN ('A','B')) OR (VBAP.GBSTA IN ('A'
,'B') OR VBAP.LFGSA IN ('A','B')))
ORDER BY
VBAK.VBELN
然后因为IN 在CDS 中无法使用,故我改版了一个cds view
define view ZCDS_OPEN_SO as select from vbak
inner join vbap on vbap.mandt = $session.client and vbap.vbeln = vbak.vbeln
inner join vbkd as VBKD_HEAD on VBKD_HEAD.mandt = $session.client and VBKD_HEAD.vbeln = vbak.vbeln and VBKD_HEAD.posnr = '000000'
left outer join vbkd on vbkd.mandt = $session.client and vbkd.vbeln = vbap.vbeln and vbkd.posnr = vbap.posnr
{
vbak.auart,
vbak.audat,
COALESCE( vbkd.bstkd , VBKD_HEAD.bstkd ) as BSTKD,
vbak.kunnr,
vbap.kwmeng,
vbap.matnr,
vbap.posnr,
vbak.spart,
vbap.netwr,
vbak.vbeln,
vbak.vkorg,
vbap.vrkme,
vbak.vtweg,
vbak.waerk
}
where vbak.trvog = '0'
and ( ( ( vbak.gbstk = 'A' or vbak.gbstk = 'B') or ( vbak.lfgsk = 'A' or vbak.lfgsk = 'B') ) or ( ( vbap.gbsta = 'A' or vbap.gbsta = 'B') or ( vbap.lfgsa = 'A' or vbap.lfgsa = 'B') ) )
and ( ( ( vbak.gbstk = 'A' or vbak.gbstk = 'B') or ( vbak.lfgsk = 'A' or vbak.lfgsk = 'B') ) or ( ( vbap.gbsta = 'A' or vbap.gbsta = 'B') or ( vbap.lfgsa = 'A' or vbap.lfgsa = 'B') ) )