Friday, October 4, 2013

HOW to Use QP_PREQ_PUB.PRICE_REQUEST API to Price an Item

For more information please refer to the Metalink Note 759804.1

DECLARE
   p_line_tbl                                        qp_preq_grp.line_tbl_type;
   p_qual_tbl                                        qp_preq_grp.qual_tbl_type;
   p_line_attr_tbl                                   qp_preq_grp.line_attr_tbl_type;
   p_line_detail_tbl                                 qp_preq_grp.line_detail_tbl_type;
   p_line_detail_qual_tbl                            qp_preq_grp.line_detail_qual_tbl_type;
   p_line_detail_attr_tbl                            qp_preq_grp.line_detail_attr_tbl_type;
   p_related_lines_tbl                               qp_preq_grp.related_lines_tbl_type;
   p_control_rec                                     qp_preq_grp.control_record_type;
   x_line_tbl                                        qp_preq_grp.line_tbl_type;
   x_line_qual                                       qp_preq_grp.qual_tbl_type;
   x_line_attr_tbl                                   qp_preq_grp.line_attr_tbl_type;
   x_line_detail_tbl                                 qp_preq_grp.line_detail_tbl_type;
   x_line_detail_qual_tbl                            qp_preq_grp.line_detail_qual_tbl_type;
   x_line_detail_attr_tbl                            qp_preq_grp.line_detail_attr_tbl_type;
   x_related_lines_tbl                               qp_preq_grp.related_lines_tbl_type;
   x_return_status                                   VARCHAR2 (240);
   x_return_status_text                              VARCHAR2 (240);
   qual_rec                                          qp_preq_grp.qual_rec_type;
   line_attr_rec                                     qp_preq_grp.line_attr_rec_type;
   line_rec                                          qp_preq_grp.line_rec_type;
   detail_rec                                        qp_preq_grp.line_detail_rec_type;
   ldet_rec                                          qp_preq_grp.line_detail_rec_type;
   rltd_rec                                          qp_preq_grp.related_lines_rec_type;
   l_pricing_contexts_tbl                            qp_attr_mapping_pub.contexts_result_tbl_type;
   l_qualifier_contexts_tbl                          qp_attr_mapping_pub.contexts_result_tbl_type;
   v_line_tbl_cnt                                    INTEGER;
   i                                                 BINARY_INTEGER;
   l_version                                         VARCHAR2 (240);
   l_file_val                                        VARCHAR2 (60);
BEGIN
   oe_debug_pub.debug_on;
   oe_debug_pub.initialize;
   l_file_val                                               := oe_debug_pub.set_debug_mode ('FILE');
   oe_debug_pub.setdebuglevel (5);
   DBMS_OUTPUT.put_line ('File : ' || l_file_val);
   qp_attr_mapping_pub.build_contexts (p_request_type_code           => 'ONT'
                                     , p_pricing_type                => 'L'
                                     , x_price_contexts_result_tbl   => l_pricing_contexts_tbl
                                     , x_qual_contexts_result_tbl    => l_qualifier_contexts_tbl
                                      );
   v_line_tbl_cnt                                           := 1;
---- Control Record
   p_control_rec.pricing_event                              := 'LINE';   -- 'BATCH';
   p_control_rec.calculate_flag                             := 'Y';   --QP_PREQ_GRP.G_SEARCH_N_CALCULATE;
   p_control_rec.simulation_flag                            := 'N';
   p_control_rec.rounding_flag                              := 'Q';
   p_control_rec.manual_discount_flag                       := 'Y';
   p_control_rec.request_type_code                          := 'ONT';
   p_control_rec.temp_table_insert_flag                     := 'Y';
