Monday, 31 October 2011

JobCode_Cost_

Select MATCH_OPTION from po_line_locations_all where po_line_id=137873
Select * from pa_projects_all
Select * from all_objects where object_name like '%PROJECTS%'
Select * from FND_FLEX_VALUES_VL where flex_value_set_id ='1005233'
Select * from fnd_flex_values where flex_value_id=33584
Select * from fnd_flex_values_tl where flex_value_id=33584
Select * from gl_code_combinations_kfv where segment6='103P' and segment1='42'
/* Formatted on 31-08-2011 15:39:43 (QP5 v5.115.810.9015) */
/* Formatted on 31-08-2011 15:40:41 (QP5 v5.115.810.9015) */
SELECT   DISTINCT hou.name Operating_unit,
                  glcc.segment6 job_code,
                  aia.invoice_num,
                  aia.INVOICE_DATE,
                  aia.INVOICE_TYPE_LOOKUP_CODE,
                  aia.GL_DATE,
                  aia.invoice_amount,
                  glcc.CONCATENATED_SEGMENTS Acct_Code
  FROM   gl_code_combinations_kfv glcc,
         ap_invoices_all aia,
         ap_invoice_distributions_All aid,
         hr_operating_units hou
 WHERE       aia.set_of_books_id = 5
         AND aid.DIST_CODE_COMBINATION_ID = glcc.CODE_COMBINATION_ID
         AND aia.invoice_id = aid.invoice_id
         AND aia.org_id = aid.org_id
         AND hou.organization_id = aia.org_id
         AND glcc.segment6 IN
                  ('103P',
                   '111P ',
                   '114P ',
                   '112P ',
                   '101P',
                   '102P',
                   '104P',
                   '105P',
                   '106P',
                   '106P',
                   '110P',
                   '104P',
                   '105P',
                   '109P',
                   '55CC',
                   '54CC',
                   '63CC',
                   '57CC',
                   '58CC',
                   '61CC',
                   '62CC',
                   '59CC',
                   '103P',
                   '50CC')

Item_Updation_Qry

UPDATE   mtl_system_items_b
   SET   INVENTORY_ITEM_FLAG = 'N',
         STOCK_ENABLED_FLAG = 'N',
         MTL_TRANSACTIONS_ENABLED_FLAG = 'N',
         REVISION_QTY_CONTROL_CODE = '1',
         COSTING_ENABLED_FLAG = 'N',
         INVENTORY_ASSET_FLAG = 'N',
         DEFAULT_INCLUDE_IN_ROLLUP_FLAG = 'N'
 WHERE   SEGMENT1 IN
               ('42000001'
                )

Create_Ap_Invoice

CREATE OR REPLACE PROCEDURE create_invoice (errcode   OUT VARCHAR2,
                                            errmsg    OUT VARCHAR2)
IS
   l_err_msg                    VARCHAR2 (1000);
   l_err_code                   VARCHAR2 (1000);
   l_invoice_num                VARCHAR2 (100);
   l_invoice_type_lookup_code   VARCHAR2 (100);
   l_vendor_id                  NUMBER;
   l_vendor_site_id             NUMBER;
   l_invoice_amount             NUMBER;
   l_invoice_currency_code      VARCHAR2 (10);
   l_source                     VARCHAR2 (240);
   l_org_id                     NUMBER;
   l_orgn_id                    NUMBER;
   l_entry_date                 DATE;
   l_form_number                NUMBER;
   l_group_id                   NUMBER;
   l_goods_received_date        DATE;
   l_currency_code              VARCHAR2 (10);
   l_po_number                  VARCHAR2 (40);
   l_amount                     NUMBER;
   counter                      NUMBER;
   l_ship_to_location_id        NUMBER;
   l_code_combination_id        NUMBER;
   l_term_id                    NUMBER;
   l_dist_code_comb_id          NUMBER;
   v_count                      NUMBER;
   l_error_flag                 VARCHAR2 (1);
   l_error_details              VARCHAR2 (250);
   CURSOR headers
   IS
      SELECT   * FROM xx_temp_inv_hdr;
   CURSOR lines (p_invoice_id NUMBER)
   IS
      SELECT   *
        FROM   xx_temp_inv_line
       WHERE   invoice_number = p_invoice_id;
