注册 登录
壹佰网|ERP100 - 企业信息化知识门户 返回首页

的个人空间 https://www.erp100.com/?0 [收藏] [复制] [RSS]

日志

BOM 子物料查找所有父物料及它的顶级产品

已有 657 次阅读2008/10/17 08:56

   在网上没有找到这样的应用,今天因需要写了下面的程序,主要是查找物料的上级BOM,及它所要应用到的所有产品,网上一般都是从上面找下去,而没有通过物料去查找它的顶级产品,通过这段PL/SQL,可以方便地让你找到物料应用到了哪些产品中!望各位支持一下!
 
--新建一个表,将结果插入到表里面 
create table CUX_BOM_ID (KINDID number(20),kindname varchar(200),FATHERID number(20),ITEMD number(20))
--新建一个存储过程,并将执行结果放入到CUX_BOM_ID里面
CREATE OR REPLACE procedure CUX_BOM is
  cursor emp_cursor is select segment1
  from (select mtl.segment1, mtl.description
          from bom_bill_of_materials a, MTL_SYSTEM_ITEMS_B mtl
         where a.ASSEMBLY_ITEM_ID = mtl.inventory_item_id
           and a.ORGANIZATION_ID = mtl.organization_id
           and mtl.organization_id = 101
          ) a
 where not exists
 (select *
          from (select mtl2.segment1, mtl2.description
                  from bom_inventory_components bom, MTL_SYSTEM_ITEMS_B mtl2
                 where bom.COMPONENT_ITEM_ID = mtl2.inventory_item_id
                   and mtl2.organization_id = 101
                   ) b where  a.segment1 = b.segment1) and rownum<15;
begin
  FOR emp_record in EMP_CURSOR loop
   insert into cux_bom_id select kindid,
       lpad('|---', (level - 1) * 4, ' ') || lpad('『', 2) || kindname ||
       rpad('』', 2) kindname,fatherid,emp_record.segment1 id
    from
  (select mtl.segment1 kindid,mtl.description kindname,mtl2.segment1 fatherid
  from bom_bill_of_materials a,
       bom_inventory_components b,
        MTL_SYSTEM_ITEMS_B mtl,
        MTL_SYSTEM_ITEMS_B mtl2
 where a.bill_sequence_id = b.BILL_SEQUENCE_ID
   and mtl.inventory_item_id=b.COMPONENT_ITEM_ID
   and a.ASSEMBLY_ITEM_ID=mtl2.inventory_item_id
   and mtl.organization_id=101
   and mtl2.organization_id=101
   and a.ORGANIZATION_ID=101
   and mtl.invoice_enabled_flag='Y'
   and mtl.organization_id=a.ORGANIZATION_ID
    )
   CONNECT BY PRIOR kindid = fatherid
  START WITH fatherid = emp_record.segment1
    order by kindid desc;
      commit;
  end loop;
  end;
--执行存储过程CUX_BOM
BEGIN
CUX_BOM;
END;
--查询即可运行得到的结果
SELECT * FROM CUX_BOM_ID;

评论 (0 个评论)

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/30 01:47 , Processed in 0.007710 second(s), 12 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

返回顶部