Thursday, December 10, 2015

Script to Cancel the Purchase Order with API

SET SERVEROUTPUT ON;
DECLARE
  l_return_status VARCHAR2(1);

  PROCEDURE APPS_INIT(a_user_name VARCHAR2 := 'OPERATIONS',
                      i_key       VARCHAR2 DEFAULT 'PURCHASING_SUPER_USER') IS
    v_User_ID NUMBER;
    v_Resp_ID NUMBER;
    v_Appl_ID NUMBER;
  BEGIN
 
    SELECT user_id INTO v_User_ID FROM fnd_user u WHERE u.user_name = a_user_name;
    SELECT r.application_id, r.responsibility_id INTO v_Appl_ID, v_Resp_ID FROM fnd_responsibility r WHERE r.responsibility_key = i_key; --'CASH_MANAGEMENT';

    FND_GLOBAL.APPS_INITIALIZE(1318, v_Resp_ID, v_Appl_Id); --по agent_id находим user_id
    GHR_SESSION.SET_SESSION_VAR_FOR_CORE(SYSDATE);
 
    --MO_GLOBAL.init('XXT');
    MO_GLOBAL.SET_POLICY_CONTEXT('S', 204); --ORG_ID
    ARP_GLOBAL.INIT_GLOBAL;
  END APPS_INIT;
 
BEGIN
  APPS_INIT;

  UPDATE po_headers_all ha
     SET ha.authorization_status = 'REJECTED'
   where ha.po_header_id = 4586215;  
  COMMIT;
 
  mo_global.init('PO'); -- need for R12
  FND_PROFILE.PUT('AFLOG_ENABLED', 'Y');
  fnd_log_repository.INIT;
  PO_LOG.enable_logging('PO', 1);
 
  --> Call the Cancel API for PO number PO123
  PO_DOCUMENT_CONTROL_PUB.CONTROL_DOCUMENT(1.0, -- p_api_version
                                           FND_API.G_TRUE, -- p_init_msg_list
                                           FND_API.G_TRUE, -- p_commit
                                           l_return_status, -- x_return_status
                                           'PO', -- p_doc_type
                                           'STANDARD', -- p_doc_subtype
                                           NULL, -- p_doc_id
                                           '10848', -- 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
                                           'CANCEL', -- p_action
                                           SYSDATE, -- p_action_date
                                           NULL, -- p_cancel_reason
                                           'N', -- p_cancel_reqs_flag
                                           NULL, -- p_print_flag
                                           NULL,
                                           p_org_id => 204); -- p_note_to_vendor

  -- Get any messages returned by the Cancel API
  DBMS_OUTPUT.PUT_LINE('L_RETURN_STATUS = '||L_RETURN_STATUS);
 
  FOR i IN 1 .. FND_MSG_PUB.count_msg
  LOOP
    DBMS_OUTPUT.put_line(FND_MSG_PUB.Get(p_msg_index => i,p_encoded   => 'F'));
  END LOOP;
  COMMIT;
END;
/


No comments:

Post a Comment

Best Blogger TipsGet Flower Effect