How Get the child of a consolidated element ??

Post Reply
beber005
Posts: 57
Joined: Mon Mar 03, 2014 2:18 pm
OLAP Product: Cognos
Version: 9.5.1
Excel Version: 2010

How Get the child of a consolidated element ??

Post 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 !!
beber005
Posts: 57
Joined: Mon Mar 03, 2014 2:18 pm
OLAP Product: Cognos
Version: 9.5.1
Excel Version: 2010

Re: How Get the child of a consolidated element ??

Post 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;
David Usherwood
Site Admin
Posts: 1458
Joined: Wed May 28, 2008 9:09 am

Re: How Get the child of a consolidated element ??

Post by David Usherwood »

ELCOMP will deliver the first child without the loop.
beber005
Posts: 57
Joined: Mon Mar 03, 2014 2:18 pm
OLAP Product: Cognos
Version: 9.5.1
Excel Version: 2010

Re: How Get the child of a consolidated element ??

Post 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 :(
beber005
Posts: 57
Joined: Mon Mar 03, 2014 2:18 pm
OLAP Product: Cognos
Version: 9.5.1
Excel Version: 2010

Re: How Get the child of a consolidated element ??

Post 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;
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: How Get the child of a consolidated element ??

Post 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
"You Never Fail Until You Stop Trying......"
beber005
Posts: 57
Joined: Mon Mar 03, 2014 2:18 pm
OLAP Product: Cognos
Version: 9.5.1
Excel Version: 2010

Re: How Get the child of a consolidated element ??

Post 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
declanr
MVP
Posts: 1831
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: How Get the child of a consolidated element ??

Post 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.
Declan Rodger
beber005
Posts: 57
Joined: Mon Mar 03, 2014 2:18 pm
OLAP Product: Cognos
Version: 9.5.1
Excel Version: 2010

Re: How Get the child of a consolidated element ??

Post 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?
Alan Kirk
Site Admin
Posts: 6667
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: How Get the child of a consolidated element ??

Post 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.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Alan Kirk
Site Admin
Posts: 6667
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: How Get the child of a consolidated element ??

Post 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.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Wim Gielis
MVP
Posts: 3241
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: How Get the child of a consolidated element ??

Post 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
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
tomok
MVP
Posts: 2836
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: How Get the child of a consolidated element ??

Post 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.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
beber005
Posts: 57
Joined: Mon Mar 03, 2014 2:18 pm
OLAP Product: Cognos
Version: 9.5.1
Excel Version: 2010

Re: How Get the child of a consolidated element ??

Post 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 :)
User avatar
jim wood
Site Admin
Posts: 3961
Joined: Wed May 14, 2008 1:51 pm
OLAP Product: TM1
Version: PA 2.0.7
Excel Version: Office 365
Location: 37 East 18th Street New York
Contact:

Re: How Get the child of a consolidated element ??

Post 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.
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
tomok
MVP
Posts: 2836
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: How Get the child of a consolidated element ??

Post 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.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
beber005
Posts: 57
Joined: Mon Mar 03, 2014 2:18 pm
OLAP Product: Cognos
Version: 9.5.1
Excel Version: 2010

Re: How Get the child of a consolidated element ??

Post 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
Wim Gielis
MVP
Posts: 3241
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: How Get the child of a consolidated element ??

Post 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!
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
Post Reply