Process doesn't delete C level elements

Post Reply
BariAbdul
Regular Participant
Posts: 424
Joined: Sat Mar 10, 2012 1:03 pm
OLAP Product: IBM TM1, Planning Analytics, P
Version: PAW 2.0.8
Excel Version: 2019

Process doesn't delete C level elements

Post 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;
Attachments
Region_All Dimension Hierarchy.doc
(38 KiB) Downloaded 253 times
"You Never Fail Until You Stop Trying......"
Wim Gielis
MVP
Posts: 3229
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.1.5
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Process doesn't delete C level elements

Post 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.
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
uchow10
Posts: 18
Joined: Mon Aug 05, 2013 9:25 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

Re: Process doesn't delete C level elements

Post 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
BariAbdul
Regular Participant
Posts: 424
Joined: Sat Mar 10, 2012 1:03 pm
OLAP Product: IBM TM1, Planning Analytics, P
Version: PAW 2.0.8
Excel Version: 2019

Re: Process doesn't delete C level elements

Post by BariAbdul »

Thanks uchow10 ,You are correct.I realised this after posting ,It is working now.
"You Never Fail Until You Stop Trying......"
Post Reply