BEGIN
   -- mo_global.init('PO');
   -- mo_global.SET_POLICY_CONTEXT('',88);
   l_err_msg := NULL;
   l_amount := 0;
   v_count := 0;
   FOR hdr_rec IN headers
   LOOP
      BEGIN
         SELECT   COUNT ( * )
           INTO   v_count
           FROM   ap_invoices_all
          WHERE   invoice_num = hdr_rec.invoice_number;
         IF v_count > 0
         THEN
            DBMS_OUTPUT.put_line('Invoice No already exists -->'
                                 || v_count
                                 || SQLERRM);
         ELSE
            BEGIN
               SELECT   vendor_id
                 INTO   l_vendor_id
                 FROM   ap_suppliers
                WHERE   vendor_name = hdr_rec.supplier_name; --'LOGWELL FORGE LTD.';
            EXCEPTION
               WHEN NO_DATA_FOUND
               THEN
                  DBMS_OUTPUT.put_line ('Vendor id is not found' || SQLERRM);
            END;
            IF l_vendor_id IS NOT NULL
            THEN
               DBMS_OUTPUT.put_line ('Vendor id is not found' || SQLERRM);
               BEGIN
                  SELECT   vendor_site_id
                    INTO   l_vendor_site_id
                    FROM   ap_supplier_sites_all
                   WHERE   vendor_site_code = hdr_rec.supplier_site_name
                           AND vendor_id = l_vendor_id;
                  IF l_vendor_site_id IS NOT NULL
                  THEN
                     DBMS_OUTPUT.put_line (
                        'Vendor id is not found' || SQLERRM
                     );
                     BEGIN
                        SELECT   code_combination_id
                          INTO   l_code_combination_id
                          FROM   gl_code_combinations_kfv
                         WHERE   concatenated_segments =
                                    hdr_rec.liability_account;
                        IF l_code_combination_id IS NOT NULL
                        THEN
                           DBMS_OUTPUT.put_line (
                              'Vendor id is not found' || SQLERRM
                           );
                           BEGIN
                              SELECT   term_id
                                INTO   l_term_id
                                FROM   ap_terms_tl
                               WHERE   NAME =
                                          '60 DAYS AFTER RECEIPT OF MATERIAL';
                              IF l_term_id IS NOT NULL
                              THEN
                                 DBMS_OUTPUT.put_line (
                                    'Vendor id is not found' || SQLERRM
                                 );
                                 DBMS_OUTPUT.put_line (
                                    'start header loop found'
                                 );
                                 INSERT INTO ap_invoices_interface (
                                                                       invoice_id,
                                                                       invoice_type_lookup_code,
                                                                       invoice_num,
                                                                       invoice_date,
                                                                       gl_date,
                                                                       vendor_id,
                                                                       vendor_num,
                                                                       vendor_site_id,
                                                                       invoice_amount,
                                                                       invoice_currency_code,
                                                                       description,
                                                                       terms_id,
                                                                       payment_method_code,
                                                                       doc_category_code,
                                                                       accts_pay_code_combination_id,
                                                                       goods_received_date,
                                                                       org_id,
                                                                       SOURCE,
                                                                       last_update_date,
                                                                       last_updated_by,
                                                                       creation_date,
                                                                       created_by
                                            )
                                   VALUES   (ap_invoices_interface_s.NEXTVAL, -- invoice_id
                                             hdr_rec.invoice_type,
                                             -- type
                                             hdr_rec.invoice_number,
                                             hdr_rec.invoice_date,
                                             hdr_rec.gl_date,
                                             l_vendor_id,
                                             hdr_rec.supplier_number,
                                             l_vendor_site_id,
                                             hdr_rec.invoice_amount,
                                             hdr_rec.invoice_currency,
                                             hdr_rec.invoice_description,
                                             l_term_id,
                                             hdr_rec.payment_method,
                                             hdr_rec.document_category,
                                             l_code_combination_id,
                                             hdr_rec.good_receiving_date,
                                             246,
                                             'OPEN BALANCE',
                                             SYSDATE,
                                             fnd_profile.VALUE ('USER_ID'),
                                             SYSDATE,
                                             fnd_profile.VALUE ('USER_ID'));
                                 fnd_file.put_line (
                                    fnd_file.LOG,
                                    'Invoice Num ' || hdr_rec.invoice_number
                                 );
                                 counter := 1;
                                 DBMS_OUTPUT.put_line (
                                    'end header loop found'
                                 );
                                 FOR rec IN lines (hdr_rec.invoice_number)
                                 LOOP
                                    DBMS_OUTPUT.put_line (
                                       'start line loop found' || SQLERRM
                                    );
                                    BEGIN
                                       SELECT   code_combination_id
                                         INTO   l_dist_code_comb_id
                                         FROM   gl_code_combinations_kfv
                                        WHERE   concatenated_segments =
                                                   rec.ACCOUNT;
                                    EXCEPTION
                                       WHEN NO_DATA_FOUND
                                       THEN
                                          DBMS_OUTPUT.put_line('dist code combination_id is not found'
                                                               || SQLERRM);
                                    END;
                                    DBMS_OUTPUT.put_line('start insert line loop found'
                                                         || SQLERRM);
                                    INSERT INTO ap_invoice_lines_interface (
                                                                               invoice_id,
                                                                               invoice_line_id,
                                                                               line_number,
                                                                               line_type_lookup_code,
                                                                               amount,
                                                                               dist_code_combination_id,
                                                                               description,
                                                                               org_id,
                                                                               last_update_date,
                                                                               last_updated_by,
                                                                               creation_date,
                                                                               created_by
                                               )
                                      VALUES   (
                                                   ap_invoices_interface_s.CURRVAL,
                                                   ap_invoice_lines_interface_s.NEXTVAL,
                                                   rec.line_number,
                                                   rec.TYPE,
                                                   rec.amount,
                                                   l_dist_code_comb_id,
                                                   rec.description,
                                                   246,
                                                   SYSDATE,
                                                   fnd_profile.VALUE (
                                                      'USER_ID'
                                                   ),
                                                   SYSDATE,
                                                   fnd_profile.VALUE (
                                                      'USER_ID'
                                                   )
                                               );
                                    DBMS_OUTPUT.put_line (
                                       'end line loop found' || SQLERRM
                                    );
                                    DBMS_OUTPUT.put_line('Invoice Line Num '
                                                         || rec.line_number
                                                         || ' Line Amount: '
                                                         || rec.amount);
                                    fnd_file.put_line (
                                       fnd_file.LOG,
                                          'Invoice Line Num '
                                       || rec.line_number
                                       || ' Line Amount: '
                                       || rec.amount
                                    );
                                    counter := counter + 1;
                                 END LOOP;
                              ELSE
                                 DBMS_OUTPUT.put_line (
                                    'Vendor id is not found' || SQLERRM
                                 );
                              END IF;
                           EXCEPTION
                              WHEN NO_DATA_FOUND
                              THEN
                                 DBMS_OUTPUT.put_line (
                                    'Term name is not found' || SQLERRM
                                 );
                           END;
                        ELSE
                           DBMS_OUTPUT.put_line (
                              'Vendor id is not found' || SQLERRM
                           );
                        END IF;
                     --'01-SSC-001-24106-0000-000-0000-000';
                     EXCEPTION
                        WHEN NO_DATA_FOUND
                        THEN
                           DBMS_OUTPUT.put_line (
                              'Account Number is not found' || SQLERRM
                           );
                     END;
                  ELSE
                     DBMS_OUTPUT.put_line (
                        'Vendor id is not found' || SQLERRM
                     );
                  END IF;
               EXCEPTION
                  WHEN NO_DATA_FOUND
                  THEN
                     DBMS_OUTPUT.put_line (
                        'Vendor site id is not found' || SQLERRM
                     );
               END;
            ELSE
               DBMS_OUTPUT.put_line ('Vendor id is not found' || SQLERRM);
            END IF;
         END IF;
      END;
   --DBMS_OUTPUT.put_line ('INVOICE NUM v_count' || v_count);
   END LOOP;
   fnd_file.put_line (fnd_file.LOG, lines%ROWCOUNT || ' Rows Inserted');
   fnd_file.put_line (fnd_file.output, 'ap invoice lines are valid');
   fnd_file.put_line (fnd_file.LOG, headers%ROWCOUNT || ' Rows Inserted');
   fnd_file.put_line (fnd_file.output, 'ap invoice headers are valid');

   COMMIT;
