Search This Blog

Sunday, November 28, 2010

Cancel Order Line – Order Management oe_order_pub.process_order

API to cancel Order Line:

CREATE OR REPLACE PROCEDURE xxom_cancel_line (
   p_errbuf    IN   VARCHAR2,
   p_retcode   IN   NUMBER,
   p_validate in varchar2
)
AS
/*************************************/
/* Variables */
/*************************************/
   l_step                      VARCHAR2 (250);
   l_err_msg                   VARCHAR2 (1000);
   v                           VARCHAR2 (1000);
   l_line_tbl                  oe_order_pub.line_tbl_type;
   lx_return_status            VARCHAR2 (10000);
   lx_msg_count                NUMBER;
   lx_msg_data                 VARCHAR2 (10000);
   lx_header_rec               oe_order_pub.header_rec_type;
   lx_header_val_rec           oe_order_pub.header_val_rec_type;
   lx_header_adj_tbl           oe_order_pub.header_adj_tbl_type;
   lx_header_adj_val_tbl       oe_order_pub.header_adj_val_tbl_type;
   lx_header_price_att_tbl     oe_order_pub.header_price_att_tbl_type;
   lx_header_adj_att_tbl       oe_order_pub.header_adj_att_tbl_type;
   lx_header_adj_assoc_tbl     oe_order_pub.header_adj_assoc_tbl_type;
   lx_header_scredit_tbl       oe_order_pub.header_scredit_tbl_type;
   lx_header_scredit_val_tbl   oe_order_pub.header_scredit_val_tbl_type;
   lx_header_payment_tbl       oe_order_pub.header_payment_tbl_type;
   lx_header_payment_val_tbl   oe_order_pub.header_payment_val_tbl_type;
   lx_line_tbl                 oe_order_pub.line_tbl_type;
   lx_line_val_tbl             oe_order_pub.line_val_tbl_type;
   lx_line_adj_tbl             oe_order_pub.line_adj_tbl_type;
   lx_line_adj_val_tbl         oe_order_pub.line_adj_val_tbl_type;
   lx_line_price_att_tbl       oe_order_pub.line_price_att_tbl_type;
   lx_line_adj_att_tbl         oe_order_pub.line_adj_att_tbl_type;
   lx_line_adj_assoc_tbl       oe_order_pub.line_adj_assoc_tbl_type;
   lx_line_scredit_tbl         oe_order_pub.line_scredit_tbl_type;
   lx_line_scredit_val_tbl     oe_order_pub.line_scredit_val_tbl_type;
   lx_line_payment_tbl         oe_order_pub.line_payment_tbl_type;
   lx_line_payment_val_tbl     oe_order_pub.line_payment_val_tbl_type;
   lx_lot_serial_tbl           oe_order_pub.lot_serial_tbl_type;
   lx_lot_serial_val_tbl       oe_order_pub.lot_serial_val_tbl_type;
   lx_action_request_tbl       oe_order_pub.request_tbl_type;

   CURSOR cur_so
   IS
      SELECT ool.header_id, ool.line_id
        FROM oe_order_lines_all ool, oe_order_headers_all ooh
       WHERE ool.flow_status_code = 'AWAITING_SHIPPING'
         AND ool.header_id = ooh.header_id
         AND ooh.order_type_id = 1202
         AND schedule_ship_date < TO_DATE ('24-Feb-2009');
