Tuesday, March 20, 2012

PO Cancellation

PROCEDURE po_cancellation (p_po_hdr_id    IN     NUMBER,
                           x_result_out      OUT NUMBER,
                           x_error_code      OUT NUMBER,
                           x_error_msg       OUT VARCHAR2)
IS
   l_return_status   VARCHAR2 (1);
   CURSOR cur_po_line
   IS
      SELECT po_line_id
        FROM xxey_tms_po_line_unreserve_t
       WHERE po_header_id = p_po_hdr_id AND flow_status_code = 'Un-Reserved';
BEGIN
   x_result_out := 0;
   x_error_code := 0;
   x_error_msg := 'Success';

   FOR rec_po_line IN cur_po_line
   LOOP
      --call the Cancel API
      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
                                               p_po_hdr_id  ,      -- p_doc_id
                                               NULL  ,             -- p_doc_num
                                               NULL   ,           -- p_release_id
                                               NULL   ,         -- p_release_num 
                                               rec_po_line.po_line_id    ,-- 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
                                                'Vendor No-Show or Clubbed', -- p_cancel_reason       
                                               'N',      -- p_cancel_reqs_flag
                                               NULL  ,          -- p_print_flag
                                               NULL ,       -- p_note_to_vendor
                                              'Y');           --p_use_gldate

      IF l_return_status = 'S'
      THEN
         UPDATE xxey_tms_po_line_unreserve_t
            SET flow_status_code = 'Cancelled'
          WHERE po_header_id = p_po_hdr_id
                AND po_line_id = rec_po_line.po_line_id;

         COMMIT;
      END IF;

      XXEY_TMS_INTEGRATION_PKG.Error_Log (
         'TMS Interface',
         'PO Line Cancel',
         'xxey_tms_po_interface_pkg.po_line_cancellation',
         NULL,
         l_return_status,
         rec_po_line.po_line_id,
         x_error_msg,
         g_user_id);
   END LOOP;
EXCEPTION
   WHEN NO_DATA_FOUND
   THEN
      x_result_out := -1;
      x_error_code := SQLCODE;
      x_error_msg := SQLERRM (x_error_code);
      XXEY_TMS_INTEGRATION_PKG.Error_Log (
         'TMS Interface',
         'PO Line Cancel',
         'xxey_tms_po_interface_pkg.po_line_cancellation',
         NULL,
         NULL,
         x_error_code,
         x_error_msg,
         g_user_id);
   WHEN OTHERS
   THEN
      x_result_out := -1;
      x_error_code := SQLCODE;
      x_error_msg := SQLERRM (x_error_code);
      XXEY_TMS_INTEGRATION_PKG.Error_Log (
         'TMS Interface',
         'PO Line Cancel',
         'xxey_tms_po_interface_pkg.po_line_cancellation',
         NULL,
         NULL,
         x_error_code,
         x_error_msg,
         g_user_id);
END po_cancellation;

No comments:

Post a Comment