--以下脚本于20180124在Tony环境实现
--online模式接收
DECLARE
g_group_id NUMBER := rcv_interface_groups_s.nextval;
g_creation_date DATE := SYSDATE;
g_created_by NUMBER := fnd_global.user_id;
g_last_updated_by NUMBER := fnd_global.user_id;
g_last_update_date DATE := SYSDATE;
g_last_update_login NUMBER := fnd_global.login_id;
l_request_id NUMBER;
l_request_flag BOOLEAN := false;
l_phase VARCHAR2(30);
l_dev_status VARCHAR2(30);
l_status VARCHAR2(20);
l_dev_phase VARCHAR2(200);
l_message VARCHAR2(2000);
timeout NUMBER;
RC NUMBER :=0;
outcome VARCHAR2(200) := NULL;
message VARCHAR2(200) := NULL;
L_PO_HEADER_ID NUMBER;
L_PO_LINE_ID NUMBER;
L_PO_DISTRIBUTION_ID NUMBER;
L_LINE_LOCATION_ID NUMBER;
l_header_iface rcv_headers_interface%ROWTYPE;
l_trx_iface rcv_transactions_interface%ROWTYPE;
l_rcv_lots_interface mtl_transaction_lots_interface%ROWTYPE;
BEGIN
/* fnd_global.apps_initialize(user_id =>1170,--fnd_global.user_id,
resp_id =>50838,--fnd_global.resp_id,
resp_appl_id =>20004);--fnd_global.resp_appl_id);
mo_global.init('PO');
mo_global.set_policy_context('S',101); */
begin
fnd_global.apps_initialize(user_id => 1110,
resp_id => 50597,
resp_appl_id => 20003);
mo_global.init('M');
end;
SELECT PDA.PO_HEADER_ID,
PDA.PO_LINE_ID,
PDA.PO_DISTRIBUTION_ID,
PDA.LINE_LOCATION_ID
INTO L_PO_HEADER_ID,
L_PO_LINE_ID,
L_PO_DISTRIBUTION_ID,
L_LINE_LOCATION_ID
FROM PO_HEADERS_ALL PHA, PO_LINES_ALL PLA, PO_DISTRIBUTIONS_ALL PDA
WHERE PHA.PO_HEADER_ID = PLA.PO_HEADER_ID
AND PLA.PO_LINE_ID = PDA.PO_LINE_ID
AND PHA.PO_HEADER_ID = PDA.PO_HEADER_ID
AND PHA.SEGMENT1 = '1018';
l_header_iface.last_update_date := g_last_update_date;
l_header_iface.last_updated_by := g_last_updated_by;
l_header_iface.last_update_login := g_last_update_login;
l_header_iface.creation_date := g_creation_date;
l_header_iface.created_by := g_created_by;
l_trx_iface.last_update_date := g_last_update_date;
l_trx_iface.last_updated_by := g_last_updated_by;
l_trx_iface.creation_date := g_creation_date;
l_trx_iface.created_by := g_created_by;
l_trx_iface.last_update_login := g_last_update_login;
l_rcv_lots_interface.last_update_date := g_last_update_date;
l_rcv_lots_interface.last_updated_by := g_last_updated_by;
l_rcv_lots_interface.creation_date := g_creation_date;
l_rcv_lots_interface.created_by := g_created_by;
l_rcv_lots_interface.last_update_login := g_last_update_login;
--FOR c_header IN cur_header LOOP
SELECT po.rcv_headers_interface_s.nextval
INTO l_header_iface.header_interface_id
FROM dual;
l_header_iface.processing_status_code := 'PENDING';
l_header_iface.receipt_source_code := 'VENDOR';
l_header_iface.transaction_type := 'NEW';
l_header_iface.auto_transact_code := 'RECEIVE';
l_header_iface.receipt_num := NULL; --接收编号,可自动生成
l_header_iface.shipment_num := to_char(sysdate,
'yyyymmddHHMISS'); --发运编号,必须唯一
l_header_iface.vendor_id := 1; --供应商
l_header_iface.vendor_site_id := 1; -- 供应商地点
l_header_iface.org_id := 82; --业务实体
l_header_iface.comments := '菱商发运采购订单入库(' || 10120170424004 || ')'; --备注,会写到发运行
l_header_iface.expected_receipt_date := SYSDATE; --接收日期
l_header_iface.validation_flag := 'Y';
l_header_iface.group_id := g_group_id; --组编号
l_header_iface.ship_to_organization_id := 81;
/* SELECT l.ship_to_organization_id
INTO l_header_iface.ship_to_organization_id
FROM po_line_locations_all l
WHERE l.po_header_id = c_header.po_header_id
AND rownum = 1;*/
INSERT INTO rcv_headers_interface VALUES l_header_iface;
-- FOR c_line IN cur_line(c_header.po_num) LOOP
SELECT rcv_transactions_interface_s.nextval
INTO l_trx_iface.interface_transaction_id
FROM dual;
--直接入库
l_trx_iface.transaction_type := 'RECEIVE';
l_trx_iface.auto_transact_code := 'DELIVER'; --(将配置文件“RCV:允许改写接收方式”在地点层改为是之后处理正常,否则此处会报错)
l_trx_iface.destination_type_code := 'INVENTORY';
l_trx_iface.processing_status_code := 'PENDING';
l_trx_iface.processing_mode_code := 'ONLINE'; --'BATCH';
l_trx_iface.transaction_status_code := 'PENDING';
l_trx_iface.receipt_source_code := 'VENDOR';
l_trx_iface.validation_flag := 'Y';
l_trx_iface.header_interface_id := l_header_iface.header_interface_id;
l_trx_iface.vendor_id := 1; --供应商
l_trx_iface.vendor_site_id := 1; --供应商地点
l_trx_iface.source_document_code := 'PO'; --来源
l_trx_iface.po_header_id := L_PO_HEADER_ID; --采购订单头表ID
l_trx_iface.po_line_id := L_PO_LINE_ID; --采购订单行表ID
l_trx_iface.po_line_location_id := L_PO_DISTRIBUTION_ID; --定位表ID
l_trx_iface.po_distribution_id := L_LINE_LOCATION_ID; --分配表ID
l_trx_iface.po_release_id := NULL; --
--l_trx_iface.category_id :=1123;--物料类型
l_trx_iface.item_id := 81; --物料ID
-- l_trx_iface.item_description := '低值医疗耗材测试';--物料描述
l_trx_iface.group_id := g_group_id; --组编号
l_trx_iface.transaction_date := SYSDATE; --接收日期
l_trx_iface.expected_receipt_date := SYSDATE; --需要日期
l_trx_iface.unit_of_measure := '个'; --单位(注意不是code)
l_trx_iface.use_mtl_lot := 2; --1;--2;--物料如果按批次,必须赋值2,1代表非批次,这里两种都需要进行测试
l_trx_iface.quantity := 10; --数量
l_trx_iface.primary_quantity := 10; --主数量
l_trx_iface.to_organization_id := 81; -- 接收组织ID
l_trx_iface.ship_to_location_id := 144; --接收地址ID
l_trx_iface.interface_source_code := 'RCV'; --来源
l_trx_iface.comments := 'PO 菱商发运接收'; --会写到发运行表
l_trx_iface.subinventory := 'XIU01'; --子库存
l_trx_iface.inspection_status_code := 'NOT INSPECTED'; --不检查
--批
-- FOR c_lot IN cur_lot(c_header.po_num,c_line.po_line_num) LOOP \
--如果物料启用了批次,则以下脚本必须不能注释,否则会提示错误消息 :=批次/序列验证失败。有关详情,请检查日志。错误消息 :=WMSINB-23184:批次/序列验证失败。有关详情,请检查日志。
SELECT mtl_material_transactions_s.nextval
INTO l_rcv_lots_interface.transaction_interface_id
FROM dual;
l_rcv_lots_interface.product_code := 'RCV';
l_rcv_lots_interface.product_transaction_id := l_trx_iface.interface_transaction_id;
l_rcv_lots_interface.lot_number := to_char(sysdate,
'yyyymmddHHMISS'); --批次号
l_rcv_lots_interface.transaction_quantity := 10; --数量
l_rcv_lots_interface.primary_quantity := 10; --主数量
l_trx_iface.quantity := 10;
l_trx_iface.primary_quantity := 10;
INSERT INTO mtl_transaction_lots_interface VALUES l_rcv_lots_interface;
-- END LOOP;
INSERT INTO rcv_transactions_interface VALUES l_trx_iface;
-- END LOOP;
--END LOOP;
dbms_output.put_line('g_group_id :=' || g_group_id);
IF g_group_id IS NOT NULL THEN
COMMIT; -- Must commit before call synchronous transaction
timeout := fnd_profile.value('INV_RPC_TIMEOUT');
IF (timeout IS NULL) THEN
timeout := 300;
END IF;
--=ONLINE(联机),
--=BATCH(批),需要手工提交一个请求,不建议使用
--=IMMEDIATE(立即),建议使用这种方式
rc := fnd_transaction.synchronous(timeout,
outcome,
message,
'PO',
'RCVTPO',
'ONLINE', -- 'IMMEDIATE',
g_group_id,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL);
END IF;
IF l_request_flag THEN
IF l_dev_status = 'NORMAL' THEN
--对于未成功的,回写错误消息
FOR error_rec IN (SELECT poe.error_message,
rti.po_header_id,
rti.po_line_id
FROM po_interface_errors poe,
rcv_transactions_interface rti
WHERE poe.interface_line_id =
rti.interface_transaction_id
AND rti.group_id = g_group_id) LOOP
dbms_output.put_line('错误消息 :=' || error_rec.error_message);
END LOOP;
ELSE
dbms_output.put_line('Exceptions happen during execution of the request(request id:' ||
l_request_id || ').');
END IF;
ELSE
dbms_output.put_line('The request has not been finished yet and the result is unknown.');
END IF;
END;