END create_invoice;
/

Cost Centre querie

/* Formatted on 31-08-2011 18:17:05 (QP5 v5.115.810.9015) */
SELECT   DISTINCT hou.name Operating_unit,
                  glcc.segment6 job_code,
                  aia.invoice_num,
                  aia.INVOICE_DATE,
                  aia.INVOICE_TYPE_LOOKUP_CODE,
                  aia.GL_DATE,
                  aia.invoice_amount,
                  aia.DOC_SEQUENCE_VALUE DOCUMENT_NO,
                  ACA.CHECK_ID,
                  ACA.CHECK_NUMBER,
                  ACA.CHECK_DATE,
                  glcc.CONCATENATED_SEGMENTS Acct_Code
  FROM   gl_code_combinations_kfv glcc,
         ap_invoices_all aia,
         ap_invoice_distributions_All aid,
         hr_operating_units hou,
         ap_invoice_payments_all aip,
         ap_checks_all aca
 WHERE       aia.set_of_books_id = 5
         AND aid.DIST_CODE_COMBINATION_ID = glcc.CODE_COMBINATION_ID
         AND aia.invoice_id = aid.invoice_id
         AND aia.org_id = aid.org_id
         AND hou.organization_id = aia.org_id
         AND aip.INVOICE_ID = aia.INVOICE_ID
         AND aca.check_id = aip.check_id
         AND glcc.segment6 IN
                  ('103P',
                   '111P ',
                   '114P ',
                   '112P ',
                   '101P',
                   '102P',
                   '104P',
                   '105P',
                   '106P',
                   '106P',
                   '110P',
                   '104P',
                   '105P',
                   '109P',
                   '55CC',
                   '54CC',
                   '63CC',
                   '57CC',
                   '58CC',
                   '61CC',
                   '62CC',
                   '59CC',
                   '103P',
                   '50CC')

