DimensionElementDelete deleting alternate elements

Post Reply
Paul-TM1
Posts: 124
Joined: Tue Jun 13, 2017 3:20 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

DimensionElementDelete deleting alternate elements

Post by Paul-TM1 »

Hi All,
I have come across a strange issue. I am trying to delete an element 'element1' and it's children in a dimension and I have looped them. When I write to a file without 'DimensionElementDelete', all the elements are written to file. But when I use the 'DimensionElementDelete', only alternate elements are deleted and only those deleted are written in the file. We use 10.2.2 FP7. Has anyone seen this before? any help is appreciated.

Thanks,
Paul.

Code: Select all

pDim = 'DimensionNm' ;
x =1 ;

WHILE(x <= DimSiz( pDim ) ) ;
  element = DimNM( pDim ,x) ;
  if ( SUBST(element , 1, 5) @=  element1 );
	asciiOutPut( degugFile , pDim, 'pDimensionSize ', numberToString ( x ),  element ) ;
	
	DimensionElementDelete(pDim, element );
	
	#After adding the line below, deleted all the elements vs alternate elements are deleted
	x = x - 1;
	# the above line would make the session hung if 'DimensionElementDelete' is not commented.
	
	asciiOutPut( degugFile , pDim, 'deleted Element', element ) ;
  endif;

  x = x + 1;
END;
tomok
MVP
Posts: 2831
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: DimensionElementDelete deleting alternate elements

Post by tomok »

In your loop you need to start at the last record and work forward because deleting the element is going to change the index value of all your elements past the one being deleted.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
AmbPin
Regular Participant
Posts: 173
Joined: Sat Mar 20, 2010 3:03 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2007-10

Re: DimensionElementDelete deleting alternate elements

Post by AmbPin »

Either that or only increment your loop index if you do not delete an element.
Moh
Posts: 43
Joined: Fri Aug 01, 2014 5:17 pm
OLAP Product: Cognos
Version: 10.1.1
Excel Version: 2010

Re: DimensionElementDelete deleting alternate elements

Post by Moh »

paul pls give the final code you used,it will help me
Wim Gielis
MVP
Posts: 3103
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: DimensionElementDelete deleting alternate elements

Post by Wim Gielis »

Code: Select all

pDim = 'DimensionNm' ;
x = DimSiz( pDim );
WHILE(x > 0 ) ;
  element = DimNM( pDim ,x) ;
  if ( SUBST(element, 1, 5) @= element1 );
	DimensionElementDelete(pDim, element );
  EndIf;
  x = x - 1;
END;
Best regards,

Wim Gielis

IBM Champion 2024
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
lotsaram
MVP
Posts: 3651
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: DimensionElementDelete deleting alternate elements

Post by lotsaram »

Moh wrote: Sat Nov 11, 2017 1:08 pm paul pls give the final code you used,it will help me
There is actually a free utility available called TI Helper which can inject TI code snippets into the architect/perspectives process editor. Reverse dimension while loop is one of the included snippets.
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
Paul-TM1
Posts: 124
Joined: Tue Jun 13, 2017 3:20 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

Re: DimensionElementDelete deleting alternate elements

Post by Paul-TM1 »

Thanks Tomok. It worked.
Sorry I had not posted the code in time, but thanks Wim for posting the code.

Good to know there is a utility that helps generate code. I will be trying it now.

Thanks everyone for helping.
Paul.
Post Reply