I am trying to delete C level elements from simple hierarchy,I have defined source as none.Below code doesn't give me any error and process run successfully but when i go back and check the dimension hierarchy is still intact.I have tried the code both prolog and epilog.Thanks
As stated many times before with these kind of loops where you delete, you should loop backwards. Just as in Excel where you can delete rows in a sheet, but from the end to the beginning.
Start with your counter equal to the Dimsiz, and loop while each time subtracting 1 from the counter until you hit the element with index in the dimension 1.
Looping forward makes you miss some elements.
Use the Prolog for this kind of process, it should be done BEFORE you enter the Metadata tab.
Best regards,
Wim Gielis
IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014 https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
BariAbdul wrote:I am trying to delete C level elements from simple hierarchy,I have defined source as none.Below code doesn't give me any error and process run successfully but when i go back and check the dimension hierarchy is still intact.I have tried the code both prolog and epilog.Thanks
DimName = 'Region_All';
DimCount = DimSiz ( DimName );
i = 1;
While ( i <= DimCount ) ;
DimCount = DimSiz (DimName);
El = DimNm ( DimName , i);
ChildCount = ElCompN(DimName, El) ;
If ( ChildCount <> 0);
y = 1;
While ( y <= ChildCount );
ChildEl = ElComp ( DimName , El, 1);
DimensionElementComponentDelete(DimName, El, ChildEl);
y = y +1 ;
End ;
EndIf ;
i = i + 1 ;
End;
Looking at your code I noticed your using DimensionElementComponentDelete. This function removes child from parent element, it does not delete an element. So that may be why the "C" elements are still in your dimension even though there is no longer a "hierarchy" in your attachment. If you want to delete an element use DimensionElementDelete