DimensionElementDelete deleting alternate elements

Post Reply
Paul-TM1
Posts: 9
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 » Wed Nov 08, 2017 7:17 pm

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;

User avatar
tomok
MVP
Posts: 2349
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 » Wed Nov 08, 2017 7:27 pm

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 » Thu Nov 09, 2017 8:30 am

Either that or only increment your loop index if you do not delete an element.

Moh
Posts: 36
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 » Sat Nov 11, 2017 1:08 pm

paul pls give the final code you used,it will help me

Wim Gielis
MVP
Posts: 1562
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1
Version: PAL 2.0
Excel Version: 2016
Location: Brussels, Belgium
Contact:

Re: DimensionElementDelete deleting alternate elements

Post by Wim Gielis » Sat Nov 11, 2017 5:26 pm

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

Excel Most Valuable Professional, 2011-2014
http://www.wimgielis.com ==> 104 TM1 articles and a lot of custom code
Newest blog article: Delete a cube and its dimensions

lotsaram
MVP
Posts: 3006
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TM1, CX
Version: TM1 10.2.2 PA 2.0x
Excel Version: 2010 2013 365
Location: Switzerland

Re: DimensionElementDelete deleting alternate elements

Post by lotsaram » Sun Nov 12, 2017 10:17 am

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: 9
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 » Mon Nov 13, 2017 4:49 pm

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