Page 1 of 1

IF function return undefined type Error

Posted: Fri Oct 25, 2019 11:52 am
by Drg
Hey brains.


how you workaround this issue:

Code: Select all

Example1:
proc = pProc;
executeprocess( 
  proc , 
  IF(param_type @= 'N' , Numbr( param_val ) , param_val )
);

Example2:
if( param_type @= 'N' );
out = Numbr( param_val );
ELSE;
out = param_val;
ENDIF;

OR

out = IF(1=1 , '1' , 1);
so far a solution with multiple IF statements :ugeek:

Re: IF function return undefined type Error

Posted: Fri Oct 25, 2019 12:50 pm
by tomok
How about using the correct comparison operator for strings? @= instead of =. ;)

Re: IF function return undefined type Error

Posted: Fri Oct 25, 2019 1:13 pm
by Mark RMBC
It would also help if example 1 had the correct number of parenthesis!

Re: IF function return undefined type Error

Posted: Mon Oct 28, 2019 10:02 am
by Drg
Thanks guys.
I repair post.

Re: IF function return undefined type Error

Posted: Mon Oct 28, 2019 10:24 am
by Wim Gielis
Drg wrote: Mon Oct 28, 2019 10:02 am Thanks guys.
I repair post.
Can you also repair your post such that it becomes clear what you want to achieve ? What issues you are encountering ?
What are variables / parameters / what is the data source ?
Your exact code (where all typo's are corrected)

And so on. Maybe if you do so, helpers can actually help you.

Re: IF function return undefined type Error

Posted: Wed Oct 30, 2019 1:46 pm
by Drg
Wim Gielis wrote: Mon Oct 28, 2019 10:24 am
Drg wrote: Mon Oct 28, 2019 10:02 am Thanks guys.
I repair post.
Can you also repair your post such that it becomes clear what you want to achieve ? What issues you are encountering ?
What are variables / parameters / what is the data source ?
Your exact code (where all typo's are corrected)

And so on. Maybe if you do so, helpers can actually help you.

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?

A few examples from life:
starting a process (each time different) with parameters (each time different for a particular process)
Processing (not loading, in loading we can rely on the data type of cells in the cube) of the file (with a dynamic set of analytics)

I’m sure I’m not the only one who faced the problem when you need to put a string or number in a variable (or in a parameter of a TI function).

And I just wanted to find out who and how to solve it and talk about it

Re: IF function return undefined type Error

Posted: Wed Oct 30, 2019 6:24 pm
by lotsaram
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.

Re: IF function return undefined type Error

Posted: Thu Oct 31, 2019 7:17 am
by Drg
wow lotsaram a nice example of finding numbers in a string.
Thank you for your answer, he really confirmed that this is a pain and not a lack of my knowledge.
You are right the future for various api services.

Re: IF function return undefined type Error

Posted: Thu Oct 31, 2019 9:20 am
by Wim Gielis
Untested, just an idea that popped up.
What if you use the functions Numbr or StringToNumber or StringToNumberEx, and if the result is <> 0, then it’s a number. Otherwise, keep treating it as String.

Re: IF function return undefined type Error

Posted: Thu Oct 31, 2019 10:34 am
by lotsaram
Wim Gielis wrote: Thu Oct 31, 2019 9:20 am Untested, just an idea that popped up.
What if you use the functions Numb or StringToNumber or StringToNumberEx, and if the result is <> 0, then it’s a number. Otherwise, keep treating it as String.
Using Numbr is OK. I do that sometimes as this will just strip ot any non-numeric characters.
e.g. Numbr('1a00b') = 100
But NumberToString not so much as this will throw an error if you call it on a string that contains non-numerics.