所有物料规划PR时对净需求+最小采购批量+安全库存+舍入值的先后考虑逻辑20171207-1228.docx
PR回写案例一:
SELECT SAFE_QTY,A.* FROM SAP_MARC A where MATNR='' and WERKS=''; --SAFE_QTY:安全库存
SELECT MIN_LOT_SIZE,LOTSIZE_INCREMENT,A.* FROM IN_SUPPLIER_ITEM A where item_id='' ; -- MIN_LOT_SIZE最小采购批量 LOTSIZE_INCREMENT舍入值
SELECT PR_CONSOLIDATE_DAYS,A.* FROM IN_ITEM_SITE A where item_id='' and SITE_ID=''; --合并下PR的时间区间 WB7 TB1 EX0 W2_14 T3_3
SELECT * FROM OUT_PR_jiankong WHERE ITEM='000000104004000454' ; --PR 净需求
SELECT * FROM OUT_PR WHERE ITEM='' ; ---加上PR回写逻辑后
SELECT * FROM TP_TEMP_PR WHERE ITEM='' ; ---最终回写去SAP的数据 select out_pr.PO_RELEASE_DATE,out_pr.supplier_id,out_pr.site_id,sap_eord.ekorg,out_pr.proc_group_id,out_pr.item,out_pr.qty,out_pr.qtyuom,substr(loc_id,-4) as LGORT
,'SAPRFC' as ERNAM,out_pr.due_datetime,out_pr.so_id,out_pr.so_lineid,out_pr.sobsl
from V_OUT_PR out_pr --其实是select * from tp_temp_pr
join sap_eord on out_pr.item = sap_eord.matnr and out_pr.supplier_id = sap_eord.lifnr and out_pr.site_id = sap_eord.werks
where out_pr.item in ('');
按照如下进行优化,优化后效果如下:
查询代码
1、首先写入OUT_PR中净需求数据
----包材物料组展望期设置14天 FP_PR2SAP 246行代码
SELECT MAX (PR.ORDERID),
PR.ITEM,
SUBSTR (PR.RECOMMENDEDSUPID, 6),
TRUNC (PR.PORELEASEDATE),
SUM (PR.QTYPLANNED),
IT.PROC_GROUP_ID,
IT.PROC_GROUP_DESCR,
IT.SITE_ID,
SI.LOCATION_ID,
SI.QTY_UOM,
PR.PLANNEDDELDATE
FROM ABPPMGR.PROCUREMENTPLAN PR,
IN_ITEM_SITE IT,
IN_SUPPLIER_ITEM SI
WHERE PR.ITEM = IT.ITEM_ID
AND IT.SITE_ID = SUBSTR (PR.RECOMMENDEDSUPID, 1, 4)
AND SI.ITEM_ID = IT.ITEM_ID
AND SI.SUPPLIER_ID = PR.RECOMMENDEDSUPID
AND SI.UDF_ITEM_TYPE_ID = ''
AND (TRUNC (PR.PORELEASEDATE) <= sysdate + DECODE (6, 7, -1, 0)+14)
AND PR.ORDERID LIKE '%PROC%'
AND ( EXISTS
(SELECT NULL
FROM IN_ITEM II
WHERE IT.ITEM_ID = II.ITEM_ID
AND II.FAMILY_ID IN
('',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
))
OR SUBSTR (PR.ITEM, 1, 9) IN ('', ''))
AND ( IT.UDF_IS_JIT = ''
OR EXISTS
(SELECT NULL
FROM TEMP_SDPP SDP
WHERE PR.ITEM = SDP.ITEM
AND ( SDP.supplytype = 'PROC'
OR SDP.supplytype IS NULL)))
--ADD BY HUANGYANGXIONG ON 20160516 增加供应商最小采购批量的限制
AND SUBSTR(PR.RECOMMENDEDSUPID,INSTR(PR.RECOMMENDEDSUPID,'_')+5) NOT IN
( SELECT DISTINCT SUPPLIER_ID FROM SAP_SUPPLIER_MINQTY )
AND PR.ITEM IN ('','','')
GROUP BY PR.ITEM,
SUBSTR (PR.RECOMMENDEDSUPID, 6),
TRUNC (PR.PORELEASEDATE),
IT.PROC_GROUP_ID,
IT.PROC_GROUP_DESCR,
IT.SITE_ID,
SI.LOCATION_ID,
SI.QTY_UOM,
PR.PLANNEDDELDATE;
2、根据最新逻辑更新OUT_PR中的数量
SELECT MIN (
PR.DUE_DATETIME)
OVER (
PARTITION BY PR.ITEM,
PR.SUPPLIER_ID,
PR.SITE_ID,
TRUNC (
(PR.DUE_DATETIME - SYSDATE)
/ DECODE (IT.PR_CONSOLIDATE_DAYS,
0, 1,
IT.PR_CONSOLIDATE_DAYS)))
DUE_DATETIME,
SUM (
PR.QTY)
OVER (
PARTITION BY PR.ITEM,
PR.SUPPLIER_ID,
PR.SITE_ID,
TRUNC (
(PR.DUE_DATETIME - SYSDATE)
/ DECODE (IT.PR_CONSOLIDATE_DAYS,
0, 1,
IT.PR_CONSOLIDATE_DAYS)))
* FP_GET_CONVRATE (tm.item_id,
TM.UDF_MEINS,
--SI.QTY_UOM)
TM.UDF_MEINS)
QTY,
PR.PR_ID,
MIN (
PR.PR_ID)
OVER (
PARTITION BY PR.ITEM,
PR.SUPPLIER_ID,
PR.SITE_ID,
TRUNC (
(PR.DUE_DATETIME - SYSDATE)
/ DECODE (IT.PR_CONSOLIDATE_DAYS,
0, 1,
IT.PR_CONSOLIDATE_DAYS)))
COMBINE_PR,
SI.MIN_LOT_SIZE,
SI.MAX_LOT_SIZE,
DECODE (SI.LOTSIZE_INCREMENT,
0, 1,
SI.LOTSIZE_INCREMENT)
LOTSIZE_INCREMENT,
SI.QTY_UOM QTY_UOM,
PR.ROWID RID,
ROWNUM RN
,MARC.SAFE_QTY ----add by landor on 20180511 PR回写逻辑需要安全库存
FROM OUT_PR PR,
IN_ITEM_SITE IT,
IN_SUPPLIER_ITEM SI,
in_item tm
,SAP_MARC MARC --add by landor on 20180511 PR回写逻辑需要安全库存
WHERE PR.ITEM = tm.ITEM_ID
AND PR.ITEM = IT.ITEM_ID
AND PR.SITE_ID = IT.SITE_ID
AND SI.ITEM_ID = PR.ITEM
AND PR.ITEM = MARC.MATNR AND PR.SITE_ID=MARC.WERKS --add by landor on 20180511 PR回写逻辑需要安全库存
AND SUBSTR (PR.ITEM, 1, 9) NOT IN('','')--ADD BY ZHANGGUIPENG ON 20170408 外购成品不参与数量合并101,401
AND SI.SUPPLIER_ID =
PR.SITE_ID || '_' || PR.SUPPLIER_ID
AND PR.ITEM IN ('','','')
PR回写案例二:
000000701119700498 周批量,最小批量30,舍入值10,安全库存15;
SELECT SAFE_QTY,A.* FROM SAP_MARC A where MATNR='' and WERKS=''; --SAFE_QTY:安全库存
SELECT MIN_LOT_SIZE,LOTSIZE_INCREMENT,A.* FROM IN_SUPPLIER_ITEM A where item_id='' ; -- MIN_LOT_SIZE最小采购批量 LOTSIZE_INCREMENT舍入值
SELECT PR_CONSOLIDATE_DAYS,A.* FROM IN_ITEM_SITE A where item_id='' and SITE_ID=''; --合并下PR的时间区间 WB7 TB1 EX0 W2_14 T3_3
SELECT * FROM TP_TEMP_PR WHERE ITEM='' ; select out_pr.PO_RELEASE_DATE,out_pr.supplier_id,out_pr.site_id,sap_eord.ekorg,out_pr.proc_group_id,out_pr.item,out_pr.qty,out_pr.qtyuom,substr(loc_id,-4) as LGORT
,'SAPRFC' as ERNAM,out_pr.due_datetime,out_pr.so_id,out_pr.so_lineid,out_pr.sobsl
from V_OUT_PR out_pr --其实是select * from tp_temp_pr
join sap_eord on out_pr.item = sap_eord.matnr and out_pr.supplier_id = sap_eord.lifnr and out_pr.site_id = sap_eord.werks
where out_pr.item in ('')
上面两图错误将涂绿色部分PO Release Time进行合并回写给SAP,正确应该按照TIME NEEDED中分三批进行回写去SAP(当然要看最新Arrival时间确定最终回写的时间)。
例如第一笔净需求12.7,安全库存15,最小批量30,舍入值10,应该回写30,而不是45(当天2018.5.8应该只回写一笔30去SAP)
SELECT PR.RECOMMENDEDSUPID,PR.ITEM,TRUNC (PR.PORELEASEDATE),TRUNC(PR.PLANNEDDELDATE), PR.QTYPLANNED
,IT.PR_CONSOLIDATE_DAYS--合并下PR的时间区间即SAP_MARC。DISLS
,IT.PROC_GROUP_ID,IT.PROC_GROUP_DESCR,IT.SITE_ID
,SI.LOCATION_ID,SI.QTY_UOM,IT.UDF_IS_JIT,SUBSTR(PR.RECOMMENDEDSUPID,INSTR(PR.RECOMMENDEDSUPID,'_')+5)
FROM ABPPMGR.PROCUREMENTPLAN PR,
IN_ITEM_SITE IT,
IN_SUPPLIER_ITEM SI
WHERE PR.ITEM = IT.ITEM_ID
AND IT.SITE_ID = SUBSTR (PR.RECOMMENDEDSUPID, 1, 4)
AND SI.ITEM_ID = IT.ITEM_ID
AND SI.SUPPLIER_ID = PR.RECOMMENDEDSUPID
AND SI.UDF_ITEM_TYPE_ID = ''
--AND (TRUNC (PR.PORELEASEDATE) <= V_CurrentDate + DECODE (V_DAY, 7, -1, 0)+V_PDAYS)
AND (TRUNC (PORELEASEDATE) <= sysdate + DECODE (6, 7, -1, 0)+14)
AND PR.ORDERID LIKE '%PROC%' AND SUBSTR(PR.RECOMMENDEDSUPID,INSTR(PR.RECOMMENDEDSUPID,'_')+5) NOT IN
( SELECT DISTINCT SUPPLIER_ID FROM SAP_SUPPLIER_MINQTY )
AND PR.item in ('' ) ;
供给:
PR回写的案例三:
000000104005000047 周批量WB,最小批量1000,舍入值100,安全库存12000
SELECT SAFE_QTY,A.* FROM SAP_MARC A where MATNR='' and WERKS=''; --SAFE_QTY:安全库存
SELECT MIN_LOT_SIZE,LOTSIZE_INCREMENT,A.* FROM IN_SUPPLIER_ITEM A where item_id='' ; -- MIN_LOT_SIZE最小采购批量 LOTSIZE_INCREMENT舍入值
SELECT PR_CONSOLIDATE_DAYS,A.* FROM IN_ITEM_SITE A where item_id='' and SITE_ID=''; --合并下PR的时间区间 WB7 TB1 EX0 W2_14 T3_3
SELECT * FROM TP_TEMP_PR WHERE ITEM='' AND SUPPLIER_ID=''; select out_pr.PO_RELEASE_DATE,out_pr.supplier_id,out_pr.site_id,sap_eord.ekorg,out_pr.proc_group_id,out_pr.item,out_pr.qty,out_pr.qtyuom,substr(loc_id,-4) as LGORT
,'SAPRFC' as ERNAM,out_pr.due_datetime,out_pr.so_id,out_pr.so_lineid,out_pr.sobsl
from V_OUT_PR out_pr --其实是select * from tp_temp_pr
join sap_eord on out_pr.item = sap_eord.matnr and out_pr.supplier_id = sap_eord.lifnr and out_pr.site_id = sap_eord.werks
where out_pr.item in ('')