Below API block is used for the Sales order cancellation.
declare
v_api_version_number NUMBER := 1;
v_return_status VARCHAR2(2000);
v_msg_count NUMBER;
v_msg_data VARCHAR2(2000);
-- IN Variables --
v_header_rec oe_order_pub.header_rec_type;
v_line_tbl oe_order_pub.line_tbl_type;
v_action_request_tbl oe_order_pub.request_tbl_type;
v_line_adj_tbl oe_order_pub.line_adj_tbl_type;
-- OUT Variables --
v_header_rec_out oe_order_pub.header_rec_type;
v_header_val_rec_out oe_order_pub.header_val_rec_type;
v_header_adj_tbl_out oe_order_pub.header_adj_tbl_type;
v_header_adj_val_tbl_out oe_order_pub.header_adj_val_tbl_type;
v_header_price_att_tbl_out oe_order_pub.header_price_att_tbl_type;
v_header_adj_att_tbl_out oe_order_pub.header_adj_att_tbl_type;
v_header_adj_assoc_tbl_out oe_order_pub.header_adj_assoc_tbl_type;
v_header_scredit_tbl_out oe_order_pub.header_scredit_tbl_type;
v_header_scredit_val_tbl_out oe_order_pub.header_scredit_val_tbl_type;
v_line_tbl_out oe_order_pub.line_tbl_type;
v_line_val_tbl_out oe_order_pub.line_val_tbl_type;
v_line_adj_tbl_out oe_order_pub.line_adj_tbl_type;
v_line_adj_val_tbl_out oe_order_pub.line_adj_val_tbl_type;
v_line_price_att_tbl_out oe_order_pub.line_price_att_tbl_type;
v_line_adj_att_tbl_out oe_order_pub.line_adj_att_tbl_type;
v_line_adj_assoc_tbl_out oe_order_pub.line_adj_assoc_tbl_type;
v_line_scredit_tbl_out oe_order_pub.line_scredit_tbl_type;
v_line_scredit_val_tbl_out oe_order_pub.line_scredit_val_tbl_type;
v_lot_serial_tbl_out oe_order_pub.lot_serial_tbl_type;
v_lot_serial_val_tbl_out oe_order_pub.lot_serial_val_tbl_type;
v_action_request_tbl_out oe_order_pub.request_tbl_type;
v_user_id NUMBER := apps.fnd_global.user_id;
v_resp_id NUMBER := apps.fnd_global.resp_id;
v_resp_appl_id NUMBER := apps.fnd_global.resp_appl_id;
v_org_id NUMBER;
BEGIN
-- Setting the Enviroment --
v_user_id := 43867;
v_resp_id := 56633;
v_resp_appl_id := 660;
v_org_id := 116919;
mo_global.init('ONT');
fnd_global.apps_initialize(user_id => v_user_id, resp_id => v_resp_id,
resp_appl_id => v_resp_appl_id);
mo_global.set_policy_context('S', v_org_id);
FOR I IN (SELECT oh.header_id order_header_id
FROM oe_order_headers_all oh
WHERE oh.order_number IN ( 145054061)
AND oh.org_id = v_org_id)
LOOP
BEGIN
-- CANCEL HEADER --
Dbms_Output.put_line ('order header id : ' || i.order_header_id);
v_header_rec := oe_order_pub.g_miss_header_rec;
v_header_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
v_header_rec.header_id := i.order_header_id;
v_header_rec.cancelled_flag := 'Y';
v_header_rec.change_reason := 'Cancel for Test';
dbms_output.put_line( 'Starting cancel of API');
-- CALLING THE API TO CANCEL AN ORDER --
OE_ORDER_PUB.PROCESS_ORDER(p_api_version_number => v_api_version_number,
p_header_rec => v_header_rec,
p_line_tbl => v_line_tbl,
p_action_request_tbl => v_action_request_tbl,
p_line_adj_tbl => v_line_adj_tbl
-- OUT variables
, x_header_rec => v_header_rec_out,
x_header_val_rec => v_header_val_rec_out,
x_header_adj_tbl => v_header_adj_tbl_out,
x_header_adj_val_tbl => v_header_adj_val_tbl_out,
x_header_price_att_tbl => v_header_price_att_tbl_out,
x_header_adj_att_tbl => v_header_adj_att_tbl_out,
x_header_adj_assoc_tbl => v_header_adj_assoc_tbl_out,
x_header_scredit_tbl => v_header_scredit_tbl_out,
x_header_scredit_val_tbl => v_header_scredit_val_tbl_out,
x_line_tbl => v_line_tbl_out,
x_line_val_tbl => v_line_val_tbl_out,
x_line_adj_tbl => v_line_adj_tbl_out,
x_line_adj_val_tbl => v_line_adj_val_tbl_out,
x_line_price_att_tbl => v_line_price_att_tbl_out,
x_line_adj_att_tbl => v_line_adj_att_tbl_out,
x_line_adj_assoc_tbl => v_line_adj_assoc_tbl_out,
x_line_scredit_tbl => v_line_scredit_tbl_out,
x_line_scredit_val_tbl => v_line_scredit_val_tbl_out,
x_lot_serial_tbl => v_lot_serial_tbl_out,
x_lot_serial_val_tbl => v_lot_serial_val_tbl_out,
x_action_request_tbl => v_action_request_tbl_out,
x_return_status => v_return_status,
x_msg_count => v_msg_count,
x_msg_data => v_msg_data);
dbms_output.put_line( 'Completion of API');
IF v_return_status = fnd_api.g_ret_sts_success THEN
COMMIT;
dbms_output.put_line(
'Order Cancellation Success : ' ||
v_header_rec_out.header_id);
else
dbms_output.put_line(
'order cancellation failed:' || v_msg_data);
rollback;
for i in 1 .. v_msg_count
loop
v_msg_data := oe_msg_pub.get(p_msg_index => i, p_encoded => 'f');
dbms_output.put_line( i || ') ' || v_msg_data);
end loop;
end if;
exception
when others then
dbms_output.put_line('error in cancel_sales_order_api. reason is :' || sqlerrm);
end;
end loop;
exception
when others then
dbms_output.put_line('error in block. reason is :' || sqlerrm);
end ;
declare
v_api_version_number NUMBER := 1;
v_return_status VARCHAR2(2000);
v_msg_count NUMBER;
v_msg_data VARCHAR2(2000);
-- IN Variables --
v_header_rec oe_order_pub.header_rec_type;
v_line_tbl oe_order_pub.line_tbl_type;
v_action_request_tbl oe_order_pub.request_tbl_type;
v_line_adj_tbl oe_order_pub.line_adj_tbl_type;
-- OUT Variables --
v_header_rec_out oe_order_pub.header_rec_type;
v_header_val_rec_out oe_order_pub.header_val_rec_type;
v_header_adj_tbl_out oe_order_pub.header_adj_tbl_type;
v_header_adj_val_tbl_out oe_order_pub.header_adj_val_tbl_type;
v_header_price_att_tbl_out oe_order_pub.header_price_att_tbl_type;
v_header_adj_att_tbl_out oe_order_pub.header_adj_att_tbl_type;
v_header_adj_assoc_tbl_out oe_order_pub.header_adj_assoc_tbl_type;
v_header_scredit_tbl_out oe_order_pub.header_scredit_tbl_type;
v_header_scredit_val_tbl_out oe_order_pub.header_scredit_val_tbl_type;
v_line_tbl_out oe_order_pub.line_tbl_type;
v_line_val_tbl_out oe_order_pub.line_val_tbl_type;
v_line_adj_tbl_out oe_order_pub.line_adj_tbl_type;
v_line_adj_val_tbl_out oe_order_pub.line_adj_val_tbl_type;
v_line_price_att_tbl_out oe_order_pub.line_price_att_tbl_type;
v_line_adj_att_tbl_out oe_order_pub.line_adj_att_tbl_type;
v_line_adj_assoc_tbl_out oe_order_pub.line_adj_assoc_tbl_type;
v_line_scredit_tbl_out oe_order_pub.line_scredit_tbl_type;
v_line_scredit_val_tbl_out oe_order_pub.line_scredit_val_tbl_type;
v_lot_serial_tbl_out oe_order_pub.lot_serial_tbl_type;
v_lot_serial_val_tbl_out oe_order_pub.lot_serial_val_tbl_type;
v_action_request_tbl_out oe_order_pub.request_tbl_type;
v_user_id NUMBER := apps.fnd_global.user_id;
v_resp_id NUMBER := apps.fnd_global.resp_id;
v_resp_appl_id NUMBER := apps.fnd_global.resp_appl_id;
v_org_id NUMBER;
BEGIN
-- Setting the Enviroment --
v_user_id := 43867;
v_resp_id := 56633;
v_resp_appl_id := 660;
v_org_id := 116919;
mo_global.init('ONT');
fnd_global.apps_initialize(user_id => v_user_id, resp_id => v_resp_id,
resp_appl_id => v_resp_appl_id);
mo_global.set_policy_context('S', v_org_id);
FOR I IN (SELECT oh.header_id order_header_id
FROM oe_order_headers_all oh
WHERE oh.order_number IN ( 145054061)
AND oh.org_id = v_org_id)
LOOP
BEGIN
-- CANCEL HEADER --
Dbms_Output.put_line ('order header id : ' || i.order_header_id);
v_header_rec := oe_order_pub.g_miss_header_rec;
v_header_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
v_header_rec.header_id := i.order_header_id;
v_header_rec.cancelled_flag := 'Y';
v_header_rec.change_reason := 'Cancel for Test';
dbms_output.put_line( 'Starting cancel of API');
-- CALLING THE API TO CANCEL AN ORDER --
OE_ORDER_PUB.PROCESS_ORDER(p_api_version_number => v_api_version_number,
p_header_rec => v_header_rec,
p_line_tbl => v_line_tbl,
p_action_request_tbl => v_action_request_tbl,
p_line_adj_tbl => v_line_adj_tbl
-- OUT variables
, x_header_rec => v_header_rec_out,
x_header_val_rec => v_header_val_rec_out,
x_header_adj_tbl => v_header_adj_tbl_out,
x_header_adj_val_tbl => v_header_adj_val_tbl_out,
x_header_price_att_tbl => v_header_price_att_tbl_out,
x_header_adj_att_tbl => v_header_adj_att_tbl_out,
x_header_adj_assoc_tbl => v_header_adj_assoc_tbl_out,
x_header_scredit_tbl => v_header_scredit_tbl_out,
x_header_scredit_val_tbl => v_header_scredit_val_tbl_out,
x_line_tbl => v_line_tbl_out,
x_line_val_tbl => v_line_val_tbl_out,
x_line_adj_tbl => v_line_adj_tbl_out,
x_line_adj_val_tbl => v_line_adj_val_tbl_out,
x_line_price_att_tbl => v_line_price_att_tbl_out,
x_line_adj_att_tbl => v_line_adj_att_tbl_out,
x_line_adj_assoc_tbl => v_line_adj_assoc_tbl_out,
x_line_scredit_tbl => v_line_scredit_tbl_out,
x_line_scredit_val_tbl => v_line_scredit_val_tbl_out,
x_lot_serial_tbl => v_lot_serial_tbl_out,
x_lot_serial_val_tbl => v_lot_serial_val_tbl_out,
x_action_request_tbl => v_action_request_tbl_out,
x_return_status => v_return_status,
x_msg_count => v_msg_count,
x_msg_data => v_msg_data);
dbms_output.put_line( 'Completion of API');
IF v_return_status = fnd_api.g_ret_sts_success THEN
COMMIT;
dbms_output.put_line(
'Order Cancellation Success : ' ||
v_header_rec_out.header_id);
else
dbms_output.put_line(
'order cancellation failed:' || v_msg_data);
rollback;
for i in 1 .. v_msg_count
loop
v_msg_data := oe_msg_pub.get(p_msg_index => i, p_encoded => 'f');
dbms_output.put_line( i || ') ' || v_msg_data);
end loop;
end if;
exception
when others then
dbms_output.put_line('error in cancel_sales_order_api. reason is :' || sqlerrm);
end;
end loop;
exception
when others then
dbms_output.put_line('error in block. reason is :' || sqlerrm);
end ;
Thanks, it works fine.
ReplyDelete