Page 1 of 1
Want to retrieve all element in Dimension
Posted: Wed Jan 18, 2012 11:23 am
by amitbehere2002
Hi,
I want to retrieve all the elements in Dimension to use it for CellputS function
please help me in the same
Thanks
Amit
Re: Want to retrieve all element in Dimension
Posted: Wed Jan 18, 2012 12:02 pm
by lotsaram
Dear Amit,
On face value this is a pretty simple requirement that just requires a while loop to iterate through the dimension. You might want to elaborate on WHY or WHAT you actually need to do as you have mentioned CellPutS as opposed to AttrPutS which I assume to mean that there are additional dimension coordinates that you also need to know - are these additional coordinates fixed values or variable? Depending on the situation the loop might go on the prolog or within the data tab, ... or you might not need a loop at all and you could just have a simple CellPutS by itself on the data tab. Unless you explain what you actually need to do and give some more thought to your question it's not possible to help any further.
Code: Select all
# loop through dimension (courtesy of Vizier code snippet)
sDimName = 'yourDim';
nCounter = 1;
nMaximum = DimSiz(sDimName);
WHILE(nCounter <= nMaximum);
sElName = DimNm(sDimName, nCounter);
nCounter = nCounter + 1;
END;
Then you need to
do something useful within the While loop such as
CellPutS('your string value', 'yourCube', sDim1, sDim2, .... sDimN);
... where you would substitute the sElName variable for one of the sDim references
Re: Want to retrieve all element in Dimension
Posted: Wed Jan 18, 2012 12:06 pm
by David Usherwood
Why not just set the view or subset as the data source? Then the looping is done for you.
Re: Want to retrieve all element in Dimension
Posted: Wed Jan 18, 2012 1:38 pm
by jim wood
A good point David but in some cases models are setup to avoid dynamic subsets. For this to work you would need to use one for dimensions that change often. If dynamic subsets are not a problem in your model then I agree. If they are then Lotsarams solution is a good alternative.
Re: Want to retrieve all element in Dimension
Posted: Wed Jan 18, 2012 1:48 pm
by David Usherwood
Indeed...
But I didn't mention dynamic subsets. It's often easier to use the All subset and skip the elements you don't want.
Re: Want to retrieve all element in Dimension
Posted: Wed Jan 18, 2012 2:03 pm
by lotsaram
David Usherwood wrote:Why not just set the view or subset as the data source? Then the looping is done for you.
I agree, and I believe I already made reference to this.
lotsaram wrote: ... or you might not need a loop at all and you could just have a simple CellPutS by itself on the data tab.
But it depends on what the OP actually needs to do, and unless he provides that information no point having any debate about the x^n various methods of solving the problem.
Re: Want to retrieve all element in Dimension
Posted: Wed Jan 18, 2012 3:18 pm
by jim wood
For me it's like using a crane to lift a cardboard box. While it will work it's over kill. David's solution is the simple soultion, Lotsaram yours is the crane.