I have this more or less common query to get an exploded BOM with the path to the child:
select distinct
LEVEL "level"
,sys_connect_by_path(msib.segment1, '|') as "PATH"
,msib2.segment1 as "CHILD ITEM"
,msib2.description
,bic.component_quantity
,TO_DATE(bic.IMPLEMENTATION_DATE) IMPLEMENTATION
,TO_DATE(bic.DISABLE_DATE)DISABLED
,(SELECT NAME FROM HR_ALL_ORGANIZATION_UNITS WHERE ORGANIZATION_ID = BIC.PK2_VALUE) ORGANIZATION
,bom.organization_id
,BIC.ITEM_NUM SECUENCE
,bic.component_item_id CHILD_INVENTORY_ID
, msib2.primary_uom_code UOM
from bom.bom_components_b bic
,bom.bom_structures_b bom
,inv.mtl_system_items_b msib
,inv.mtl_system_items_b msib2
where 1=1
and bic.bill_sequence_id = bom.bill_sequence_id
and bom.assembly_item_id = msib.inventory_item_id
and bom.organization_id = msib.organization_id
and bic.component_item_id = msib2.inventory_item_id
and bom.organization_id = msib2.organization_id
and bom.organization_id IN (1269)
and bom.alternate_bom_designator is NULL
AND bic.DISABLE_DATE IS NULL <---------------- !!!LOOK HERE!!!
connect by nocycle prior bic.codmponent_item_id = msib.inventory_item_id
D = the item has disabled date
--- EXAMPLE 0 FATHER CHILD0 CHILD1 CHILD2 Should return: FATHER|CHILD0 FATHER|CHILD1 FATHER|CHILD2--- EXAMPLE 1 FATHER CHILD0 CHILD1 (D) CHILD2 Should return: FATHER|CHILD0 FATHER|CHILD2
--- EXAMPLE 2 FATHER CHILD0 (D) CHILD1 (D) CHILD2 (D) Should return: FATHER (does not matter the assy is empty, this'd be corrected in the BOM)
--- EXAMPLE 3 FATHER (D) CHILD0 CHILD1 CHILD2 Should return: NULL
With the current code if an assembly has at least one item active even if the father is not, it's loaded in the query:
--- EXAMPLE 4 FATHER (D) CHILD0 (D) CHILD1 (D) CHILD2 Returns: FATHER|CHILD0 FATHER|CHILD1 FATHER|CHILD2 Should return: NULL --- EXAMPLE 5 FATHER (D) CHILD0 CHILD1 CHILD2 Returns: FATHER|CHILD0 FATHER|CHILD1 FATHER|CHILD2 Should return: NULL
How can I prevent this? This is, I need to retrieve items only if themselves or the father do NOT have disabled date. My BOMs have at most 9 levels. Thanks!
Edit: Made @mathguy modifications:
select distinct
LEVEL "level"
,sys_connect_by_path(msib.segment1, '|') as "PATH"
,msib2.segment1 as "CHILD ITEM"
<SNIP>
from bom.bom_components_b bic
,bom.bom_structures_b bom
,inv.mtl_system_items_b msib
,inv.mtl_system_items_b msib2
where 1=1
and bic.bill_sequence_id = bom.bill_sequence_id
and bom.assembly_item_id = msib.inventory_item_id
and bom.organization_id = msib.organization_id
and bic.component_item_id = msib2.inventory_item_id
and bom.organization_id = msib2.organization_id
and bom.organization_id IN (1269)
and bom.alternate_bom_designator is NULL
START WITH msib.segment1 = 'GRANDPA' AND bic.DISABLE_DATE IS NULL
CONNECT BY nocycle prior bic.component_item_id = msib.inventory_item_id AND bic.DISABLE_DATE IS NULL
ORDER BY LEVEL,PATH ASC
And the query returned a lot less rows (good!) but this test case is still failing:
--- EXAMPLE 4 GRANDPA FATHER (D) CHILD0 CHILD1 CHILD2 Should return: GRANDPA Returns: GRANDPA|FATHER|CHILD0 GRANDPA|FATHER|CHILD1 GRANDPA|FATHER|CHILD2
Perhaps this is related at how deep the hierarchy is going?