API for Closing/Finally Closing PO Using po_actions.close_po
API for closing or finally closing the POs. In this API, there is a parameter "p_action" which we need to set as either CLOSE (if we want to close the PO) or FINALLY CLOSE (If we want to Finally Close) the PO. Another Parameter which needs to set properly is "p_auto_close". This parameter should be set to 'N'.
/*oracle R12 : PO - Script to Close / Finally Close PO using PO_ACTIONS CLOSE_PO API.sql*/
DECLARE
x_action constant varchar2(20) := 'CLOSE'; -- Change this parameter as per requirement
x_calling_mode constant varchar2(2) := 'PO';
x_conc_flag constant varchar2(1) := 'N';
x_return_code_h varchar2(100);
x_auto_close constant varchar2(1) := 'N';
x_origin_doc_id number;
x_returned boolean;
CURSOR c_po_details IS
SELECT
pha.po_header_id,
pha.org_id,
pha.segment1,
pha.agent_id,
pdt.document_subtype,
pdt.document_type_code,
pha.closed_code,
pha.closed_date
FROM apps.po_headers_all pha, apps. pdt
WHERE pha.type_lookup_code = pdt.document_subtype
AND pha.org_id = pdt.org_id
AND pdt.document_type_code = 'PO'
AND authorization_status = 'APPROVED'
AND pha.closed_code <> 'CLOSED'
AND segment1 = 'P_PO_Number'; -- Enter the PO Number if only one PO needs to be finally closed/Closed
begin
fnd_global.apps_initialize (user_id => P_user_id,
resp_id => P_resp_id,
resp_appl_id => P_resp_appl_id);
/*For more details on how to Initialize the session oracle Apps R-12 visit Initializing The Session Oracle Apps R-12
*/
for po_head in c_po_details
LOOP
mo_global.init (po_head.document_type_code);
mo_global.set_policy_context ('S', po_head.org_id);
DBMS_OUTPUT.PUT_LINE ('Calling PO_Actions.close_po for Closing/Finally Closing PO =>' po_head.segment1);
x_returned :=
po_actions.close_po(
p_docid => po_head.po_header_id,
p_doctyp => po_head.document_type_code,
p_docsubtyp => po_head.document_subtype,
p_lineid => NULL,
p_shipid => NULL,
p_action => x_action,
p_reason => NULL,
p_calling_mode => x_calling_mode,
p_conc_flag => x_conc_flag,
p_return_code => x_return_code_h,
p_auto_close => x_auto_close,
p_action_date => SYSDATE,
p_origin_doc_id => NULL);
IF x_returned = TRUE THEN
DBMS_OUTPUT.PUT_LINE ('Purchase Order which just got Closed/Finally Closed is ' po_head.segment1);
COMMIT;
ELSE
DBMS_OUTPUT.PUT_LINE ('API Failed to Close/Finally Close the Purchase Order');
END IF;
END LOOP;
END;
/**Note : You can change document_type_code to close others type also for eg. PA,RFQ,REQUISITION etc. */