描述:当主料中有损耗时,替料却占了主料损耗比例进行回写数量造成规划异常。
下图:BOM中主料的损耗为0.02,替料损耗为0
下图却显示替料占了2%的损耗
方二:進mst_BOMCOMPONENTSALT時把QTYPER扣減損耗
方一:可以修改IN_BOM_DETAIL数据
如果替料有损耗的话,替料的IN_BOM_DETAIL.USAGE_QTY=主料用量/(1+0.02)*(1+替料的损耗比例)
如果替料无损耗的话,替料的IN_BOM_DETAIL.USAGE_QTY=主料用量/(1+0.02)
SELECT BOM_ID,ITEM_ID,COMPONENTGROUP,COMPONENT_YIELD_UOM,PRIORITY ,USAGE_QTY FROM IN_BOM_DETAILS WHERE (BOM_ID LIKE '00280869_2023_01%' AND COMPONENTGROUP='01') OR (BOM_ID LIKE '00119055_2022_01%' AND COMPONENTGROUP='23') order by BOM_ID,COMPONENTGROUP,priority;
方案一:改代码如下 修改SAP_BOM_DETAILS存储过程 ,修改后不生效,此方法作废
TRUNCATE TABLE TB_BOM_COMPONENTGROUP_NOYIELD; TRUNCATE TABLE TB_BOM_COMPONENTGROUP_HASYIELD; INSERT INTO TB_BOM_COMPONENTGROUP_NOYIELD SELECT A.BOM_ID,A.COMPONENTGROUP,A.ITEM_ID, A.PRIORITY,C.PRIORITY PRIORITY2,C.USAGE_QTY,A.USAGE_QTY/(1+A.COMPONENT_YIELD_UOM) ,SYSDATE FROM IN_BOM_DETAILS A, IN_BOM_DETAILS C WHERE A.BOM_ID=C.BOM_ID AND A.COMPONENTGROUP=C.COMPONENTGROUP AND A.USAGE_QTY_UOM=C.USAGE_QTY_UOM and A.PRIORITY=1 --1代表主料,大于1代表替料 and C.PRIORITY>1 AND C.COMPONENT_YIELD_UOM=0 --替料损耗为0; AND C.USAGE_QTY_UOM!='G'AND C.USAGE_QTY_UOM!='KG' order by A.BOM_ID,A.COMPONENTGROUP; COMMIT; INSERT INTO TB_BOM_COMPONENTGROUP_HASYIELD SELECT A.BOM_ID,A.COMPONENTGROUP,A.ITEM_ID, A.PRIORITY,C.PRIORITY PRIORITY2,C.USAGE_QTY,A.USAGE_QTY/(1+A.COMPONENT_YIELD_UOM) ,SYSDATE FROM IN_BOM_DETAILS A, IN_BOM_DETAILS C WHERE A.BOM_ID=C.BOM_ID AND A.COMPONENTGROUP=C.COMPONENTGROUP AND A.USAGE_QTY_UOM=C.USAGE_QTY_UOM and A.PRIORITY=1 --1代表主料,大于1代表替料 and C.PRIORITY>1 AND C.COMPONENT_YIELD_UOM>0 --替料有损耗; AND C.USAGE_QTY_UOM!='G'AND C.USAGE_QTY_UOM!='KG' order by A.BOM_ID,A.COMPONENTGROUP; COMMIT; --如果替料无损耗的话,替料的IN_BOM_DETAIL.USAGE_QTY=主料用量/(1+0.02) UPDATE IN_BOM_DETAILS C SET C.USAGE_QTY= (SELECT A.USAGE_QTY/(1+A.COMPONENT_YIELD_UOM)--BOM_ID,ITEM_ID,USAGE_QTY,COMPONENT_YIELD_UOM,PRIORITY FROM IN_BOM_DETAILS A WHERE A.PRIORITY=1 --1代表主料,大于1代表替料 --AND A.BOM_ID LIKE '00280869_2023_01%' AND A.COMPONENTGROUP='01' AND A.BOM_ID=C.BOM_ID AND A.COMPONENTGROUP=C.COMPONENTGROUP AND A.USAGE_QTY_UOM=C.USAGE_QTY_UOM -- AND A.USAGE_QTY_UOM!='G'AND A.USAGE_QTY_UOM!='KG'--除碳粉外 ) WHERE C.PRIORITY>1 --只更新替料 AND C.COMPONENT_YIELD_UOM=0 --替料损耗为0; AND C.USAGE_QTY_UOM!='G'AND C.USAGE_QTY_UOM!='KG'--除碳粉外 AND NOT EXISTS (SELECT NULL FROM TB_BOM_COMPONENTGROUP_NOYIELD X WHERE X.BOM_ID = C.BOM_ID AND X.COMPONENTGROUP = C.COMPONENTGROUP) ---BOM 主替料中优化级序号维护异常,需过滤掉 --AND C.BOM_ID LIKE '00197652_2023_01%' AND C.COMPONENTGROUP='03' ; COMMIT; --如果替料有损耗的话,替料的IN_BOM_DETAIL.USAGE_QTY=主料用量/(1+0.02)*(1+替料的损耗比例) UPDATE IN_BOM_DETAILS C SET C.USAGE_QTY= (SELECT A.USAGE_QTY/(1+A.COMPONENT_YIELD_UOM)*(1+C.COMPONENT_YIELD_UOM)--BOM_ID,ITEM_ID,USAGE_QTY,COMPONENT_YIELD_UOM,PRIORITY FROM IN_BOM_DETAILS A WHERE A.PRIORITY=1 --1代表主料,大于1代表替料 AND A.BOM_ID=C.BOM_ID AND A.COMPONENTGROUP=C.COMPONENTGROUP AND A.USAGE_QTY_UOM=C.USAGE_QTY_UOM ) WHERE C.PRIORITY>1 --只更新替料 AND C.COMPONENT_YIELD_UOM>0 --替料有损耗; AND C.USAGE_QTY_UOM!='G'AND C.USAGE_QTY_UOM!='KG'--除碳粉外 AND NOT EXISTS (SELECT NULL FROM TB_BOM_COMPONENTGROUP_HASYIELD X WHERE X.BOM_ID = C.BOM_ID AND X.COMPONENTGROUP = C.COMPONENTGROUP) ---BOM 主替料中优化级序号维护异常,需过滤掉 ; COMMIT;
方法二:修改IN2ODS中的存储过程FP_BOM
--有3条数据 SELECT * FROM ABPPMGR.MST_BOMCOMPONENTSALT WHERE BOMID LIKE '%00204661_2023_01%' and COMPONENTGROUP='13'; ----有2条数据 SELECT A.BOM_ID,A.COMPONENTGROUP,A.PRIORITY,A.ITEM_ID,C.PRIORITY PRIORITY2,C.ITEM_ID ITEM_IDTL ,A.COMPONENT_YIELD_UOM,A.USAGE_QTY,C.USAGE_QTY USAGE_QTYTL,SYSDATE FROM IN_BOM_DETAILS A, IN_BOM_DETAILS C WHERE A.BOM_ID=C.BOM_ID AND A.COMPONENTGROUP=C.COMPONENTGROUP AND A.USAGE_QTY_UOM=C.USAGE_QTY_UOM and A.PRIORITY=1 --1代表主料,大于1代表替料 AND A.COMPONENT_YIELD_UOM>0 --大于0代表主料有损耗 and C.PRIORITY>1 --大于1为替料 AND C.COMPONENT_YIELD_UOM=0 --替料损耗为0 AND C.USAGE_QTY_UOM!='G'AND C.USAGE_QTY_UOM!='KG' AND A.BOM_ID LIKE '00204661_2023_01%' order by A.BOM_ID,A.COMPONENTGROUP;
--如果替料无损耗的话,替料的=主料用量/(1+0.02) --错误做法 UPDATE ABPPMGR.MST_BOMCOMPONENTSALT M SET M.QTYPER= (SELECT M.QTYPER/(1+A.COMPONENT_YIELD_UOM)--A.USAGE_QTY/(1+A.COMPONENT_YIELD_UOM)需要修改 FROM IN_BOM_DETAILS A, IN_BOM_DETAILS C WHERE A.BOM_ID=C.BOM_ID AND A.COMPONENTGROUP=C.COMPONENTGROUP AND A.USAGE_QTY_UOM=C.USAGE_QTY_UOM and A.PRIORITY=1 --1代表主料,大于1代表替料 AND A.COMPONENT_YIELD_UOM>0 --大于0代表主料有损耗 and C.PRIORITY>1 --大于1为替料 AND C.COMPONENT_YIELD_UOM=0 --替料损耗为0 AND C.USAGE_QTY_UOM!='G'AND C.USAGE_QTY_UOM!='KG' ----除碳粉外 AND A.BOM_ID LIKE '00204661_2023_01%' AND TRIM(A.BOM_ID)=Substr(M.BOMID,length(M.BOMID)-15,16) AND A.COMPONENTGROUP=M.COMPONENTGROUP AND M.ALTERNATEITEM=C.ITEM_ID ) ; COMMIT; --正确做法 MERGE INTO ABPPMGR.MST_BOMCOMPONENTSALT M USING(SELECT A.BOM_ID ,A.COMPONENTGROUP,A.COMPONENT_YIELD_UOM ,A.USAGE_QTY,C.ITEM_ID FROM IN_BOM_DETAILS A, IN_BOM_DETAILS C WHERE A.BOM_ID=C.BOM_ID AND A.COMPONENTGROUP=C.COMPONENTGROUP AND A.USAGE_QTY_UOM=C.USAGE_QTY_UOM and A.PRIORITY=1 --1代表主料,大于1代表替料 AND A.COMPONENT_YIELD_UOM>0 --大于0代表主料有损耗 and C.PRIORITY>1 --大于1为替料 AND C.COMPONENT_YIELD_UOM=0 --替料损耗为0 AND C.USAGE_QTY_UOM!='G'AND C.USAGE_QTY_UOM!='KG' ----除碳粉外 AND A.BOM_ID LIKE '00204661_2023_01%' )K ON (TRIM(K.BOM_ID)=Substr(M.BOMID,length(M.BOMID)-15,16) AND K.COMPONENTGROUP=M.COMPONENTGROUP AND K.ITEM_ID=M.ALTERNATEITEM) WHEN MATCHED THEN UPDATE SET M.QTYPER= M.QTYPER/(1+K.COMPONENT_YIELD_UOM) WHERE M.BOMID LIKE '%00204661_2023_01%' ; COMMIT;
TRUNCATE TABLE TB_BOM_COMPONENTGROUP_HASYIELD; INSERT INTO TB_BOM_COMPONENTGROUP_HASYIELD SELECT A.BOM_ID,A.COMPONENTGROUP,A.ITEM_ID, A.PRIORITY,C.PRIORITY PRIORITY2,C.USAGE_QTY,A.USAGE_QTY/(1+A.COMPONENT_YIELD_UOM) ,SYSDATE FROM IN_BOM_DETAILS A, IN_BOM_DETAILS C WHERE A.BOM_ID=C.BOM_ID AND A.COMPONENTGROUP=C.COMPONENTGROUP AND A.USAGE_QTY_UOM=C.USAGE_QTY_UOM and A.PRIORITY=1 --1代表主料,大于1代表替料 and C.PRIORITY>1 AND C.COMPONENT_YIELD_UOM>0 --替料有损耗; AND C.USAGE_QTY_UOM!='G'AND C.USAGE_QTY_UOM!='KG' order by A.BOM_ID,A.COMPONENTGROUP; COMMIT; --如果替料有损耗的话,替料的IN_BOM_DETAIL.USAGE_QTY=主料用量/(1+0.02)*(1+替料的损耗比例) UPDATE ABPPMGR.MST_BOMCOMPONENTSALT M SET M.QTYPER= (SELECT A.USAGE_QTY/(1+A.COMPONENT_YIELD_UOM)*(1+C.COMPONENT_YIELD_UOM)--此处需要修改 FROM IN_BOM_DETAILS A, IN_BOM_DETAILS C WHERE A.BOM_ID=C.BOM_ID AND A.COMPONENTGROUP=C.COMPONENTGROUP AND A.USAGE_QTY_UOM=C.USAGE_QTY_UOM and A.PRIORITY=1 --1代表主料,大于1代表替料 and C.PRIORITY>1 --大于1为替料 AND C.COMPONENT_YIELD_UOM>0 ----替料有损耗; AND C.USAGE_QTY_UOM!='G'AND C.USAGE_QTY_UOM!='KG' ----除碳粉外 AND NOT EXISTS (SELECT NULL FROM TB_BOM_COMPONENTGROUP_HASYIELD X WHERE X.BOM_ID = C.BOM_ID AND X.COMPONENTGROUP = C.COMPONENTGROUP) ---BOM 主替料中优化级序号维护异常,需过滤掉 -- AND A.BOM_ID LIKE '00275576_2023_01%' AND TRIM(A.BOM_ID)=Substr(M.BOMID,length(M.BOMID)-15,16) AND A.COMPONENTGROUP=M.COMPONENTGROUP ) ; COMMIT;
验证数据如下:
SELECT * FROM ABPPMGR.MST_BOMCOMPONENTSALT WHERE BOMID LIKE '%00204661_2023_01%' and COMPONENTGROUP='13';