THRESHOLD_FROM_DATA_UPDATION_QRY

/* Formatted on 14-09-2011 17:34:37 (QP5 v5.115.810.9015) */
CREATE TABLE JAI_AP_TDS_THHOLD_HDRS_BKUP AS SELECT * FROM Jai_Ap_Tds_Thhold_Hdrs;
CREATE TABLE JAI_AP_TDS_THHOLD_TYPES_BKUP AS SELECT * FROM JAI_AP_TDS_THHOLD_TYPES;

SELECT   *
  FROM   Jai_Ap_Tds_Thhold_Hdrs
 WHERE   threshold_hdr_id = :P_HEADER_ID;

SELECT   *
  FROM   JAI_AP_TDS_THHOLD_TYPES
 WHERE   threshold_hdr_id = :P_HEADER_ID;

UPDATE   JAI_AP_TDS_THHOLD_TYPES
   SET   from_date = '01-APR-2011'
 WHERE   threshold_hdr_id = :P_HEADER_ID;

PO_REQ_UPDATE_QRY

/* Formatted on 15-09-2011 10:13:09 (QP5 v5.115.810.9015) */
select SEGMENT1, ORG_ID from po_requisition_headers_all where  AUTHORIZATION_STATUS  =
      'APPROVED'
CREATE TABLE PO_REQUISITION_LINES_ALL_BKPUP
AS
   SELECT   * FROM po_requisition_lines_all
SELECT   REQS_IN_POOL_FLAG ,   ORG_ID
  FROM   po_requisition_lines_all
 WHERE   REQUISITION_HEADER_ID IN
               (SELECT   REQUISITION_HEADER_ID
                  FROM   po_requisition_headers_all
                 WHERE   AUTHORIZATION_STATUS = 'APPROVED')
                 and REQS_IN_POOL_FLAG IS NOT NULL
                
