根據API創建BOM

--根據API創建BOM
--
/*******************************************************************************
*創建:COOLER LEE 2006-1-11 16:09
*目的:該PROCEDURE用於中轉對標準創建BOM的API調用。每次調用創建一個BOM
*參數:l_bom_header_rec,BOM頭的信息
* l_bom_component_tbl BOM組件的相關信息
* x_return_status 返回值,處理結果,成功爲'S',失敗爲'E',警告爲'W'
* x_msg_count 返回值,處理過程中的信息條數,可用代碼爲中示例來取信息。 
*
*注意事項及用法:

賦值例子:
--BOM頭 
l_bom_header_rec := bom_bo_pub.g_miss_bom_header_rec;
l_bom_header_rec.transaction_type := 'CREATE';
-- l_bom_header_rec.Common_Assembly_Item_Name:=;
l_bom_header_rec.assembly_item_name := 'B';
l_bom_header_rec.organization_code := 'ITM';
l_bom_header_rec.assembly_type := 1;
-- l_bom_header_rec.Original_System_Reference:='';

--BOM行
l_bom_component_tbl(1) := bom_bo_pub.g_miss_bom_component_rec;
l_bom_component_tbl(1).transaction_type := 'CREATE';
l_bom_component_tbl(1).assembly_item_name := 'B';
l_bom_component_tbl(1).component_item_name := 'C';
l_bom_component_tbl(1).start_effective_date := SYSDATE;
l_bom_component_tbl(1).organization_code := 'ITM';
l_bom_component_tbl(1).operation_sequence_number := 1;
l_bom_component_tbl(1).item_sequence_number := 10;
l_bom_component_tbl(1).optional := 1; --選項類
l_bom_component_tbl(1).so_basis := 2; --無基準
l_bom_component_tbl(1).wip_supply_type := 1;
l_bom_component_tbl(1).quantity_per_assembly := 1;
*
* 3.在創建ATO模型時,需先創建可選件(AOC)的BOM,最後創建ATO模型.
********************************************************************************/

PROCEDURE create_bom(l_bom_header_rec IN bom_bo_pub.bom_head_rec_type,
l_bom_component_tbl IN bom_bo_pub.bom_comps_tbl_type,
x_return_status IN OUT VARCHAR2,
x_msg_data OUT VARCHAR2,
x_msg_count IN OUT NUMBER) IS

--OUT VARIBLE
x_bom_header_rec bom_bo_pub.bom_head_rec_type;
x_bom_revision_tbl bom_bo_pub.bom_revision_tbl_type;
x_bom_component_tbl bom_bo_pub.bom_comps_tbl_type;
x_bom_ref_designator_tbl bom_bo_pub.bom_ref_designator_tbl_type;
x_bom_sub_component_tbl bom_bo_pub.bom_sub_component_tbl_type;

/* x_return_status VARCHAR2(1);
x_msg_count NUMBER;
*/
BEGIN
--初始化,單獨在PL/SQL中測試時需要
/**********************************************
fnd_global.apps_initialize(8949, 50186, 702);
***********************************************/
error_handler.initialize;
x_return_status := NULL;

bom_bo_pub.process_bom(p_bom_header_rec => l_bom_header_rec,
p_init_msg_list => TRUE,
p_bom_component_tbl => l_bom_component_tbl,
x_bom_header_rec => x_bom_header_rec,
x_bom_revision_tbl => x_bom_revision_tbl,
x_bom_component_tbl => x_bom_component_tbl,
x_bom_ref_designator_tbl => x_bom_ref_designator_tbl,
x_bom_sub_component_tbl => x_bom_sub_component_tbl,
x_return_status => x_return_status,
x_msg_count => x_msg_count);
/*,
--p_debug => 'Y',
--p_output_dir => '/usr/tmp',
--p_debug_filename => 'BOM_XGL_009.log'*/

IF x_msg_count > 0 THEN
FOR l_index IN 1 .. x_msg_count LOOP

DECLARE
x_index VARCHAR2(10);
x_msg_data_tmp VARCHAR2(2000);
x_entity_id VARCHAR2(10);
x_message_type VARCHAR2(10);
BEGIN
error_handler.get_message(x_entity_index => x_index,
x_message_text => x_msg_data_tmp,
x_entity_id => x_entity_id,
x_message_type => x_message_type);
dbms_output.put_line(l_index);
x_msg_data := x_msg_data || x_msg_data_tmp;

FOR i IN 1 .. round(length(x_msg_data_tmp) / 255) + 1 LOOP
dbms_output.put_line(substr(x_msg_data_tmp, (i - 1) * 254, 254));
END LOOP;
END;

END LOOP;

END IF;

-- 執行後的信息顯示,如果是在PL/SQL中測試需要下段
/**********************************************************************
IF x_msg_count > 0 THEN
FOR l_index IN 1 .. x_msg_count LOOP

DECLARE
x_index VARCHAR2(10);
x_msg_data VARCHAR2(2000);
x_entity_id VARCHAR2(10);
x_message_type VARCHAR2(10);
BEGIN
error_handler.get_message(x_entity_index => x_index,
x_message_text => x_msg_data,
x_entity_id => x_entity_id,
x_message_type => x_message_type);
dbms_output.put_line(l_index);
FOR i IN 1 .. round(length(x_msg_data) / 255) + 1 LOOP
dbms_output.put_line(substr(x_msg_data, (i - 1) * 254, 254));
END LOOP;
END;

END LOOP;

END IF;
-- Check the return status
IF x_return_status = fnd_api.g_ret_sts_success THEN

dbms_output.put_line('創建BOM成功!');
--success;
COMMIT;
ELSE
-- failure;
ROLLBACK;
END IF;
**********************************************************************/

END create_bom;

--
--根據API爆開已創建的BOM
--
/*******************************************************************************
*創建:COOLER LEE 2006-1-11 16:09
*目的:該PROCEDURE用於將新創建的BOM展開到BOM_EXPLOSIONS表。每次調用展開一個多級清單
*參數:p_top_assembly_item_id,BOM中最頂層的inventory_item_id
* p_org_id 組織,如不輸入,則取項目主組織
* x_err_msg 返回值,處理結果,存放出錯信息,成功時爲NULL
* x_err_code 返回值,存放出錯代碼,成功時爲NULL
*
*注意事項及用法:
* 1.該過程一次可以處理整個BOM(最多20層)
* 2.對於ATO模型,必須在插入行到訂單之前將ATO模型展開
********************************************************************************/

PROCEDURE exploder_bom(p_top_assembly_item_id NUMBER,
p_org_id NUMBER DEFAULT 2,
x_err_msg IN OUT VARCHAR2,
x_err_code IN OUT NUMBER) IS
v_user_id NUMBER;
BEGIN

v_user_id := nvl(fnd_global.user_id, 0);

bom_oe_exploder_pkg.be_exploder(arg_org_id => p_org_id,
arg_starting_rev_date => SYSDATE,
arg_item_id => p_top_assembly_item_id,
arg_comp_code => '-',
arg_user_id => v_user_id,
arg_err_msg => x_err_msg,
arg_error_code => x_err_code);

-- 執行後的信息顯示,如果是在PL/SQL中測試需要下段
/**********************************************************************
IF err_msg IS NOT NULL THEN
dbms_output.put_line(err_code || ':' || err_msg);
ELSE
dbms_output.put_line('成功爆開BOM');
END IF;
**********************************************************************/

END exploder_bom
發佈了7 篇原創文章 · 獲贊 9 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章