Thursday, 22 October 2020

BOM Data Drill Down Query in Oracle Apps R12

SELECT (SELECT ou.name 
        FROM   org_organization_definitions ood, 
               hr_operating_units ou 
        WHERE  ood.operating_unit = ou.organization_id 
               AND ood.organization_id = msi1.organization_id)ou, 
       (SELECT ood.organization_name 
        FROM   org_organization_definitions ood 
        WHERE  ood.organization_id = msi1.organization_id)    inv_code, 
       (SELECT segment1 
        FROM   mtl_system_items_b 
        WHERE  1 = 1 
               AND inventory_item_id = path 
               AND organization_id = :p_organization_id)      assembly_item, 
       msi.description                                        assembly_item_desc, 
       alternate_bom_designator 
       ALTERNATE_name, 
       item_num, 
       operation_seq_num, 
       Lpad (' ', 10 * ( lvl - 1 ))||msi1.segment1           AS Component_item, 
       msi1.description                                       comp_item_desc, 
       component_quantity, 
       msi1.primary_unit_of_measure                           uom 
FROM   mtl_system_items_b msi, 
       mtl_system_items_b msi1, 
       (SELECT assembly_item_id, 
               LEVEL                                                lvl, 
               Substr (Sys_connect_by_path (assembly_item_id, '/') 
                       || '/', 2, Instr (( Sys_connect_by_path (assembly_item_id 
                                           , '/') 
                                           || '/' ), '/', 2) - 2)   path, 
               component_item_id, 
               component_quantity, 
               item_num, 
               supply_subinventory, 
               component_quantity * Nvl(PRIOR component_quantity, 1)extended_qty, 
               alternate_bom_designator, 
               implementation_date, 
               creation_date, 
               from_date, 
               to_date, 
               operation_seq_num 
        FROM   (SELECT DISTINCT bom.assembly_item_id, 
                                bic.component_item_id, 
                                bom.organization_id, 
                                bom.alternate_bom_designator, 
                                Trunc (bom.implementation_date) 
                                implementation_date, 
                                bic.component_quantity, 
                                bic.item_num, 
                                bic.supply_subinventory, 
                                bom.creation_date, 
                                bic.effectivity_date            from_date, 
                                bic.disable_date                to_date, 
                                bic.operation_seq_num 
                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 ) 
                       AND bic.implementation_date IS NOT NULL 
                       AND bom.alternate_bom_designator IS NULL 
                       AND bom.organization_id = Nvl(:p_organization_id,bom.organization_id) 
               
               ) 
        START WITH assembly_item_id IN (SELECT inventory_item_id 
                                        FROM   mtl_system_items_b 
                                        WHERE  segment1 = Nvl (:p_item_code,segment1) 
                                               AND organization_id = Nvl (:p_organization_id,organization_id))
        CONNECT BY NOCYCLE PRIOR component_item_id = assembly_item_id) bom 
WHERE  bom.assembly_item_id = msi.inventory_item_id 
       AND msi.organization_id = msi1.organization_id 
       AND bom.component_item_id = msi1.inventory_item_id 
       AND msi.organization_id = :p_organization_id; 

No comments:

Post a Comment