1.標準的BOM API展開程序是採用插入數據到:BOM_EXPLOSION_TEMP 表,但由於此表是全局臨時表,只對當前的會話有效,只要會話退出,數據馬上被刪除,因此需要建立表來保存BOM物料數據;
腳本如下:
create table BOM_EXPLOSION_TEMP_SAVE as select * from BOM_EXPLOSION_TEMP;
2.寫BOM展開程序如下:
(多級清單BOM的展開)
declare
v_item varchar2(240) := '251200200168'; -- item to explode
v_org varchar2(3) := 'W09'; -- org in which item is exploded
v_cnt NUMBER := 0;
v_err_msg varchar2(240);
v_err_code NUMBER := 0;
v_verify_flag NUMBER := 0; -- DEFAULT 0
v_online_flag NUMBER := 2; -- DEFAULT 0
v_item_id NUMBER := 0; -- set to inventory_item_id of item to explode
v_org_id NUMBER := 0; -- set to organization_id of item to explode
v_alternate VARCHAR2(240) := NULL; -- DEFAULT null
v_list_id NUMBER := 0; -- for reports (default 0)
v_order_by NUMBER := 1; -- DEFAULT 1
v_grp_id NUMBER := 0; --
v_session_id NUMBER := 0; -- DEFAULT 0
v_req_id NUMBER := 0; -- DEFAULT 0
v_prgm_appl_id NUMBER := -1; -- DEFAULT -1
v_prgm_id NUMBER := -1; -- DEFAULT -1
v_levels_to_explode NUMBER := 1; -- DEFAULT 1
v_bom_or_eng NUMBER := 1; -- DEFAULT 1
v_impl_flag NUMBER := 1; -- DEFAULT 1
v_plan_factor_flag NUMBER := 2; -- DEFAULT 2
v_incl_lt_flag NUMBER := 2; -- DEFAULT 2
v_explode_option NUMBER := 2; -- DEFAULT 2
v_module NUMBER := 2; -- DEFAULT 2
v_cst_type_id NUMBER := 0; -- DEFAULT 0
v_std_comp_flag NUMBER := 0; -- DEFAULT 0
v_rev_date VARCHAR2(240); --
v_comp_code VARCHAR2(240) := NULL; --
v_expl_qty NUMBER := 1; -- DEFAULT 1
begin
-- item revision will be based on this explode date.
-- In this example, we use current date/time
v_rev_date := to_char(SYSDATE);
-- Find org_id
select mp.organization_id into v_org_id
from MTL_PARAMETERS mp
where mp.organization_code = v_org;
-- Find item_id
select inventory_item_id into v_item_id
from MTL_ITEM_FLEXFIELDS
where organization_id = v_org_id and item_number = v_item;
-- v_grp_id is a unique identifier for this run of the exploder
select bom_explosion_temp_s.nextval into v_grp_id from dual;
-- determine maximum levels to explode from bom_explosions
--這裏是多級BOM展開,包括BOM頭的信息也存在
select maximum_bom_level into v_levels_to_explode
from bom_parameters where organization_id = v_org_id;
--可以設置 v_levels_to_explode=1;
apps.bompexpl.exploder_userexit (
v_verify_flag,
v_org_id,
v_order_by,
v_grp_id,
v_session_id,
v_levels_to_explode,
v_bom_or_eng,
v_impl_flag,
v_plan_factor_flag,
v_explode_option,
v_module,
v_cst_type_id,
v_std_comp_flag,
v_expl_qty,
v_item_id,
v_alternate,
v_comp_code,
v_rev_date,
v_err_msg,
v_err_code);
if ( v_err_code <> 0 ) then
rollback;
dbms_output.put_line('ERROR: ' || v_err_msg);
else
select count(*) into v_cnt from bom_explosion_temp where group_id=v_grp_id;
dbms_output.put_line('Count=' || v_cnt);
commit;
dbms_output.put_line('.');
dbms_output.put_line('Group Id=' || v_grp_id);
dbms_output.put_line('Org =' || v_org);
dbms_output.put_line('Item =' || v_item);
dbms_output.put_line('Ord Id =' || v_org_id);
dbms_output.put_line('Item Id=' || v_item_id);
dbms_output.put_line('Levels =' || v_levels_to_explode);
end if;
end;
/
3.插入到自己創建的臨時表中:
insert into BOM_EXPLOSION_TEMP_SAVE select * from BOM_EXPLOSION_TEMP;
commit;
4.推出會話,查看臨時表;
//////////////////////////////////////////////////////////////////
SELECT distinct
bb.BOM層次,
bb.裝配件,
bb.裝配件說明,
bb.組件序號,
bb.組件,
bb.組件說明,
bb.組件用量,
bb.單位,
bb.利用率,
bb.衝減庫房,
bb.衝減貨位,
bb.屬性,
bb.BOM創建時間,
BOR.COMPLETION_SUBINVENTORY 入庫,
MSI.WIP_SUPPLY_SUBINVENTORY 衝減,
MSI.MAXIMUM_ORDER_QUANTITY 最大批量,
MSI.LEAD_TIME_LOT_SIZE 提前期,
MSI.FULL_LEAD_TIME 製造週期,
MSI.FIXED_LOT_MULTIPLIER 固定增加,
MSI.MINIMUM_ORDER_QUANTITY 最小批量,
MSI.FIXED_ORDER_QUANTITY 固定定貨量,
MSI.FIXED_DAYS_SUPPLY 固定天數,
MSI.PLANNER_CODE 計劃員
FROM MTL_SYSTEM_ITEMS MSI,
BOM_OPERATIONAL_ROUTINGS BOR,
BOM_OPERATION_SEQUENCES BOS,
(select distinct
aa.lvl BOM層次,
msi.segment1 裝配件,
msi.description 裝配件說明,
aa.item_num 組件序號,
msi1.segment1 組件,
msi1.description 組件說明,
aa.component_quantity 組件用量,
msi1.primary_unit_of_measure 單位,
aa.COMPONENT_YIELD_FACTOR 利用率,
msi1.wip_supply_subinventory 衝減庫房,
mil.segment1 || '.' || mil.segment2 || '.' || mil.segment3 || '.' ||
mil.segment4 衝減貨位,
decode(msi1.planning_make_buy_code,1,'製造',2,'採購') 屬性,
to_char(msi1.creation_date,'yyyy.mm.dd hh24:mm.ss') BOM創建時間,
msi1.inventory_item_id
from mtl_system_items_b msi,
mtl_system_items_b msi1,
bom_bill_of_materials bom,
bom_inventory_components bic,
mtl_item_locations mil,
(
select level lvl,
bic.bill_sequence_id,
bic.component_item_id,
bic.component_quantity,
bic.OPERATION_SEQ_NUM,
bic.COMPONENT_YIELD_FACTOR,
bic.COMPONENT_SEQUENCE_ID,
bic.item_num,
bic.wip_supply_type,
bic.supply_subinventory,
bic.effectivity_date
FROM bom_inventory_components bic
where disable_date IS NULL
start with bic.bill_sequence_id in
(select bill_sequence_id
from bom_bill_of_materials bom2,
inv.mtl_system_items_b msi
where bom2.assembly_item_id = msi.inventory_item_id
and bom2.organization_id = msi.organization_id
---------------------------------------輸入要查詢的項目---------------------------------------------
and msi.segment1 =&ITEM_NUMBER
---------------------------------------輸入要查詢的項目---------------------------------------------
and msi.organization_id = &組織ID
and bom2.alternate_bom_designator is null)
CONNECT BY bic.bill_sequence_id in prior
(SELECT distinct bill_sequence_id
FROM bom_bill_of_materials BO, inv.mtl_system_items_b msi
WHERE BO.assembly_item_id = bic.component_item_id
AND BO.organization_id = &組織ID
and bo.ORGANIZATION_ID = msi.ORGANIZATION_ID
and bo.ASSEMBLY_ITEM_ID = msi.INVENTORY_ITEM_ID
and bo.alternate_bom_designator is null
and disable_date IS NULL)) aa
where msi.organization_id=&組織ID
and msi1.organization_id=&組織ID
and bom.organization_id=&組織ID
and msi.inventory_item_id=bom.assembly_item_id
and bom.bill_sequence_id=bic.bill_sequence_id
and bic.component_item_id=msi1.inventory_item_id
and bic.disable_date is null
and aa.bill_sequence_id=bic.bill_sequence_id
and aa.component_item_id=msi1.inventory_item_id
and mil.inventory_location_id(+)=msi1.wip_supply_locator_id
and mil.organization_id(+)=&組織ID
order by
aa.lvl,
aa.item_num) bb
WHERE BOR.ASSEMBLY_ITEM_ID(+) = MSI.INVENTORY_ITEM_ID
AND BOS.ROUTING_SEQUENCE_ID(+) = BOR.ROUTING_SEQUENCE_ID
AND MSI.ORGANIZATION_ID(+) = &組織ID
and bor.alternate_routing_designator is null
and bb.inventory_item_id=msi.inventory_item_id
order by
bb.BOM層次,
bb.裝配件,
bb.裝配件說明,
bb.組件序號,
bb.組件
//////////////////////////////////////////////////////////////
多組織的展開
select rownum seq_num
,top_item
,top_org
,lpad(to_char(level),decode(level,1,1,level+1),'.') bom_level
,bbm.ASSEMBLY_ITEM_ID
,msi.segment1 assembly_item
,msi.description assembly_description
,bbm.COMMON_ASSEMBLY_ITEM_ID
,bic.item_NUM
,bbm.COMMON_BILL_SEQUENCE_ID
,bbm.BILL_SEQUENCE_ID
,msic.segment1 component_item
,msic.description c_item_description
,bic.COMPONENT_ITEM_ID
,bic.COMPONENT_QUANTITY
,msic.primary_unit_of_measure
,bic.COMPONENT_YIELD_FACTOR
,bic.EFFECTIVITY_DATE
,bic.ATTRIBUTE1
,bic.ATTRIBUTE2
,bic.CHANGE_NOTICE
,ood.ORGANIZATION_CODE
,ood.ORGANIZATION_NAME
,bbm.ORGANIZATION_ID
,bbm.COMMON_ORGANIZATION_ID
from bom_bill_of_materials bbm
,bom_inventory_components bic
,mtl_system_items_b msi
,mtl_system_items_b msic
,org_organization_definitions ood
where
bbm.ASSEMBLY_ITEM_ID = msi.inventory_item_id
and bbm.ORGANIZATION_ID = msi.organization_id
and bic.COMPONENT_ITEM_ID =msic.inventory_item_id
--and bic.PK2_VALUE =msic.organization_id
and bbm.ORGANIZATION_ID =msic.organization_id
--and bbm.BILL_SEQUENCE_ID=bic.BILL_SEQUENCE_ID
and decode(bbm.COMMON_ASSEMBLY_ITEM_ID,null,bbm.BILL_SEQUENCE_ID,bbm.COMMON_BILL_SEQUENCE_ID)=bic.BILL_SEQUENCE_ID
and (bic.DISABLE_DATE is null or bic.DISABLE_DATE >= sysdate)
and bic.EFFECTIVITY_DATE <= sysdate
and ood.ORGANIZATION_ID=msi.organization_id
connect by bbm.ASSEMBLY_ITEM_ID = prior bic.COMPONENT_ITEM_ID
and bbm.ORGANIZATION_ID = decode (prior bbm.COMMON_ORGANIZATION_ID, null, prior bbm.ORGANIZATION_ID, prior bbm.COMMON_ORGANIZATION_ID)
start with msi.segment1=:P_ITEM
and ood.ORGANIZATION_CODE =:P_ORG