CREATE OR REPLACE PACKAGE BODY po_cancel_pkg AS
PROCEDURE process_po_cancel(errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_operating_unit_id IN NUMBER,
p_vendor_name IN VARCHAR2,
p_vendor_site_cd IN VARCHAR2
) IS
CURSOR get_po_details IS
SELECT pha.segment1 po_number,
pha.po_header_id,
pla.po_line_id ,
plla.line_location_id,
pha.org_id org_id
FROM po_headers_all pha,
ap_suppliers ap,
ap_supplier_sites_all aps,
po_lines_all pla,
po_line_locations_all plla
PROCEDURE process_po_cancel(errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_operating_unit_id IN NUMBER,
p_vendor_name IN VARCHAR2,
p_vendor_site_cd IN VARCHAR2
) IS
CURSOR get_po_details IS
SELECT pha.segment1 po_number,
pha.po_header_id,
pla.po_line_id ,
plla.line_location_id,
pha.org_id org_id
FROM po_headers_all pha,
ap_suppliers ap,
ap_supplier_sites_all aps,
po_lines_all pla,
po_line_locations_all plla
WHERE ap.vendor_id = aps.vendor_id
AND pha.vendor_id = ap.vendor_id
AND pha.vendor_site_id = aps.vendor_site_id
AND NVL(pha.closed_code, 'OPEN') = 'OPEN'
AND NVL(pha.cancel_flag, 'N') = 'N'
AND NVL(plla.cancel_flag, 'N') = 'N'
AND pha.approved_flag = 'Y'
AND pha.po_header_id = pla.po_header_id
AND pla.po_line_id = plla.po_line_id
AND pha.segment1 = <PO_NUMBER>
AND pha.type_lookup_code = 'STANDARD'
AND NVL(plla.quantity_received,0) =0
AND pha.org_id = p_operating_unit_id
AND UPPER(ap.segment1) = NVL(UPPER(p_vendor_name), UPPER(ap.segment1)) -- segment1
AND UPPER(aps.attribute14) = NVL(UPPER(p_vendor_site_cd), UPPER(aps.attribute14)); -- attribute14
l_return_status VARCHAR2(20) DEFAULT NULL;
AND pha.vendor_id = ap.vendor_id
AND pha.vendor_site_id = aps.vendor_site_id
AND NVL(pha.closed_code, 'OPEN') = 'OPEN'
AND NVL(pha.cancel_flag, 'N') = 'N'
AND NVL(plla.cancel_flag, 'N') = 'N'
AND pha.approved_flag = 'Y'
AND pha.po_header_id = pla.po_header_id
AND pla.po_line_id = plla.po_line_id
AND pha.segment1 = <PO_NUMBER>
AND pha.type_lookup_code = 'STANDARD'
AND NVL(plla.quantity_received,0) =0
AND pha.org_id = p_operating_unit_id
AND UPPER(ap.segment1) = NVL(UPPER(p_vendor_name), UPPER(ap.segment1)) -- segment1
AND UPPER(aps.attribute14) = NVL(UPPER(p_vendor_site_cd), UPPER(aps.attribute14)); -- attribute14
l_return_status VARCHAR2(20) DEFAULT NULL;
v_user_id NUMBER := FND_GLOBAL.USER_ID;
v_msg VARCHAR2(4000) DEFAULT
NULL;
v_resp_id CONSTANT NUMBER := fnd_global.resp_id;
v_appl_id CONSTANT NUMBER := fnd_global.resp_appl_id;
v_success_rec NUMBER :=0;
v_fail_rec NUMBER :=0;
v_total_rec NUMBER :=0;
BEGIN
fnd_file.put_line(fnd_file.Log,'Start of the Open PO Cancel program');
fnd_file.put_line(fnd_file.Log,'Vendor Name = '|| p_vendor_name);
fnd_file.put_line(fnd_file.Log,'Vendor Site Code = '||p_vendor_site_cd );
FOR rec in get_po_details
LOOP
v_total_rec := v_total_rec +1 ;
--Intialization for API
fnd_global.apps_initialize(v_user_id, v_resp_id, v_appl_id);
mo_global.init('PO');
mo_global.set_policy_context('S', rec.org_id);
--API Call
po_document_control_pub.control_document(p_api_version => 1.0,
p_init_msg_list => fnd_api.g_true,
p_commit => fnd_api.g_true,
x_return_status => l_return_status,
p_doc_type => 'PO',
p_doc_subtype => 'STANDARD',
p_doc_id => rec.po_header_id,
p_doc_num => NULL,
p_release_id => NULL,
p_release_num => NULL,
p_doc_line_id => rec.po_line_id,
p_doc_line_num => NULL,
p_doc_line_loc_id => rec.line_location_id,
p_doc_shipment_num => NULL,
p_action => 'CANCEL',
p_action_date => SYSDATE,
p_cancel_reason => NULL,
p_cancel_reqs_flag => 'N',
p_print_flag => NULL,
p_note_to_vendor => NULL,
p_use_gldate => NULL,
p_org_id => rec.org_id);
COMMIT;
IF l_return_status = 'S' THEN
v_msg := 'Purchase order : ' || rec.po_number ||'location id '||rec.line_location_id ||' is now cancelled.';
fnd_file.put_line(fnd_file.Log,v_msg);
v_success_rec := v_success_rec +1;
ELSE
l_return_status := 'E';
v_msg := 'Below Error occured while Cancelling Purchase Order : ' ||
rec.po_number ||' - location id '||rec.line_location_id ;
fnd_file.put_line(fnd_file.Log,v_msg);
if fnd_msg_pub.count_msg > 0 then
FOR i IN 1 .. fnd_msg_pub.count_msg LOOP
v_msg := fnd_msg_pub.get(p_msg_index => i, p_encoded => 'F');
fnd_file.put_line(fnd_file.Log,v_msg);
END LOOP;
else
fnd_file.put_line(fnd_file.Log,'No error');
end if;
v_fail_rec := v_fail_rec+1;
END IF;
END LOOP;
fnd_file.put_line(fnd_file.Log,'Number of PO Processed : '||v_total_rec);
fnd_file.put_line(fnd_file.Log,'Number of PO cancelled successfully : '||v_success_rec);
fnd_file.put_line(fnd_file.Log,'Number of PO failed to cancelled : '||v_fail_rec);
EXCEPTION
WHEN others THEN
v_msg := SUBSTR('Error : Something uexpected occured ' ||
SQLERRM,
1,
200);
fnd_file.put_line(fnd_file.Log,v_msg);
retcode := 2;
errbuf := v_msg;
END process_po_cancel;
END po_cancel_pkg;
/
v_resp_id CONSTANT NUMBER := fnd_global.resp_id;
v_appl_id CONSTANT NUMBER := fnd_global.resp_appl_id;
v_success_rec NUMBER :=0;
v_fail_rec NUMBER :=0;
v_total_rec NUMBER :=0;
BEGIN
fnd_file.put_line(fnd_file.Log,'Start of the Open PO Cancel program');
fnd_file.put_line(fnd_file.Log,'Vendor Name = '|| p_vendor_name);
fnd_file.put_line(fnd_file.Log,'Vendor Site Code = '||p_vendor_site_cd );
FOR rec in get_po_details
LOOP
v_total_rec := v_total_rec +1 ;
--Intialization for API
fnd_global.apps_initialize(v_user_id, v_resp_id, v_appl_id);
mo_global.init('PO');
mo_global.set_policy_context('S', rec.org_id);
--API Call
po_document_control_pub.control_document(p_api_version => 1.0,
p_init_msg_list => fnd_api.g_true,
p_commit => fnd_api.g_true,
x_return_status => l_return_status,
p_doc_type => 'PO',
p_doc_subtype => 'STANDARD',
p_doc_id => rec.po_header_id,
p_doc_num => NULL,
p_release_id => NULL,
p_release_num => NULL,
p_doc_line_id => rec.po_line_id,
p_doc_line_num => NULL,
p_doc_line_loc_id => rec.line_location_id,
p_doc_shipment_num => NULL,
p_action => 'CANCEL',
p_action_date => SYSDATE,
p_cancel_reason => NULL,
p_cancel_reqs_flag => 'N',
p_print_flag => NULL,
p_note_to_vendor => NULL,
p_use_gldate => NULL,
p_org_id => rec.org_id);
COMMIT;
IF l_return_status = 'S' THEN
v_msg := 'Purchase order : ' || rec.po_number ||'location id '||rec.line_location_id ||' is now cancelled.';
fnd_file.put_line(fnd_file.Log,v_msg);
v_success_rec := v_success_rec +1;
ELSE
l_return_status := 'E';
v_msg := 'Below Error occured while Cancelling Purchase Order : ' ||
rec.po_number ||' - location id '||rec.line_location_id ;
fnd_file.put_line(fnd_file.Log,v_msg);
if fnd_msg_pub.count_msg > 0 then
FOR i IN 1 .. fnd_msg_pub.count_msg LOOP
v_msg := fnd_msg_pub.get(p_msg_index => i, p_encoded => 'F');
fnd_file.put_line(fnd_file.Log,v_msg);
END LOOP;
else
fnd_file.put_line(fnd_file.Log,'No error');
end if;
v_fail_rec := v_fail_rec+1;
END IF;
END LOOP;
fnd_file.put_line(fnd_file.Log,'Number of PO Processed : '||v_total_rec);
fnd_file.put_line(fnd_file.Log,'Number of PO cancelled successfully : '||v_success_rec);
fnd_file.put_line(fnd_file.Log,'Number of PO failed to cancelled : '||v_fail_rec);
EXCEPTION
WHEN others THEN
v_msg := SUBSTR('Error : Something uexpected occured ' ||
SQLERRM,
1,
200);
fnd_file.put_line(fnd_file.Log,v_msg);
retcode := 2;
errbuf := v_msg;
END process_po_cancel;
END po_cancel_pkg;
/