-------------------------
---- Line Records ---------
   line_rec.request_type_code                               := 'ONT';
   line_rec.line_id                                         := 2125125;   -- Order Line Id. This can be any thing for this script
   line_rec.line_index                                      := '1';   -- Request Line Index
   line_rec.line_type_code                                  := 'LINE';   -- LINE or ORDER(Summary Line)
   line_rec.pricing_effective_date                          := SYSDATE;   -- Pricing as of what date ?
   line_rec.active_date_first                               := SYSDATE;   -- Can be Ordered Date or Ship Date
   line_rec.active_date_second                              := SYSDATE;   -- Can be Ordered Date or Ship Date
   line_rec.active_date_first_type                          := 'NO TYPE';   -- ORD/SHIP
   line_rec.active_date_second_type                         := 'NO TYPE';   -- ORD/SHIP
   line_rec.line_quantity                                   := 1;   -- Ordered Quantity
   line_rec.line_uom_code                                   := 'Ea';   -- Ordered UOM Code
   line_rec.currency_code                                   := 'USD';   -- Currency Code
   line_rec.price_flag                                      := 'Y';   -- Price Flag can have 'Y' , 'N'(No pricing) , 'P'(Phase)
   p_line_tbl (1)                                           := line_rec;
---- Line Attribute Record
   line_attr_rec.line_index                                 := 1;
   line_attr_rec.pricing_context                            := 'ITEM';   --
   line_attr_rec.pricing_attribute                          := 'PRICING_ATTRIBUTE3';
   line_attr_rec.pricing_attr_value_from                    := 'ALL';
   line_attr_rec.validated_flag                             := 'N';
   p_line_attr_tbl (1)                                      := line_attr_rec;
   line_attr_rec.line_index                                 := 1;
   line_attr_rec.pricing_context                            := 'ITEM';   --
   line_attr_rec.pricing_attribute                          := 'PRICING_ATTRIBUTE1';
   line_attr_rec.pricing_attr_value_from                    := '307627';   -- INVENTORY ITEM ID
   line_attr_rec.validated_flag                             := 'N';
   p_line_attr_tbl (2)                                      := line_attr_rec;
---- Qualifier Attribute Record
   qual_rec.line_index                                      := 1;   -- Attributes for the above line. Attributes are attached with the line index
   qual_rec.qualifier_context                               := 'MODLIST';
   qual_rec.qualifier_attribute                             := 'QUALIFIER_ATTRIBUTE4';
   qual_rec.qualifier_attr_value_from                       := '54824';   -- PRICE LIST ID
   qual_rec.comparison_operator_code                        := '=';
   qual_rec.validated_flag                                  := 'Y';
   p_qual_tbl (1)                                           := qual_rec;
   qual_rec.line_index                                      := 1;
   qual_rec.qualifier_context                               := 'CUSTOMER';
   qual_rec.qualifier_attribute                             := 'QUALIFIER_ATTRIBUTE2';
   qual_rec.qualifier_attr_value_from                       := 16071;   -- CUSTOMER ID;
   qual_rec.comparison_operator_code                        := '=';
   qual_rec.validated_flag                                  := 'Y';
   p_qual_tbl (2)                                           := qual_rec;
   qp_preq_pub.price_request (p_line_tbl
                            , p_qual_tbl
                            , p_line_attr_tbl
                            , p_line_detail_tbl
                            , p_line_detail_qual_tbl
                            , p_line_detail_attr_tbl
                            , p_related_lines_tbl
                            , p_control_rec
                            , x_line_tbl
                            , x_line_qual
                            , x_line_attr_tbl
                            , x_line_detail_tbl
                            , x_line_detail_qual_tbl
                            , x_line_detail_attr_tbl
                            , x_related_lines_tbl
                            , x_return_status
                            , x_return_status_text
                             );