UPDATE   po_requisition_lines_all
   SET   REQS_IN_POOL_FLAG = 'Y'
 WHERE   REQUISITION_HEADER_ID IN
               (SELECT   REQUISITION_HEADER_ID
                  FROM   po_requisition_headers_all
                 WHERE   AUTHORIZATION_STATUS = 'APPROVED')
         AND REQS_IN_POOL_FLAG IS NULL
                
 

PO_DELIVERY_TERMS_UPD_QRY_v1.0

/* Formatted on 17-09-2011 21:58:33 (QP5 v5.115.810.9015) */
SELECT   FLV1.MEANING Delivery_Terms,
         FLV1.LOOKUP_CODE,
         FLV2.MEANING Freight,
         FLV2.DESCRIPTION,
         PH.SHIP_VIA_LOOKUP_CODE Carrier
  FROM   po_headers_all ph, FND_LOOKUP_VALUES FLV1, FND_LOOKUP_VALUES FLV2
 WHERE       FLV1.LOOKUP_CODE(+) = PH.FOB_LOOKUP_CODE
         AND FLV2.LOOKUP_CODE(+) = PH.FREIGHT_TERMS_LOOKUP_CODE
         AND FLV1.LOOKUP_TYPE(+) = 'FOB'
         AND FLV2.LOOKUP_TYPE(+) = 'FREIGHT TERMS'
         and FLV1.MEANING is not null and FLV2.MEANING is not null
        
Due
INCLUSIVE
PAID BY YOU
Paid
TOPAY
SELECT DISTINCT  SHIP_VIA_LOOKUP_CODE
  FROM   po_headers_All
 WHERE   segment1 IN (SELECT   po_no FROM XX_186_PO_FOB) AND org_id = 90
SELECT   FREIGHT_TERMS_LOOKUP_CODE, SHIP_VIA_LOOKUP_CODE, FOB_LOOKUP_CODE
  FROM   po_headers_All
 WHERE   segment1 IN (SELECT   po_no FROM XX_186_PO_FOB) AND org_id = 90 --and FOB_LOOKUP_CODE <> 'Ex Works'

 /* Formatted on 17-09-2011 22:07:00 (QP5 v5.115.810.9015) */
/* Formatted on 17-09-2011 22:07:27 (QP5 v5.115.810.9015) */
UPDATE   po_headers_All
   SET   FOB_LOOKUP_CODE = 'F.O.R  BALLARPUR'
 WHERE       FOB_LOOKUP_CODE = 'FOR  BALLARPUR'
         AND segment1 IN (SELECT   po_no FROM XX_186_PO_FOB)
         AND org_id = 90

    NEW
-----------
SELECT   FLV1.MEANING Delivery_Terms,
         ph.SEGMENT1 po_num,
        -- ph.org_id,
         ood.ORGANIZATION_NAME,
         ood.OPERATING_UNIT,
         FLV1.LOOKUP_CODE,
         FLV2.MEANING Freight,
         FLV2.DESCRIPTION,
         PH.SHIP_VIA_LOOKUP_CODE Carrier
  FROM   po_headers_all ph, FND_LOOKUP_VALUES FLV1, FND_LOOKUP_VALUES FLV2,org_organization_definitions ood
 WHERE       FLV1.LOOKUP_CODE(+) = PH.FOB_LOOKUP_CODE
         AND FLV2.LOOKUP_CODE(+) = PH.FREIGHT_TERMS_LOOKUP_CODE
         AND ood.OPERATING_UNIT(+) = ph.org_id
         AND FLV1.LOOKUP_TYPE(+) = 'FOB'
         AND FLV2.LOOKUP_TYPE(+) = 'FREIGHT TERMS'
         and FLV1.MEANING is not null and FLV2.MEANING is not null
        

PO_DELIVERY_TERMS_UPD_QRY

/* Formatted on 28-09-2011 11:57:57 (QP5 v5.115.810.9015) */
DECLARE
   CURSOR c1
   IS
      SELECT   po.FREIGHT_TERMS_LOOKUP_CODE,
               po.SHIP_VIA_LOOKUP_CODE,
               po.FOB_LOOKUP_CODE,
               map.OLD_R12_TERMID,
               map.TERM_NAME,
               map.NEW_CARRIER,
               map.NEW_FREIGHT,
               map.DT_LOOKUP_CODE,
               map.po_no,
               po.org_id,
               map.NEW_R12_TERM_NAME,
               map.NEW_R12_TERM_ID,
               po.terms_id
        FROM   xx_backlog_po_updation map, PO_HEADERS_ALL po
       WHERE   map.po_no = po.segment1 and map.org_id=po.org_id;                  --AND po.org_id = 90;
