Showing posts with label API. Show all posts
Showing posts with label API. Show all posts

22 December, 2020

API to Cancel Open PO

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
        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;

    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;
/

30 October, 2017

API to update Project code on Requisition

Below API can be used in oracle apps to Update the project code on requisition.

set serveroutput on
DECLARE

l_req_hdr PO_REQUISIITON_UPDATE_PUB.req_hdr;
l_req_line_tbl  PO_REQUISIITON_UPDATE_PUB.req_line_tbl;
l_req_dist_tbl PO_REQUISIITON_UPDATE_PUB.req_dist_tbl;
l_return_status VARCHAR2(1);
l_msg_count NUMBER;
l_msg_data VARCHAR2(2000);

BEGIN

dbms_output.ENABLE(1000000);
   fnd_global.Apps_initialize(108970, 20707, 201);
   -- pass in user_id, responsibility_id, and application_id 
   oe_msg_pub.initialize;
   oe_debug_pub.initialize;
   mo_global.Init ('ONT'); -- Required for R12
   mo_global.Set_org_context (101, NULL, 'ONT');
   fnd_global.Set_nls_context ('AMERICAN');
   mo_global.Set_policy_context ('S', 101);
 
l_req_hdr.segment1 :='Test123';
l_req_hdr.org_id := 101;

l_req_dist_tbl.project_id := 344;

dbms_output.put_line('Before calling the API');

PO_REQUISIITON_UPDATE_PUB.update_requisition(1.0,
'F',
'N',
l_return_status,
l_msg_count,
l_msg_data,
'Y',
l_req_hdr,
    l_req_line_tbl,
    l_req_dist_tbl
);

dbms_output.put_line('After calling the API');
dbms_output.put_line('l_return_status'||l_return_status);
    dbms_output.put_line('l_msg_count'||      l_msg_count);
    dbms_output.put_line('l_msg_data'|| l_msg_data);

END;
/

Oracle apps Requisition Cancellation API

Below API can be used for Oracle apps Requisition cancellation.

DECLARE
   v_requisition_header_id po_requisition_headers_all.requisition_header_id%TYPE;
   v_requisition_line_id   po_requisition_lines_all.requisition_line_id%TYPE;
   v_REQ_HEADER_ID         PO_TBL_NUMBER;
   v_REQ_LINE_ID           PO_TBL_NUMBER;
   v_msg                   VARCHAR2(1000);
   x_returnstatus          VARCHAR2(10);
   x_msgcount              NUMBER;
   x_msgdata               VARCHAR2(200);
BEGIN
FND_GLOBAL.APPS_INITIALIZE(
user_id => 43867 -- User ID
, resp_id => 20707 -- Order Management Super User
, resp_appl_id => 201 -- Oracle Order Management
);
MO_GLOBAL.INIT('PO');
mo_global.set_policy_context('S', 101);


FOR i IN (SELECT         
               prh.requisition_header_id,
               prl.requisition_line_id
            FROM
               apps.po_requisition_lines_all prl
where <desired conditions .. >
             
)
LOOP
          v_requisition_header_id := i.requisition_header_id;
          v_requisition_line_id   := i.requisition_line_id;
--
            v_REQ_HEADER_ID := PO_TBL_NUMBER(v_requisition_header_id);
            v_REQ_LINE_ID   := PO_TBL_NUMBER(v_requisition_line_id);
            --Cancelling the requisition
            po_req_document_cancel_grp.cancel_requisition(p_api_version => 1.0,
                                                          p_req_header_id => v_REQ_HEADER_ID,
                                                          p_req_line_id => v_REQ_LINE_ID,
                                                          p_cancel_date => SYSDATE,
                                                          p_cancel_reason => 'QTY shipped',
                                                          p_source => NULL,
                                                          x_return_status => x_returnstatus,
                                                          x_msg_count => x_msgcount,
                                                          x_msg_data => x_msgdata);
END LOOP;
END;

COMMIT;
/

API to Cancel Sales order

Below API block is used for the Sales order cancellation.

