Page 1 of 1
How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 8:42 am
by beber005
Hi everyone,
I have a problem. I want to put information, except that I realize that the element that I want to put is a consolidated element. So I want to say: "as soon as it is consolidated, looking for its first simple child" and affects to my variable the name of this child. There is a part of my code :
Code: Select all
vTest = DNLEV(cDimPC);
ASCIIOutput(cOutputLog, 'Valeur du Profit Center : ' | NumberToString(vTest));
If( vTest > 0);
While(DTYPE(cDimPC,vPC) @='C');
vNewPC = ELISCOMP(cDimPC,vPC,vPC);
End;
Else;
vNewPC = vPC;
EndIf;
What do you think about it ? Because the function ELISCOMP, I'm not sure but it is not the good solution
Thank's a lot for your help !!
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 8:55 am
by beber005
I find a solution, but I'm not sure if it's the best way
Code: Select all
vNbDim = 13;
vIndex1 = 1;
While(vIndex1 < vNbDim);
# Current dimension
vCurDim = TABDIM(cCube_Dest, vIndex1);
#If I'm on the dimension PCENTER ...
If(vCurDim @= 'PCENTER');
While(DTYPE('PCENTER',vPC) @= 'C');
# Get the 1st child
vNewPC = ELCOMP('PROFIT_CENTER',vPC,1);
End;
EndIf;
# I upgrade my index to go the next dimension of the cube
vIndex1 = vIndex1 + 1;
End;
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 8:59 am
by David Usherwood
ELCOMP will deliver the first child without the loop.
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 9:22 am
by beber005
Yes I know but the loop is used because may I have a sequence of consolidated nodes. Don't you think ?
On this code I have an "error" because" this one loop indefinitely

Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 9:34 am
by beber005
I found the fail loop but I don't understand why this one generate this problem .. Sorry for my inability !!
Code: Select all
While(DTYPE('PCENTER',vPC) @= 'C');
# Get the 1st child
vNewPC = ELCOMP('PROFIT_CENTER',vPC,1);
End;
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 9:37 am
by BariAbdul
Code: Select all
vTest = DNLEV(cDimPC);
ASCIIOutput(cOutputLog, 'Valeur du Profit Center : ' | NumberToString(vTest));
If( vTest > 0);
While(DTYPE(cDimPC,vPC) @='C');
vNewPC = ELISCOMP(cDimPC,vPC,vPC);
End;
Else;
vNewPC = vPC;
EndIf;
Hi Berber005, I didn't see variable defined as vPC anywhere in the could,Could you please clarify? Thanks
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 9:44 am
by beber005
Hey,
Don't look this code because it's false. And further look this one
Code: Select all
vNbDim = 13;
vIndex1 = 1;
While(vIndex1 < vNbDim);
# Current dimension
vCurDim = TABDIM(cCube_Dest, vIndex1);
#If I'm on the dimension PCENTER ...
If(vCurDim @= 'PCENTER');
While(DTYPE('PCENTER',vPC) @= 'C');
# Get the 1st child
vNewPC = ELCOMP('PROFIT_CENTER',vPC,1);
End;
EndIf;
# I upgrade my index to go the next dimension of the cube
vIndex1 = vIndex1 + 1;
End;
I have an indefinitely loop on the 2nd while and I don't find why
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 9:57 am
by declanr
beber005 wrote:Hey,
Don't look this code because it's false. And further look this one
Code: Select all
(DTYPE('PCENTER',vPC) @= 'C');
# Get the 1st child
vNewPC = ELCOMP('PROFIT_CENTER',vPC,1);
End;
I have an indefinitely loop on the 2nd while and I don't find why
Your loop is dependent on vPC.
vPC goes into the start of your loop then at no point in your loop does it change; as such - if it meets the criteria of the while at the start it will ALWAYS meet the criteria of your loop.
I can see what you are trying to do but TM1 has no way of knowing that vNewPC and vPC are in essence the same thing.
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 10:10 am
by beber005
What should be done to me is to indicate under the while it takes down a level. If this level = 'S' then the name is recored.
What do you think?
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 10:44 am
by Alan Kirk
beber005 wrote:What should be done to me is to indicate under the while it takes down a level. If this level = 'S' then the name is recored.
What do you think?
I think perhaps you should re-read Wim's reply in
this very recent thread about your chances of having S elements as children of consolidations, which makes the whole premise of your question rather moot, does it not?
Of course, this also contradicts your statement in the very first post that:
beber005 wrote:So I want to say: "as soon as it is consolidated, looking for its first simple child" and affects to my variable the name of this child.
The right words; they actually
do matter to a question.
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 10:59 am
by Alan Kirk
On the off chance that you did actually mean
N element, not
S element, then I'd make a couple of suggestions:
(a) Don't rely on DType alone. A consolidation can have no children, and will still return a C. If that happens you're screwed for the purposes of this exercise.
(b) See below. This code is quick and dirty and has only been knocked up since my last post, so although I tested it once I haven't tested it extensively or bullet-proofed it.
If the original element is an N (simple) type already, then it bypasses the loop (since s_DTypeCurrent@= 'C' is never True) and you just pick the original element up below that.
If the loop
is executed, it will loop through the first element of a consolidation tree until it hits an N level element. If it doesn't find one, it spits an error.
In this case I've assigned a constant value representing the dimension name to SC_DIM (not shown in the extract below).
Code: Select all
s_LeafLevelChild = '';
s_CurrentElement = vPC;
s_DTypeCurrent = DType( SC_DIM, s_CurrentElement);
While ( s_DTypeCurrent@= 'C' );
If ( ElCompN ( SC_DIM, s_CurrentElement) = 0 );
s_DTypeCurrent = 'Error';
ItemReject ( 'No children for the consolidation element ' | s_CurrentElement);
Else;
# Get the first child. This is the important bit, since
# it changes the value of the variable that controls the loop.
s_CurrentElement = ElComp ( SC_DIM,s_CurrentElement, 1);
s_DTypeCurrent = DType( SC_DIM, s_CurrentElement);
# If it's an N element you use it, otherwise we just loop to the next consol element down.
If ( s_DTypeCurrent @= 'N' );
s_LeafLevelChild = s_CurrentElement;
s_DTypeCurrent = 'Found';
EndIf;
EndIf;
End;
# If it wasn't a consolidation and didn't pass through the loop,
# just use the original element name.
If ( s_DTypeCurrent @= 'N' );
s_LeafLevelChild = s_CurrentElement;
EndIf;
# Now use s_LeafLevelChild wherever you need to in your code.
AsciiOutput ( 'F:\Temp\Test.txt', s_LeafLevelChild);
Any questions? No? Good, because I won't be around to answer them anyway, I'm going to bed. Declan, David and Wim have the night shift.
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 12:05 pm
by Wim Gielis
Thank you for poking me, Alan
My take on this... I would not use loops! But consider an MDX statement, instead.
Code: Select all
vDim = 'MyDimension';
vElement = 'MyParent';
vSubset = 'MySubset';
SubsetCreateByMDX( vSubset, '{[' | vDim | '].[' | vElement | '], {TM1FILTERBYLEVEL({DESCENDANTS([' | vDim | '].[' | vElement | ']) }, 0)} }');
SubsetElementDelete(vDim, vSubset, 1);
If(SubsetGetSize( vDim, vSubset ) = 0);
TextOutput('test.txt', 'Oops, no n-element found...');
Else;
TextOutput('test.txt', 'The n-element is ''' | SubsetGetElementName(vDim, vSubset, 1) | '''.');
EndIf;
SubsetDestroy( vDim, vSubset);
Enter the value for vDim and vElement.
Then run the process and look in the TM1 Data directory for the output.
Added benefit: this MDX statement allows to go more than 1 level deep (below the parent element).
Only question is... how many items in the data source will request the creation and removal of a subset?
This code might be too difficult for you now, but then you've got something to keep yourself busy
Wim
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 1:54 pm
by tomok
What are you trying to accomplish with this? What good is a data export that, when encountering a consolidated node, only includes the first leaf child of that node?Wouldn't you want all the non-zero leaf children? In any case it looks like you are using the wrong functionality. When I export data from a cube I almost always use a view as my data source and filter what I wanted using subsets and play with the view settings to filter down to what I want. I would never attempt looping through anything except as a last resort.
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 3:00 pm
by beber005
Thank's a lot Alan your solution works perfctly and you save my life lol !!
Sorry Wim but your solution is too difficult for me I think !!
Anyway thank you very much for your help guys

Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 3:01 pm
by jim wood
Tomok,
I think he's trying to load data but his data sorce includes consolidated elements and he's trying to load the data in to the first child that isn't a string element. Well that's what I kind got from it after reading through,
Jim.
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 3:38 pm
by tomok
jim wood wrote:Tomok,
I think he's trying to load data but his data sorce includes consolidated elements and he's trying to load the data in to the first child that isn't a string element. Well that's what I kind got from it after reading through,
Jim.
I thought so too until I saw the ASCIIOutput in his code.
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 3:47 pm
by beber005
Yes jim,
I'm trying to load data but my data source includes consolidated elements and it's not possible to put any information on a node. That's why I would like to recuperate the 1st child of this node
Re: How Get the child of a consolidated element ??
Posted: Wed Apr 02, 2014 3:56 pm
by Wim Gielis
beber005 wrote:Sorry Wim but your solution is too difficult for me I think !!
What you don't understand now, could one day be "Oh yes, that's how it works" and the penny drops.
With a tool like TM1, you can do certain actions in many different ways.
You should always be open to new insights and approaches.
Glad to see it's solved!