BEGIN
   FOR i IN c1
   LOOP
      UPDATE   PO_HEADERS_ALL
         SET   --FREIGHT_TERMS_LOOKUP_CODE = i.NEW_FREIGHT,
               --SHIP_VIA_LOOKUP_CODE = i.NEW_CARRIER,
               --FOB_LOOKUP_CODE = i.DT_LOOKUP_CODE,
               TERMS_ID = i.NEW_R12_TERM_ID
       WHERE   segment1 = i.po_no AND org_id = i.org_id;
   END LOOP;
END;

PAYMENT_TERMS_UPDATION_R12

select * from po_headers_all
/* Formatted on 17-09-2011 19:25:32 (QP5 v5.115.810.9015) */
CREATE TABLE PO_HEADERS_ALL_17SEP11
AS
   SELECT   * FROM po_headers_all
  
  
CREATE TABLE XX_186_PO_TERMS
(
   PO_NO          VARCHAR2 (10),
   R11_TERMS_ID   NUMBER,
   R11_TERMS    VARCHAR2(50),
   R12_TERMS_ID   NUMBER,
   R12_TERMS    VARCHAR2(50)
)

/* Formatted on 17-09-2011 19:46:51 (QP5 v5.115.810.9015) */
UPDATE   po_headers_all POH
   SET   POH.TERMS_ID =
            (SELECT   R12_TERMS_ID
               FROM   XX_186_PO_TERMS
              WHERE   PO_NO = POH.SEGMENT1 AND POH.ORG_ID = 90)
SELECT R12_TERMS_ID FROM XX_186_PO_TERMS , po_headers_all POH WHERE  PO_NO=POH.SEGMENT1
SELECT TERMS_ID FROM PO_HEADERS_ALL WHERE SEGMENT1 IN ( SELECT PO_NO FROM XX_186_PO_TERMS)
AND ORG_ID IN ( 90)
/* Formatted on 17-09-2011 19:50:53 (QP5 v5.115.810.9015) */
/* Formatted on 17-09-2011 19:51:13 (QP5 v5.115.810.9015) */
UPDATE   po_headers_all POH
   SET   POH.TERMS_ID =
            (SELECT   R12_TERMS_ID
               FROM   XX_186_PO_TERMS
              WHERE   PO_NO = POH.SEGMENT1 AND POH.ORG_ID = 90)
 WHERE   POH.SEGMENT1 IN (SELECT   PO_NO FROM XX_186_PO_TERMS)
 and org_id =90
        

ITEM_INSPECTION_REQ_UPD_QRY_18SEP11

SELECT   pol.RECEIVING_ROUTING_ID , poh.segment1 , ood.ORGANIZATION_CODE
  FROM   po_line_locations_all pol, po_headers_all poh, org_organization_definitions ood
 WHERE  
 pol.po_header_id=poh.po_header_id and
 ood.ORGANIZATION_ID=pol.SHIP_TO_ORGANIZATION_ID and
 pol.po_line_id IN
               (SELECT   po_line_id
                  FROM   po_lines_all
                 WHERE   item_id IN
                               (SELECT   inventory_item_id
                                  FROM   mtl_system_items_b msi,
                                         xx_item_map map
                                 WHERE   MAP.ITM_NEW_GRP =
                                            SUBSTR (msi.segment1, 1, 2)
                                         AND map.ITM_CAT = 'MRO'))
                                         and RECEIVING_ROUTING_ID =3 --3
                                         and length(poh.segment1)=8

