Thursday, March 6, 2014

Query to get All BOM Levels in Oracle Apps R12

SELECT (SELECT segment1
          FROM mtl_system_items_b
         WHERE bom.assembly_item_id = inventory_item_id
           AND organization_id = 204
           AND bom.lvl = 1) part,
       msi.segment1 parent_item_number, msi1.segment1 item_number,
       msi1.description, lvl bom_level,
       (SELECT MAX (revision)
          FROM mtl_item_revisions
         WHERE inventory_item_id = bom.component_item_id
           AND organization_id = 204) revision,
       component_quantity quantity
  FROM mtl_system_items_b msi,
       mtl_system_items_b msi1,
       (SELECT     assembly_item_id, LEVEL lvl, component_item_id,
                   component_quantity
              FROM (SELECT bom.assembly_item_id assembly_item_id,
                           bic.component_item_id component_item_id,
                           component_quantity
                      FROM bom_bill_of_materials bom,
                           bom_inventory_components bic
                     WHERE bom.bill_sequence_id = bic.bill_sequence_id
                       AND (   bic.disable_date IS NULL
                            OR bic.disable_date > SYSDATE
                           ))
        START WITH assembly_item_id IN (
                         SELECT inventory_item_id
                           FROM mtl_system_items_b
                          WHERE segment1 = '124-4567'
                                AND organization_id = 204)
        CONNECT BY PRIOR component_item_id = assembly_item_id) bom
 WHERE bom.assembly_item_id = msi.inventory_item_id
   AND msi.organization_id = 204
   AND bom.component_item_id = msi1.inventory_item_id
   AND msi1.organization_id = 204

No comments:

Post a Comment