-- Return Status Information ..
   DBMS_OUTPUT.put_line ('Return Status text ' || x_return_status_text);
   DBMS_OUTPUT.put_line ('Return Status  ' || x_return_status);
   DBMS_OUTPUT.put_line ('+---------Information Returned to Caller---------------------+ ');
   DBMS_OUTPUT.put_line ('-------------Request Line Information-------------------');
   i                                                        := x_line_tbl.FIRST;
   IF i IS NOT NULL
   THEN
      LOOP
         DBMS_OUTPUT.put_line ('Line Index: ' || x_line_tbl (i).line_index);
         DBMS_OUTPUT.put_line ('Unit_price: ' || x_line_tbl (i).unit_price);
         DBMS_OUTPUT.put_line ('Percent price: ' || x_line_tbl (i).percent_price);
         DBMS_OUTPUT.put_line ('Adjusted Unit Price: ' || x_line_tbl (i).adjusted_unit_price);
         DBMS_OUTPUT.put_line ('Pricing status code: ' || x_line_tbl (i).status_code);
         DBMS_OUTPUT.put_line ('Pricing status text: ' || x_line_tbl (i).status_text);
         EXIT WHEN i = x_line_tbl.LAST;
         i                                                        := x_line_tbl.NEXT (i);
      END LOOP;
   END IF;
   DBMS_OUTPUT.put_line ('-----------Pricing Attributes Information-------------');
   i                                                        := x_line_detail_attr_tbl.FIRST;
   IF i IS NOT NULL
   THEN
      LOOP
         DBMS_OUTPUT.put_line ('Line detail Index ' || x_line_detail_attr_tbl (i).line_detail_index);
         DBMS_OUTPUT.put_line ('Context ' || x_line_detail_attr_tbl (i).pricing_context);
         DBMS_OUTPUT.put_line ('Attribute ' || x_line_detail_attr_tbl (i).pricing_attribute);
         DBMS_OUTPUT.put_line ('Value ' || x_line_detail_attr_tbl (i).pricing_attr_value_from);
         DBMS_OUTPUT.put_line ('Status Code ' || x_line_detail_attr_tbl (i).status_code);
         DBMS_OUTPUT.put_line ('---------------------------------------------------');
         EXIT WHEN i = x_line_detail_attr_tbl.LAST;
         i                                                        := x_line_detail_attr_tbl.NEXT (i);
      END LOOP;
   END IF;
   DBMS_OUTPUT.put_line ('-----------Qualifier Attributes Information-------------');
   i                                                        := x_line_detail_qual_tbl.FIRST;
   IF i IS NOT NULL
   THEN
      LOOP
         DBMS_OUTPUT.put_line ('Line Detail Index ' || x_line_detail_qual_tbl (i).line_detail_index);
         DBMS_OUTPUT.put_line ('Context ' || x_line_detail_qual_tbl (i).qualifier_context);
         DBMS_OUTPUT.put_line ('Attribute ' || x_line_detail_qual_tbl (i).qualifier_attribute);
         DBMS_OUTPUT.put_line ('Value ' || x_line_detail_qual_tbl (i).qualifier_attr_value_from);
         DBMS_OUTPUT.put_line ('Status Code ' || x_line_detail_qual_tbl (i).status_code);
         DBMS_OUTPUT.put_line ('---------------------------------------------------');
         EXIT WHEN i = x_line_detail_qual_tbl.LAST;
         i                                                        := x_line_detail_qual_tbl.NEXT (i);
      END LOOP;
   END IF;
   i                                                        := x_line_detail_tbl.FIRST;
   DBMS_OUTPUT.put_line ('------------Price List/Discount Information------------');
   IF i IS NOT NULL
   THEN
      LOOP
         DBMS_OUTPUT.put_line ('Line Index: ' || x_line_detail_tbl (i).line_index);
         DBMS_OUTPUT.put_line ('Line Detail Index: ' || x_line_detail_tbl (i).line_detail_index);
         DBMS_OUTPUT.put_line ('Line Detail Type:' || x_line_detail_tbl (i).line_detail_type_code);
         DBMS_OUTPUT.put_line ('List Header Id: ' || x_line_detail_tbl (i).list_header_id);
         DBMS_OUTPUT.put_line ('List Line Id: ' || x_line_detail_tbl (i).list_line_id);
         DBMS_OUTPUT.put_line ('List Line Type Code: ' || x_line_detail_tbl (i).list_line_type_code);
         DBMS_OUTPUT.put_line ('Adjustment Amount : ' || x_line_detail_tbl (i).adjustment_amount);
         DBMS_OUTPUT.put_line ('Line Quantity : ' || x_line_detail_tbl (i).line_quantity);
         DBMS_OUTPUT.put_line ('Operand Calculation Code: ' || x_line_detail_tbl (i).operand_calculation_code);
         DBMS_OUTPUT.put_line ('Operand value: ' || x_line_detail_tbl (i).operand_value);
         DBMS_OUTPUT.put_line ('Automatic Flag: ' || x_line_detail_tbl (i).automatic_flag);
         DBMS_OUTPUT.put_line ('Override Flag: ' || x_line_detail_tbl (i).override_flag);
         DBMS_OUTPUT.put_line ('status_code: ' || x_line_detail_tbl (i).status_code);
         DBMS_OUTPUT.put_line ('status text: ' || x_line_detail_tbl (i).status_text);
         DBMS_OUTPUT.put_line ('-------------------------------------------');
         EXIT WHEN i = x_line_detail_tbl.LAST;
         i                                                        := x_line_detail_tbl.NEXT (i);
      END LOOP;
   END IF;
   DBMS_OUTPUT.put_line ('--------------Related Lines Information for Price Breaks/Service Items---------------');
   i                                                        := x_related_lines_tbl.FIRST;
   IF i IS NOT NULL
   THEN
      LOOP
         DBMS_OUTPUT.put_line ('Line Index :' || x_related_lines_tbl (i).line_index);
         DBMS_OUTPUT.put_line ('Line Detail Index: ' || x_related_lines_tbl (i).line_detail_index);
         DBMS_OUTPUT.put_line ('Relationship Type Code: ' || x_related_lines_tbl (i).relationship_type_code);
         DBMS_OUTPUT.put_line ('Related Line Index: ' || x_related_lines_tbl (i).related_line_index);
         DBMS_OUTPUT.put_line ('Related Line Detail Index: ' || x_related_lines_tbl (i).related_line_detail_index);
         DBMS_OUTPUT.put_line ('Status Code: ' || x_related_lines_tbl (i).status_code);
         EXIT WHEN i = x_related_lines_tbl.LAST;
         i                                                        := x_related_lines_tbl.NEXT (i);
      END LOOP;
   END IF;