declare
      v_api_version_number NUMBER := 1;
      v_return_status      VARCHAR2(2000);
      v_msg_count          NUMBER;
      v_msg_data           VARCHAR2(2000);
 
      -- IN Variables --
      v_header_rec         oe_order_pub.header_rec_type;
      v_line_tbl           oe_order_pub.line_tbl_type;
      v_action_request_tbl oe_order_pub.request_tbl_type;
      v_line_adj_tbl       oe_order_pub.line_adj_tbl_type;
 
      -- OUT Variables --
      v_header_rec_out             oe_order_pub.header_rec_type;
      v_header_val_rec_out         oe_order_pub.header_val_rec_type;
      v_header_adj_tbl_out         oe_order_pub.header_adj_tbl_type;
      v_header_adj_val_tbl_out     oe_order_pub.header_adj_val_tbl_type;
      v_header_price_att_tbl_out   oe_order_pub.header_price_att_tbl_type;
      v_header_adj_att_tbl_out     oe_order_pub.header_adj_att_tbl_type;
      v_header_adj_assoc_tbl_out   oe_order_pub.header_adj_assoc_tbl_type;
      v_header_scredit_tbl_out     oe_order_pub.header_scredit_tbl_type;
      v_header_scredit_val_tbl_out oe_order_pub.header_scredit_val_tbl_type;
      v_line_tbl_out               oe_order_pub.line_tbl_type;
      v_line_val_tbl_out           oe_order_pub.line_val_tbl_type;
      v_line_adj_tbl_out           oe_order_pub.line_adj_tbl_type;
      v_line_adj_val_tbl_out       oe_order_pub.line_adj_val_tbl_type;
      v_line_price_att_tbl_out     oe_order_pub.line_price_att_tbl_type;
      v_line_adj_att_tbl_out       oe_order_pub.line_adj_att_tbl_type;
      v_line_adj_assoc_tbl_out     oe_order_pub.line_adj_assoc_tbl_type;
      v_line_scredit_tbl_out       oe_order_pub.line_scredit_tbl_type;
      v_line_scredit_val_tbl_out   oe_order_pub.line_scredit_val_tbl_type;
      v_lot_serial_tbl_out         oe_order_pub.lot_serial_tbl_type;
      v_lot_serial_val_tbl_out     oe_order_pub.lot_serial_val_tbl_type;
      v_action_request_tbl_out     oe_order_pub.request_tbl_type;
 
      v_user_id      NUMBER := apps.fnd_global.user_id;
      v_resp_id      NUMBER := apps.fnd_global.resp_id;
      v_resp_appl_id NUMBER := apps.fnd_global.resp_appl_id;
      v_org_id       NUMBER;
   BEGIN
 
      -- Setting the Enviroment --
     
      v_user_id      := 43867;
      v_resp_id      := 56633;
      v_resp_appl_id := 660;
      v_org_id       := 116919;
 
      mo_global.init('ONT');
      fnd_global.apps_initialize(user_id => v_user_id, resp_id => v_resp_id,
                                 resp_appl_id => v_resp_appl_id);
      mo_global.set_policy_context('S', v_org_id);
 
      FOR I IN (SELECT oh.header_id order_header_id
                FROM   oe_order_headers_all oh
                WHERE  oh.order_number IN ( 145054061)
                AND    oh.org_id = v_org_id)
      LOOP
        BEGIN
              -- CANCEL HEADER --
              Dbms_Output.put_line ('order header id : ' || i.order_header_id);
          v_header_rec                := oe_order_pub.g_miss_header_rec;
          v_header_rec.operation      := OE_GLOBALS.G_OPR_UPDATE;
          v_header_rec.header_id      := i.order_header_id;
          v_header_rec.cancelled_flag := 'Y';
          v_header_rec.change_reason  := 'Cancel for Test';
     
          dbms_output.put_line( 'Starting cancel of API');
     
          -- CALLING THE API TO CANCEL AN ORDER --
     
          OE_ORDER_PUB.PROCESS_ORDER(p_api_version_number => v_api_version_number,
                                     p_header_rec => v_header_rec,
                                     p_line_tbl => v_line_tbl,
                                     p_action_request_tbl => v_action_request_tbl,
                                     p_line_adj_tbl => v_line_adj_tbl
                                     -- OUT variables
                                    , x_header_rec => v_header_rec_out,
                                     x_header_val_rec => v_header_val_rec_out,
                                     x_header_adj_tbl => v_header_adj_tbl_out,
                                     x_header_adj_val_tbl => v_header_adj_val_tbl_out,
                                     x_header_price_att_tbl => v_header_price_att_tbl_out,
                                     x_header_adj_att_tbl => v_header_adj_att_tbl_out,
                                     x_header_adj_assoc_tbl => v_header_adj_assoc_tbl_out,
                                     x_header_scredit_tbl => v_header_scredit_tbl_out,
                                     x_header_scredit_val_tbl => v_header_scredit_val_tbl_out,
                                     x_line_tbl => v_line_tbl_out,
                                     x_line_val_tbl => v_line_val_tbl_out,
                                     x_line_adj_tbl => v_line_adj_tbl_out,
                                     x_line_adj_val_tbl => v_line_adj_val_tbl_out,
                                     x_line_price_att_tbl => v_line_price_att_tbl_out,
                                     x_line_adj_att_tbl => v_line_adj_att_tbl_out,
                                     x_line_adj_assoc_tbl => v_line_adj_assoc_tbl_out,
                                     x_line_scredit_tbl => v_line_scredit_tbl_out,
                                     x_line_scredit_val_tbl => v_line_scredit_val_tbl_out,
                                     x_lot_serial_tbl => v_lot_serial_tbl_out,
                                     x_lot_serial_val_tbl => v_lot_serial_val_tbl_out,
                                     x_action_request_tbl => v_action_request_tbl_out,
                                     x_return_status => v_return_status,
                                     x_msg_count => v_msg_count,
                                     x_msg_data => v_msg_data);
     
          dbms_output.put_line( 'Completion of API');
     
          IF v_return_status = fnd_api.g_ret_sts_success THEN
             COMMIT;
             dbms_output.put_line(
                               'Order Cancellation Success : ' ||
                                v_header_rec_out.header_id);
          else
             dbms_output.put_line(
                               'order cancellation failed:' || v_msg_data);
             rollback;
             for i in 1 .. v_msg_count
             loop
                v_msg_data := oe_msg_pub.get(p_msg_index => i, p_encoded => 'f');
                dbms_output.put_line( i || ') ' || v_msg_data);
             end loop;
          end if;
        exception
          when others then
             dbms_output.put_line('error in cancel_sales_order_api. reason is :' || sqlerrm);       
        end;
      end loop;
   exception
      when others then
         dbms_output.put_line('error in block. reason is :' || sqlerrm);
     
   end ;