/*************************************/
/* Main */
/*************************************/
BEGIN
   DELETE FROM test_adel;

   mo_global.set_policy_context ('S', 82);
   fnd_global.apps_initialize (1090, 21623, 660);
   fnd_client_info.set_org_context (82);
   fnd_file.put_line (fnd_file.LOG, 'P_header_id = ' || 40574);
   fnd_file.put_line (fnd_file.LOG, 'P_line_id = ' || 59116);
   l_step := 'Insert values into l_line_tbl';

   FOR i IN cur_so
   LOOP
      l_line_tbl (1) := oe_order_pub.g_miss_line_rec;
      l_line_tbl (1).ordered_quantity := 0;
      l_line_tbl (1).header_id := i.header_id;
      l_line_tbl (1).line_id := i.line_id;
      l_line_tbl (1).change_reason := 1;
      -- 'Test'; --'No reason provided';
      l_line_tbl (1).operation := oe_globals.g_opr_update;
      l_step := 'Run API OE_ORDER_PUB.PROCESS_ORDER';
      apps.oe_order_pub.process_order
                      (p_api_version_number          => 1.0,
                       p_init_msg_list               => fnd_api.g_true,
                       p_return_values               => fnd_api.g_true,
                       p_action_commit               => fnd_api.g_true,
                       x_return_status               => lx_return_status,
                       x_msg_count                   => lx_msg_count,
                       x_msg_data                    => lx_msg_data,
                       p_line_tbl                    => l_line_tbl,
                       x_header_rec                  => lx_header_rec,
                       x_header_val_rec              => lx_header_val_rec,
                       x_header_adj_tbl              => lx_header_adj_tbl,
                       x_header_adj_val_tbl          => lx_header_adj_val_tbl,
                       x_header_price_att_tbl        => lx_header_price_att_tbl,
                       x_header_adj_att_tbl          => lx_header_adj_att_tbl,
                       x_header_adj_assoc_tbl        => lx_header_adj_assoc_tbl,
                       x_header_scredit_tbl          => lx_header_scredit_tbl,
                       x_header_scredit_val_tbl      => lx_header_scredit_val_tbl,
                       x_header_payment_tbl          => lx_header_payment_tbl,
                       x_header_payment_val_tbl      => lx_header_payment_val_tbl,
                       x_line_tbl                    => lx_line_tbl,
                       x_line_val_tbl                => lx_line_val_tbl,
                       x_line_adj_tbl                => lx_line_adj_tbl,
                       x_line_adj_val_tbl            => lx_line_adj_val_tbl,
                       x_line_price_att_tbl          => lx_line_price_att_tbl,
                       x_line_adj_att_tbl            => lx_line_adj_att_tbl,
                       x_line_adj_assoc_tbl          => lx_line_adj_assoc_tbl,
                       x_line_scredit_tbl            => lx_line_scredit_tbl,
                       x_line_scredit_val_tbl        => lx_line_scredit_val_tbl,
                       x_line_payment_tbl            => lx_line_payment_tbl,
                       x_line_payment_val_tbl        => lx_line_payment_val_tbl,
                       x_lot_serial_tbl              => lx_lot_serial_tbl,
                       x_lot_serial_val_tbl          => lx_lot_serial_val_tbl,
                       x_action_request_tbl          => lx_action_request_tbl
                      );
     
      fnd_file.put_line (fnd_file.LOG, 'Return Status -' || lx_return_status);

      IF lx_return_status = 'S'
      THEN
         fnd_file.put_line (fnd_file.LOG, 'Success - Line cancelled');
      END IF;

      IF lx_msg_count > 0
      THEN
         DBMS_OUTPUT.put_line
                        ('Listing Errors .................for Order Number -');

         FOR l_index IN 1 .. lx_msg_count
         LOOP
            DBMS_OUTPUT.put_line
                        ('Listing Errors .................for Order Number -');
            v :=
               apps.oe_msg_pub.get (p_msg_index      => l_index,
                                    p_encoded        => apps.fnd_api.g_false
                                   );

            INSERT INTO test_adel
                        (error
                        )
                 VALUES (v
                        );
         END LOOP;
      END IF;
   END LOOP;
   if p_validate = 'Commit' then
     commit;
   else
   rollback;
   end if;
EXCEPTION
   WHEN OTHERS
   THEN
      l_err_msg := 'Error in script ETALCANCELCI.sql at: ' || l_step || ': ';
      l_err_msg := l_err_msg || SQLERRM;
      fnd_file.put_line (fnd_file.LOG, CHR (10) || l_err_msg);
      RAISE;
END xxom_cancel_line;

No comments:

Post a Comment