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.