END;  

Wednesday, October 2, 2013

Query to get the Concatenated Line Number on the Sales Order



SELECT   oh.org_id
       , order_number
       ,    ol.line_number
         || '.'
         || ol.shipment_number
         || '.'
         || ol.option_number
         || '.'
         || ol.component_number
         || '.'
         || ol.service_number line_number
    FROM oe_order_lines_all ol
       , oe_order_headers_all oh
   WHERE oh.header_id = ol.header_id
     AND oh.order_number = '&Order_number'
ORDER BY ol.line_number
       , ol.shipment_number
       , ol.option_number
       , ol.component_number
       , ol.service_number

Friday, September 27, 2013

How to handle the Exception in FORALL statement 11G Feature




The below mentioned way of handling the exceptions for FORALL statement is available in Oracle 11g DB version.

-- Temporary table for this example:
CREATE TABLE emp_temp AS SELECT * FROM employees;

DECLARE
   TYPE empid_tab IS TABLE OF employees.employee_id%TYPE;

   emp_sr                                            empid_tab;
-- Exception handler for ORA-24381:
   ERRORS                                            NUMBER;
   dml_errors                                        EXCEPTION;
   PRAGMA EXCEPTION_INIT (dml_errors, -24381);
BEGIN
   SELECT employee_id
   BULK COLLECT INTO emp_sr
     FROM emp_temp
    WHERE hire_date < '30-DEC-94';

-- Add '_SR' to job_id of most senior employees:
   FORALL i IN emp_sr.FIRST .. emp_sr.LAST SAVE EXCEPTIONS
      UPDATE emp_temp
      SET job_id = job_id || '_SR'
      WHERE  emp_sr (i) = emp_temp.employee_id;
-- If errors occurred during FORALL SAVE EXCEPTIONS,
-- a single exception is raised when the statement completes.
EXCEPTION
-- Figure out what failed and why
   WHEN dml_errors
   THEN
      ERRORS                                                   := SQL%BULK_EXCEPTIONS.COUNT;
      DBMS_OUTPUT.put_line ('Number of statements that failed: ' || ERRORS);

      FOR i IN 1 .. ERRORS
      LOOP
         DBMS_OUTPUT.put_line ('Error #' || i || ' occurred during ' || 'iteration #'
                               || SQL%BULK_EXCEPTIONS (i).ERROR_INDEX
                              );
         DBMS_OUTPUT.put_line ('Error message is ' || SQLERRM (-SQL%BULK_EXCEPTIONS (i).ERROR_CODE));
      END LOOP;
END;
/