我正在通过API创建一个Move Order,但我遇到的问题是它没有将Line Items作为bash处理,而是单独执行每个。我尝试从循环中删除Header,但结果仍然存在。提前谢谢你。
create or replace PROCEDURE XXGSC_CREATE_MO
as
x_return_status VARCHAR2 (1);
x_msg_data VARCHAR2 (4000);
x_msg_count NUMBER;
l_user_id NUMBER;
l_resp_id NUMBER;
l_appl_id NUMBER;
l_hdr_rec inv_move_order_pub.trohdr_rec_type := inv_move_order_pub.g_miss_trohdr_rec;
x_hdr_rec inv_move_order_pub.trohdr_rec_type := inv_move_order_pub.g_miss_trohdr_rec;
l_line_tbl inv_move_order_pub.trolin_tbl_type:= inv_move_order_pub.g_miss_trolin_tbl;
x_line_tbl inv_move_order_pub.trolin_tbl_type:= inv_move_order_pub.g_miss_trolin_tbl;
x_hdr_val_rec inv_move_order_pub.trohdr_val_rec_type;
x_line_val_tbl inv_move_order_pub.trolin_val_tbl_type;
v_msg_index_out NUMBER;
l_cnt number := 0;
l_rsr_type inv_reservation_global.mtl_reservation_tbl_type;
l_code_combination_id gl_code_combinations.code_combination_id%type;
CURSOR c_itm_onhand
IS
select msi.inventory_item_id, msi.organization_id, sum (mmt.transaction_quantity) as qty, mmt.subinventory_code, transaction_uom, '1203' as ccid
from mtl_material_transactions mmt
join mtl_system_items_b msi
on mmt.organization_id = msi.organization_id and mmt.inventory_item_id = msi.inventory_item_id
where segment1 like '1010027%'
and msi.organization_id = 102
group by msi.inventory_item_id, msi.organization_id, mmt.subinventory_code, transaction_uom, '1203';
BEGIN
SELECT user_id INTO l_user_id FROM fnd_user WHERE user_name = 'CONCSYS';
SELECT fr.responsibility_id,
fr.application_id
INTO l_resp_id,
l_appl_id
FROM fnd_responsibility fr,
fnd_responsibility_tl frt
WHERE fr.responsibility_id = frt.responsibility_id
AND frt.responsibility_name = 'ISD-Inventory Super User'; --Responsibility
fnd_global.apps_initialize (l_user_id, l_resp_id, l_appl_id);
DBMS_OUTPUT.put_line ('Creating MO');
FOR i IN c_itm_onhand
LOOP
l_cnt := l_cnt + 1;
mo_global.set_policy_context ('S', i.organization_id);
inv_globals.set_org_id (i.organization_id);
mo_global.init ('INV');
--SELECT code_combination_id
--INTO l_code_combination_id
--FROM gl_code_combinations_kfv
--WHERE concatenated_segments = '01-520-5250-0000-000';
l_line_tbl.DELETE;
x_line_tbl.DELETE;
--Header
l_hdr_rec.date_required := SYSDATE;
l_hdr_rec.header_status := inv_globals.g_to_status_preapproved;
l_hdr_rec.organization_id := 102;
l_hdr_rec.status_date := SYSDATE;
l_hdr_rec.transaction_type_id := inv_globals.g_type_transfer_order_issue; --Type:Move Order Issue
l_hdr_rec.move_order_type := inv_globals.g_move_order_requisition;
l_hdr_rec.db_flag := fnd_api.g_true;
l_hdr_rec.operation := inv_globals.g_opr_create;
l_hdr_rec.description := 'Test MO5';
--l_hdr_rec.to_account_id := i.ccid;
--l_hdr_rec.from_subinventory_code := i.subinventory_code;
--Table Lines
l_line_tbl (l_cnt).date_required := SYSDATE;
l_line_tbl (l_cnt).inventory_item_id := i.inventory_item_id;
l_line_tbl (l_cnt).line_id := fnd_api.g_miss_num;
--l_line_tbl (l_cnt).line_number := l_cnt;
l_line_tbl (l_cnt).line_status := inv_globals.g_to_status_preapproved;
l_line_tbl (l_cnt).transaction_type_id := inv_globals.g_type_transfer_order_issue;
l_line_tbl (l_cnt).organization_id := i.organization_id;
l_line_tbl (l_cnt).quantity := i.qty;
l_line_tbl (l_cnt).status_date := SYSDATE;
l_line_tbl (l_cnt).uom_code := i.transaction_uom;
l_line_tbl (l_cnt).db_flag := fnd_api.g_true;
l_line_tbl (l_cnt).operation := inv_globals.g_opr_create;
l_line_tbl (l_cnt).from_subinventory_code := i.subinventory_code;
l_line_tbl (l_cnt).to_account_id := i.ccid;
--l_line_tbl (l_cnt).lot_number := i.lot_number;
DBMS_OUTPUT.put_line ('===================================');
DBMS_OUTPUT.put_line ('Calling INV_MOVE_ORDER_PUB to Create MO');
INV_MOVE_ORDER_PUB.PROCESS_MOVE_ORDER (p_api_version_number => 1.0, p_init_msg_list => fnd_api.g_false, p_return_values => fnd_api.g_false, p_commit => fnd_api.g_false, x_return_status => x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data, p_trohdr_rec => l_hdr_rec, p_trolin_tbl => l_line_tbl, x_trohdr_rec => x_hdr_rec, x_trohdr_val_rec => x_hdr_val_rec, x_trolin_tbl => x_line_tbl, x_trolin_val_tbl => x_line_val_tbl);
DBMS_OUTPUT.put_line (x_return_status);
DBMS_OUTPUT.put_line (x_msg_count);
IF x_return_status = 'S' THEN
COMMIT;
DBMS_OUTPUT.put_line ('Move Order Successfully Created');
DBMS_OUTPUT.put_line ('Move Order Number is :=> '||x_hdr_rec.request_number);
DBMS_OUTPUT.put_line ('===================================');
ELSE
ROLLBACK;
DBMS_OUTPUT.put_line ('Move Order Creation Failed Due to Following Reasons');
DBMS_OUTPUT.put_line ('===================================');
END IF;
IF x_msg_count > 0 THEN
FOR v_index IN 1 .. x_msg_count
LOOP
fnd_msg_pub.get (p_msg_index => v_index, p_encoded => 'F', p_data => x_msg_data, p_msg_index_out => v_msg_index_out );
x_msg_data := SUBSTR (x_msg_data, 1, 200);
DBMS_OUTPUT.put_line (x_msg_data);
END LOOP;
END IF;
END LOOP;
END XXGSC_CREATE_MO;
答案 0 :(得分:0)
它没有将订单项处理为bash,而是单独执行每个
这就是你编写它的方式:对于每个循环,你将一条记录放入l_line_tbl并将其传递给INV_MOVE_ORDER_PUB。
相反,将l_line_tbl.DELETE移动到循环开始之前。在循环中,递增l_cnt并将该行添加到l_line_tbl。然后,在循环之后,只调用一次INV_MOVE_ORDER_PUB。