Friday, 17 March 2017

API to cancel po in oracle apps R12

DECLARE
 v_return_status   VARCHAR2 (1000);
 v_msg_data        VARCHAR2 (1000);
 v_po_header_id    NUMBER        := 1692230;
 v_doc_subtype     VARCHAR2(10)  := 'STANDARD';
 v_doc_type        VARCHAR2(10)  := 'PO';
 v_org_id          NUMBER         := 2767;
 v_action          VARCHAR2(10)  := 'CANCEL';
 v_action_date     DATE          := SYSDATE;
 l_user_id     number;
 l_resp_id     number;
 l_resp_appl_id  number;
BEGIN
SELECT fnd.user_id, fresp.responsibility_id, fresp.application_id
  INTO l_user_id, l_resp_id, l_resp_appl_id
  FROM fnd_user fnd,
  fnd_responsibility_tl fresp
  WHERE fnd.user_name = 'XXXXXX'
 AND fresp.responsibility_name like 'XXXXX Purchasing Super User'

fnd_global.APPS_INITIALIZE(user_id      => 173683,
                           resp_id      => 52543,
                           resp_appl_id => 201
                          );
 COMMIT;
MO_GLOBAL.INIT ('PO');
--- context done ------------
DBMS_OUTPUT.PUT_LINE ('Calling API For Cancelling Documents');
PO_DOCUMENT_CONTROL_PUB.CONTROL_DOCUMENT
   ( p_api_version      => 1.0,
     p_init_msg_list    => fnd_api.g_true,
     p_commit           => fnd_api.g_false,
     x_return_status    => v_return_status,
     p_doc_type         => v_doc_type,
     p_doc_subtype      => v_doc_subtype,
     p_doc_id           => v_po_header_id,
     p_doc_num          => NULL,
     p_release_id       => NULL,
     p_release_num      => NULL,
     p_doc_line_id      => NULL,
     p_doc_line_num     => NULL,
     p_doc_line_loc_id  => NULL,
     p_doc_shipment_num => NULL,
     p_action           => v_action,
     p_action_date      => v_action_date,
     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           => v_org_id
);
COMMIT;
DBMS_OUTPUT.PUT_LINE('The Return Status of the API : '|| v_return_status);
IF v_return_status = fnd_api.g_ret_sts_success THEN
   COMMIT;
   DBMS_OUTPUT.PUT_LINE ('Cancellation of PO is Sucessfull : '||v_po_header_id);
ELSE
   DBMS_OUTPUT.PUT_LINE ('Cancellation of PO Failed ');
   ROLLBACK;
   FOR i IN 1 .. FND_MSG_PUB.COUNT_MSG
   LOOP
      v_msg_data := FND_MSG_PUB.GET( p_msg_index => i, p_encoded => 'F');
      DBMS_OUTPUT.PUT_LINE( i|| ') '|| v_msg_data);
   END LOOP;
END IF;
END;

No comments:

Post a Comment