Page 1 of 1

Process doesn't delete C level elements

Posted: Sun Aug 17, 2014 11:42 am
by BariAbdul
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

Code: Select all

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;

Re: Process doesn't delete C level elements

Posted: Sun Aug 17, 2014 11:53 am
by Wim Gielis
Hello,

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.

Re: Process doesn't delete C level elements

Posted: Tue Aug 19, 2014 7:04 pm
by uchow10
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

Code: Select all

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

Re: Process doesn't delete C level elements

Posted: Wed Aug 20, 2014 4:39 am
by BariAbdul
Thanks uchow10 ,You are correct.I realised this after posting ,It is working now.