UPDATE   po_line_locations_all
   SET   RECEIVING_ROUTING_ID = 2
 WHERE   po_line_id IN
               (SELECT   pol.po_line_id
                  FROM   po_line_locations_all pol,
                         po_headers_all poh,
                         org_organization_definitions ood
                 WHERE   pol.po_header_id = poh.po_header_id
                         AND ood.ORGANIZATION_ID =
                               pol.SHIP_TO_ORGANIZATION_ID
                         AND pol.po_line_id IN
                                  (SELECT   po_line_id
                                     FROM   po_lines_all
                                    WHERE   item_id IN
                                                  (SELECT   inventory_item_id
                                                     FROM   mtl_system_items_b msi,
                                                            xx_item_map map
                                                    WHERE   MAP.ITM_NEW_GRP =
                                                               SUBSTR (
                                                                  msi.segment1,
                                                                  1,
                                                                  2
                                                               )
                                                            AND map.ITM_CAT =
                                                                  'MRO'))
                         AND RECEIVING_ROUTING_ID = 3
                         AND LENGTH (poh.segment1) = 8)

ITEM_INSPECTION_REQ_UPD_QRY

/* Formatted on 16-09-2011 12:15:37 (QP5 v5.115.810.9015) */
  SELECT   msi.inventory_item_id,
           msi.segment1 item_code,
           msi.organization_id,
           ood.ORGANIZATION_NAME,
           msi.INSPECTION_REQUIRED_FLAG
    FROM   mtl_system_items_b msi, org_organization_definitions ood
   WHERE   SUBSTR (msi.Segment1, 1, 2) IN (SELECT   ITM_GRP
                                             FROM   xx_item_map
                                            WHERE   itm_cat = 'MRO')
GROUP BY   msi.inventory_item_id,
           msi.segment1,
           msi.organization_id,
           ood.ORGANIZATION_NAME,
           msi.INSPECTION_REQUIRED_FLAG
--Select * from xx_item_map where itm_cat='MRO'


/* Formatted on 16-09-2011 12:18:04 (QP5 v5.115.810.9015) */
UPDATE   mtl_system_items_b
   SET   INSPECTION_REQUIRED_FLAG = 'Y'
 WHERE   INVENTORY_ITEM_ID IN
               (SELECT   inventory_item_id
                  FROM   (  SELECT   msi.inventory_item_id,
                                     msi.segment1 item_code,
                                     msi.organization_id,
                                     ood.ORGANIZATION_NAME,
                                     msi.INSPECTION_REQUIRED_FLAG
                              FROM   mtl_system_items_b msi,
                                     org_organization_definitions ood
                             WHERE   SUBSTR (msi.Segment1, 1, 2) IN
                                           (SELECT   ITM_GRP
                                              FROM   xx_item_map
                                             WHERE   itm_cat = 'MRO')
                          GROUP BY   msi.inventory_item_id,
                                     msi.segment1,
                                     msi.organization_id,
                                     ood.ORGANIZATION_NAME,
                                     msi.INSPECTION_REQUIRED_FLAG))
                                    
SELECT   RECEIVING_ROUTING_ID, SHIP_TO_ORGANIZATION_ID
  FROM   po_line_locations_all
 WHERE   SHIP_TO_ORGANIZATION_ID IN (SELECT   organization_id
                               FROM   org_organization_definitions
                              WHERE   organization_code LIKE '%C%' OR organization_code LIKE '%E%' OR  organization_code LIKE '%S%'
                              OR  organization_code LIKE '%I%')
                              AND  RECEIVING_ROUTING_ID not in (1, 2)
Select * from rcv_routing_headers
Select * from org_organization_definitions where organization_id=134
SELECT   organization_id , organization_code
                               FROM   org_organization_definitions
                              WHERE   organization_code LIKE '%C%' OR organization_code LIKE '%E%' OR  organization_code LIKE '%S%'
                              OR  organization_code LIKE '%I%'
                             
                             
/* Formatted on 16-09-2011 18:04:44 (QP5 v5.115.810.9015) */
create table PO_LINE_LOCATIONS_ALL_16SEP11 as  Select * from po_line_locations_all
UPDATE   po_line_locations_all
   SET   RECEIVING_ROUTING_ID = 2
 WHERE   SHIP_TO_ORGANIZATION_ID IN
               (SELECT   organization_id
                  FROM   org_organization_definitions
                 WHERE      organization_code LIKE '%C%'
                         OR organization_code LIKE '%E%'
                         OR organization_code LIKE '%S%'
                         OR organization_code LIKE '%I%')
         AND RECEIVING_ROUTING_ID NOT IN (1, 2)
        
