Oracle has provided a standard API to cancel PO Line/Lines "po_document_control_pub.control_document".
Step:1 Create a object type to store multiple purchase order lines.
create or replace TYPE po_line_type AS TABLE OF NUMBER;
Step:2 Run the below script to cancel Purchase order line/lines.
Below mentioned is the sample script using which we can cancel single/multiple Purchase Order Lines.
Step:1 Create a object type to store multiple purchase order lines.
create or replace TYPE po_line_type AS TABLE OF NUMBER;
Step:2 Run the below script to cancel Purchase order line/lines.
SET serveroutput ON
DECLARE
v_error_flag NUMBER:=0;
v_po_line_id po_line_type;
v_po_hdr_id NUMBER;
v_error_msg VARCHAR2(1000);
l_return_status VARCHAR2(1000);
l_msg_data VARCHAR2(1000);
BEGIN
-------Fetching Po Header Id-----
BEGIN
SELECT po_header_id INTO v_po_hdr_id
FROM apps.po_headers_all WHERE segment1='52765';
exception
WHEN no_data_found THEN
v_error_flag:=1;
v_error_msg:='Purchase order not found (ND)';
WHEN others THEN
v_error_flag:=1;
v_error_msg:='Purchase order not found (OTH)'||sqlcode||' '||sqlerrm;
END;
IF(v_error_flag <> 1) THEN
-------Fetching Po Line Id-----
SELECT po_line_id BULK COLLECT
INTO v_po_line_id
FROM apps.po_lines_all
WHERE po_header_id=v_po_hdr_id;
-----------------INITIALIZING APPS ---------------------
apps.mo_global.init ('PO');
apps.mo_global.set_policy_context ('S',204);
apps.fnd_global.apps_initialize ( user_id => 1319, resp_id => 50578, resp_appl_id => 201 );
FOR i IN v_po_line_id.FIRST ..v_po_line_id.LAST
loop
dbms_output.put_line('lien'||v_po_line_id(i));
apps.po_document_control_pub.control_document (1.0, -- P_API_VERSION
apps.fnd_api.g_true, -- P_INIT_MSG_LIST
apps.fnd_api.g_true, -- P_COMMIT
l_return_status, -- X_RETURN_STATUS
'PO', -- P_DOC_TYPE
'STANDARD', -- P_DOC_SUBTYPE
NULL, -- P_DOC_ID
'52765', -- P_DOC_NUM
NULL, -- P_RELEASE_ID
NULL, -- P_RELEASE_NUM
v_po_line_id(i), -- P_DOC_LINE_ID
NULL, -- P_DOC_LINE_NUM
NULL, -- P_DOC_LINE_LOC_ID
NULL, -- P_DOC_SHIPMENT_NUM
'CANCEL', -- P_ACTION
SYSDATE, -- P_ACTION_DATE
NULL, -- P_CANCEL_REASON
'N', -- P_CANCEL_REQS_FLAG
NULL, -- P_PRINT_FLAG
NULL, -- P_NOTE_TO_VENDOR
'N' ); --P_USE_GLDATE
COMMIT;
END loop;
dbms_output.put_line('Status '||l_return_status);
------------------FOR ERROR ---------------
IF l_return_status != 'S' THEN
FOR err_code IN 1 .. apps.fnd_msg_pub.count_msg
loop
l_msg_data := substr (apps.fnd_msg_pub.get (p_msg_index => 1,
p_encoded => 'F'), 1, 200 );
dbms_output.put_line('Error Status'||l_msg_data);
END loop;
END IF;
ELSE
dbms_output.put_line('Error'||v_error_msg);
END IF;
END;
Free Webinar : Oracle E-Business Suite - Salesforce.com Integration via Oracle's API on Aug 26th, 2015 at 3PM EST.
ReplyDeleteVisit: http://blog.optiosys.com