Variable variable names
-
- Posts: 131
- Joined: Tue May 17, 2011 10:04 am
- OLAP Product: TM1
- Version: Planning Analytics 2.0
- Excel Version: 2016
- Location: Freiburg, Germany
Variable variable names
Hi all,
is there a way to use variable variable names in a Turbo Integrator process? I want to fill a range of 25 variables from P0 to P24. I hate to rewrite that code for each of those 25 variables; so what I have in mind is something like this:
i=0;
while (i<=24);
varName = 'P' | NumberToString(i);
Result = doSomeWeirdCalculation();
%%varName = Result; (or what ever the proper syntax might be)
i = i+1;
endif;
Any hope?
Thank you
Holger
is there a way to use variable variable names in a Turbo Integrator process? I want to fill a range of 25 variables from P0 to P24. I hate to rewrite that code for each of those 25 variables; so what I have in mind is something like this:
i=0;
while (i<=24);
varName = 'P' | NumberToString(i);
Result = doSomeWeirdCalculation();
%%varName = Result; (or what ever the proper syntax might be)
i = i+1;
endif;
Any hope?
Thank you
Holger
-
- 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: Variable variable names
Short answer is no and I don't know why you would need to do that, quite frankly. Variable names are meaningless to the actual execution of code. People come up with all kinds of schemes to name them but that is just for organization's sake. If you WERE able to do that (rename a variable), it would do you no benefit since that would all happen inside the execution of the script and you would never see it.
-
- MVP
- Posts: 3703
- Joined: Fri Mar 13, 2009 11:14 am
- OLAP Product: TableManager1
- Version: PA 2.0.x
- Excel Version: Office 365
- Location: Switzerland
Re: Variable variable names
Look up the EXPAND function in the reference guide. It may be what you are looking for.
-
- Posts: 131
- Joined: Tue May 17, 2011 10:04 am
- OLAP Product: TM1
- Version: Planning Analytics 2.0
- Excel Version: 2016
- Location: Freiburg, Germany
Re: Variable variable names
tomok,
seems like I failed to make my intention clear. I would prefer to loop through those 25 variables with just some five lines of code instead of re-writing the code for all of them.
Somehow I could not yet figure out how the EXPAND() example (which I had seen before) could help me here, but I keep on trying.
Regards
Holger
seems like I failed to make my intention clear. I would prefer to loop through those 25 variables with just some five lines of code instead of re-writing the code for all of them.
Somehow I could not yet figure out how the EXPAND() example (which I had seen before) could help me here, but I keep on trying.
Regards
Holger
-
- Posts: 131
- Joined: Tue May 17, 2011 10:04 am
- OLAP Product: TM1
- Version: Planning Analytics 2.0
- Excel Version: 2016
- Location: Freiburg, Germany
Re: Variable variable names
Thank you prameson, but all that just solves the reading of variables, but not the dynamic addressing of them in order to write into them.
In TCL (Cubeware Importer) it would work like this:
puts "Enter a variable name:"
gets stdin varname
set $varname 42
puts "I have set variable $varname to [set $varname]"
(a great web site re this btw: http://rosettacode.org/wiki/Dynamic_variable_names)
I guess I have to think of other ways.
Thanks to all of you
Holger
In TCL (Cubeware Importer) it would work like this:
puts "Enter a variable name:"
gets stdin varname
set $varname 42
puts "I have set variable $varname to [set $varname]"
(a great web site re this btw: http://rosettacode.org/wiki/Dynamic_variable_names)
I guess I have to think of other ways.
Thanks to all of you
Holger
- Martin Ryan
- Site Admin
- Posts: 1989
- Joined: Sat May 10, 2008 9:08 am
- OLAP Product: TM1
- Version: 10.1
- Excel Version: 2010
- Location: Wellington, New Zealand
- Contact:
Re: Variable variable names
You could use a dimension as your variable holder. I'm not sure how many lines of code it'll actually save, but something like this (assuming the dimension TempDim already exists and is prepopulated with 25 elements, though you could do this step in the prolog if you wanted).
sDim='TempDim';
i=1;
while(i<25);
sElem='P' | i;
result=docalc;
attrputs(result, sDim, sElem, 'AttrName');
i=i+1;
end;
I suspect that doesn't quite answer your question (as I'm not entirely sure I understand your question), but it may help point you in the right direction.
Martin
sDim='TempDim';
i=1;
while(i<25);
sElem='P' | i;
result=docalc;
attrputs(result, sDim, sElem, 'AttrName');
i=i+1;
end;
I suspect that doesn't quite answer your question (as I'm not entirely sure I understand your question), but it may help point you in the right direction.
Martin
Please do not send technical questions via private message or email. Post them in the forum where you'll probably get a faster reply, and everyone can benefit from the answers.
Jodi Ryan Family Lawyer
Jodi Ryan Family Lawyer
-
- Posts: 131
- Joined: Tue May 17, 2011 10:04 am
- OLAP Product: TM1
- Version: Planning Analytics 2.0
- Excel Version: 2016
- Location: Freiburg, Germany
Re: Variable variable names
Martin, now this is a really smart way of dealing with it. Actually I found a way to redesign the code so I do not need that any longer, but I will keep your suggestion in mind for similar cases.
Thank you
Holger
Thank you
Holger
-
- Posts: 131
- Joined: Tue May 17, 2011 10:04 am
- OLAP Product: TM1
- Version: Planning Analytics 2.0
- Excel Version: 2016
- Location: Freiburg, Germany
Re: Variable variable names
Now some time has passed and my hair has turned grey, I re-read this and found that today I would probably use a string variable to store all those values, maybe like this:
Or maybe just '1#9#4#', then reading this input again where ever I need it. Could even be a global variable so it would be available in other processes. Or, in cases where I do not mind the extra effort, I note things in a csv file and read them again later with a separate process.
Storing the values in an auxiliary dimension sure works nicely as well, but this locks the }Dimensons dimension which then inhibits other processes, especially those which use the same trick.
And once I understood the somewhat confusing description of the expand() function in the reference guide, I came to highly estimate the benefit of it. It allows to concatenate the name of a variable and then read the contents of it - I use this a lot:
Unfortunately, as stated before, there is no way to write into V1 that way...
Regards
Holger
Code: Select all
sString = 'V01=1#V02=9#V03=4#'
Storing the values in an auxiliary dimension sure works nicely as well, but this locks the }Dimensons dimension which then inhibits other processes, especially those which use the same trick.
And once I understood the somewhat confusing description of the expand() function in the reference guide, I came to highly estimate the benefit of it. It allows to concatenate the name of a variable and then read the contents of it - I use this a lot:
Code: Select all
i=1;
sVarName = 'V' | NumberToString(i);
nValue = Expand('%sVarName%');
Regards
Holger