Drg wrote: ↑Wed Oct 30, 2019 1:46 pm
The question is more philosophical.
What options do you (forum users) see for solving the problem of an indefinite data type (no matter where from the database or from a text file).
Let me explain to you that a string data type always comes to you, but a string may contain a number (a good example would be a file with an unknown set of analytics).
And actually the question itself sounds what options do you use?
Now you are asking a really interesting question!
In TM1 it is a REAL PAIN that
1. variable type once declared is forever immutable
2. we ony have numeric and string types
The 1st is not normally a pain but becomes very much a real pain when writing generic processes where you don't know the data type of each field or variable in advance and also for generic wrapper proceses that might call other processes and need to know the parameter types of processes they are calling. It leads to one hell of a lot of complication and unecessary duplication.
But to limit the discussion to processes dealing with variables of unknown type. There really is only one viable approach,
set all unknown variables to string then on the data tab you need to examine the contents of the variable to determine if it contains any non numeric characters (plus decimal separator and minus sign), typically with a Scan function
e.g.
Code: Select all
i = 1;
nErr = 0;
While( i <= Long(sVar) );
sChar = SubSt( sVar, i, 1 );
If( Scan( sChar, '-.0123456789' ) = 0 );
nErr = 1;
# here throw error message, strip character out, write log, etc.
EndIf;
i = i + 1;
End;
If( nErr = 0 );
# variable is numeric
nVar = StringToNumber( sVar );
# blah blah
EndIf;
If all tests pass then the input variable is numeric, you can convert it to a number and assign to a numeric variable.
Of course the test can get more elaborate to allow for different decimal and thousand separators, enclosing brackets for negative, "SAP" trailing negative indicator, scientific notation, etc, etc. but basically it is quite a laborious process. Keeping everything completel within TM1/TurboIntegrator there simply isn't a better way.
The future I think, with tools like TM1Py, looks a little different.