SELECT   POH.SEGMENT1 PO_NO,
         MSI.SEGMENT1 ITEM_CODE,
         POLL.RECEIVING_ROUTING_ID,
         RRH.ROUTING_NAME,
         POLL.SHIP_TO_ORGANIZATION_ID ORGANIZATION_ID,
         OOD.ORGANIZATION_NAME,
         OOD.ORGANIZATION_CODE,
         POH.AUTHORIZATION_STATUS
  FROM   po_line_locations_all POLL,
         PO_LINES_ALL PLA,
         MTL_SYSTEM_ITEMS_B MSI,
         PO_HEADERS_ALL POH,
         ORG_ORGANIZATION_DEFINITIONS OOD,
         RCV_ROUTING_HEADERS RRH
 WHERE       POLL.PO_LINE_ID = PLA.PO_LINE_ID
         AND POH.PO_HEADER_ID = PLA.PO_HEADER_ID
         AND POH.PO_HEADER_ID = POLL.PO_HEADER_ID
         AND POH.ORG_ID = PLA.ORG_ID
         AND POLL.ORG_ID = PLA.ORG_ID
         AND MSI.INVENTORY_ITEM_ID = PLA.ITEM_ID
         AND POLL.SHIP_TO_ORGANIZATION_ID = MSI.ORGANIZATION_ID
         AND OOD.ORGANIZATION_ID=MSI.ORGANIZATION_ID
         AND RRH.ROUTING_HEADER_ID=POLL.RECEIVING_ROUTING_ID
         AND POH.ORG_ID IN (90, 91)
         AND POLL.SHIP_TO_ORGANIZATION_ID IN
                  (SELECT   organization_id
                     FROM   org_organization_definitions
                    WHERE      organization_code LIKE '%C%'
                            OR organization_code LIKE '%E%'
                            OR organization_code LIKE '%S%'
                            OR organization_code LIKE '%I%')
         AND POLL.RECEIVING_ROUTING_ID NOT IN (1, 2)
         and length(POH.SEGMENT1)=8
        
/* Formatted on 17-09-2011 16:53:33 (QP5 v5.115.810.9015) */
UPDATE   po_line_locations_all
   SET   RECEIVING_ROUTING_ID = 2
 WHERE   SHIP_TO_ORGANIZATION_ID IN
               (SELECT   POLL.SHIP_TO_ORGANIZATION_ID ORGANIZATION_ID
                  FROM   po_line_locations_all POLL,
                         PO_LINES_ALL PLA,
                         MTL_SYSTEM_ITEMS_B MSI,
                         PO_HEADERS_ALL POH,
                         ORG_ORGANIZATION_DEFINITIONS OOD,
                         RCV_ROUTING_HEADERS RRH
                 WHERE       POLL.PO_LINE_ID = PLA.PO_LINE_ID
                         AND POH.PO_HEADER_ID = PLA.PO_HEADER_ID
                         AND POH.PO_HEADER_ID = POLL.PO_HEADER_ID
                         AND POH.ORG_ID = PLA.ORG_ID
                         AND POLL.ORG_ID = PLA.ORG_ID
                         AND MSI.INVENTORY_ITEM_ID = PLA.ITEM_ID
                         AND POLL.SHIP_TO_ORGANIZATION_ID =
                               MSI.ORGANIZATION_ID
                         AND OOD.ORGANIZATION_ID = MSI.ORGANIZATION_ID
                         AND RRH.ROUTING_HEADER_ID =
                               POLL.RECEIVING_ROUTING_ID
                         AND POH.ORG_ID IN (90, 91)
                         AND POLL.SHIP_TO_ORGANIZATION_ID IN
                                  (SELECT   organization_id
                                     FROM   org_organization_definitions
                                    WHERE      organization_code LIKE '%C%'
                                            OR organization_code LIKE '%E%'
                                            OR organization_code LIKE '%S%'
                                            OR organization_code LIKE '%I%')
                         AND POLL.RECEIVING_ROUTING_ID NOT IN (1, 2)
                         AND LENGTH (POH.SEGMENT1) = 8)