Page 1 of 1

HELP : Problem add element to a dimension

Posted: Mon Sep 19, 2016 12:54 pm
by merics
Hi,
Firstable, I’m sorry for my english.

So, I’m trying to copy a part of a dimension to an other, but when I use DIMENSIONELEMENTCOMPONENTADD, elements are where I want but the 5 or 6 last elements are also copy in the top level.

This is my code in Prologue (I try to use metadata too)

Code: Select all

DIMENSIONELEMENTINSERT(cDimTmp,'',c_Noeud_Subset,'c');

index = 0;
nbSubset = 0;

nbIndex = DIMSIZ(pDim);
WHILE( index <nbIndex);
	index = index + 1;
	val = DIMNM(pDim,index);
	If (ELISCOMP(pDim, val, c_Noeud_Subset) = 1);
		DimensionElementInsert(cDimTmp,'',val,'C'); 
		DIMENSIONELEMENTCOMPONENTADD(cDimTmp,c_Noeud_Subset,val,1);
		nbSubset = nbSubset + 1;
	EndIf;
END;

index = 0;
WHILE( index <nbIndex);
	index = index + 1;
	val = DIMNM(pDim,index);
	If (ELISANC(pDim, c_Noeud_Subset, val) = 1);
		vSubset = 0;
		While (vSubset < nbSubset);
			vSubset = vSubset + 1;	
			vNameSubset = DIMNM(cDimTmp,vSubset+1); 
			If (ELISCOMP(pDim, val, vNameSubset) = 1);
				DimensionElementInsert(cDimTmp,'',val,'N'); 
				DIMENSIONELEMENTCOMPONENTADD(cDimTmp,vNameSubset,val,0);
			EndIf;

		End;
	EndIf;
END;
Source: pDim
https://drive.google.com/open?id=0B5sW_ ... nF6cE5SeUU

Dest : cDimTmp
https://drive.google.com/open?id=0B5sW_ ... 3Z0TTlUTmM

I'm on Architect 10.2.2
Thanks

Re: HELP : Problem add element to a dimension

Posted: Tue Sep 20, 2016 9:31 pm
by paulsimon
Hi

Sorry I don't have the time to read your code.

I suggest avoiding the term Subset in a variable for a Consolidation. Its confusing. I can't see what purpose nbSubset has in the first loop.

There are two possibilities.

a) Your dimension is fine but looks odd due to the sort order of the elements. Issue a DimensionSortOrder on an empty statement or put the values into }DimensionProperties. See elsewhere on this Forum for that.

b) Your logic is wrong. Add AsciiOutput statements to output key variables to work out where it is going wrong. I would suggest looking at the state of the temp dim after the first loop. A simple way to comment out a block in TI is to use IF( 1 = 0 ) ; and an ENDIF at the end of the section you want to comment out.

Regards

Paul Simon

Re: HELP : Problem add element to a dimension

Posted: Wed Sep 21, 2016 7:47 am
by merics
Thanks for your answer,

nbSubset in the first loop is used for count the number of direct child of the top element Z_feeder_Spec.
The first loop create this child in the new dimension, I try only this loop and it's OK:
Image

I also use AsciiOutput before DIMENSIONELEMENTCOMPONENTADD and this is my log:
Image

Re: HELP : Problem add element to a dimension

Posted: Wed Sep 21, 2016 12:58 pm
by jwilkins
paulsimon wrote:a) Your dimension is fine but looks odd due to the sort order of the elements. Issue a DimensionSortOrder on an empty statement or put the values into }DimensionProperties. See elsewhere on this Forum for that.
This is the source of your confusion. The "duplicated" elements are not duplicated, there is simply a consolidated element between them and the consolidation they are a child of. This causes TM1 to show them under the root level as well. Consider
- Top Element
-- Parent A
---- Child A
-- Parent B
---- Child B

If the order of the elements is: Top Element, Parent A, Parent B, Child B, Child A; TM1 would show the following as the dimension structure
- Top Element
-- Parent A
---- Child A
-- Parent B
---- Child B
- Child A

Note that all of your duplicated elements do not appear in the last consolidation of your dimension. As Paul suggested, the fix for this is to set your dimension sort order appropriately.