Is there any way to trap a function error in a TI process? TM1 version: 9.0.3.196 – Update 9 (64-bit).
I'm using the NUMBR function to distinguish between pure numeric and alphanumeric string element values in an IF statement and process records accordingly.
Works great unless it hits a purely alphabetic value, in which case it causes an error (“cannot convert string to a real number†in the Message Log). The IF statement continues processing at the next line in this case.
I found a way to order the IF statement to get the output I want, but that might not always work, and I’d prefer trapping the errors in the process and keeping them out of the Message Log.
Thanks.
Error trapping in TM1 9.0?
- paulsimon
- MVP
- Posts: 808
- Joined: Sat Sep 03, 2011 11:10 pm
- OLAP Product: TM1
- Version: PA 2.0.5
- Excel Version: 2016
- Contact:
Re: Error trapping in TM1 9.0?
Hi
The oldest version I have is 9.1. In 9.1 it works OK eg NUMBR('AA') returns 0 as you would expect. As a work around in your version you could try concatenating a '0' to the front of the number so there is always something numeric in the string, eg NUMBR( '0' | vMyInput )
Regards
Paul Simon
The oldest version I have is 9.1. In 9.1 it works OK eg NUMBR('AA') returns 0 as you would expect. As a work around in your version you could try concatenating a '0' to the front of the number so there is always something numeric in the string, eg NUMBR( '0' | vMyInput )
Regards
Paul Simon
-
- Site Admin
- Posts: 6647
- Joined: Sun May 11, 2008 2:30 am
- OLAP Product: TM1
- Version: PA2.0.9.18 Classic NO PAW!
- Excel Version: 2013 and Office 365
- Location: Sydney, Australia
- Contact:
Re: Error trapping in TM1 9.0?
If the data source is a View and what you're really checking for is whether the value is an S type or an N type, then the Value_Is_String variable would be able to do that for you rather than doing a Numbr conversion.Eeyore wrote:Is there any way to trap a function error in a TI process? TM1 version: 9.0.3.196 – Update 9 (64-bit).
I'm using the NUMBR function to distinguish between pure numeric and alphanumeric string element values in an IF statement and process records accordingly.
Works great unless it hits a purely alphabetic value, in which case it causes an error (“cannot convert string to a real number†in the Message Log). The IF statement continues processing at the next line in this case.
I found a way to order the IF statement to get the output I want, but that might not always work, and I’d prefer trapping the errors in the process and keeping them out of the Message Log.
Short of that, you're correct... and there's no IsNumeric style function that will help you work around that easily. The only workaround that I can think of off the top of my head is to:
- Get the length of the input using the Long function, then
- Use the Subst function to pull each character out of it inside a While loop, and
- Use the Code() function to see whether the ASCII code for the character falls between 48 ("0") and 57 ("9").
You can handle that one of two ways. If you find one that IS in that range, then you know it's safe to use your Numbr function. Alternatively if you don't, you'll know that you can't.
It ain't pretty, but it'll do the job.
(Paul got his post in ahead of me but his idea is another possibility. Unfortunately in 9.0, it definitely does generate the error. However the error's treated as non-critical and the code on the remainder of the tab still completes. This is of course potentially dangerous if the value of the Numbr conversion is stored in a variable as, unless the variable is reinitialised, the value from the previous conversion is used in the code for the remainder of the tab.)
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
-
- Posts: 6
- Joined: Wed Mar 04, 2009 9:32 pm
- OLAP Product: TM1
- Version: 9.0 SP3 64-bit
- Excel Version: 2003
Re: Error trapping in TM1 9.0?
Thank you both for the suggestions. I didn't think there was any real error trapping capability in 9.0.
The “prepending zero†approach suggested by PaulSimon was a great idea, but it didn't work; I kept getting the same “cannot convert string to a real number†errors, even though there was now a number in the string. This happened with any variation I tried of 1 or 2 leading numbers followed by all alpha characters; seems to be another limitation of the NUMBR function in 9.0. It handled alphanumeric strings with trailing numbers as documented.
The CODE function approach suggested by Alan did work quite well. I had thought of that initially, but was put off by concerns about all the extra processing time it would take. In practice, processing time did not change appreciably; TM1 continues to surprise me with how ridiculously fast it is with certain operations.
Is there any way to break out of a WHILE loop? I couldn't find one, so I ended up getting that effect by setting the index counter to a terminal value in the statement where I wanted the break to occur.
The “prepending zero†approach suggested by PaulSimon was a great idea, but it didn't work; I kept getting the same “cannot convert string to a real number†errors, even though there was now a number in the string. This happened with any variation I tried of 1 or 2 leading numbers followed by all alpha characters; seems to be another limitation of the NUMBR function in 9.0. It handled alphanumeric strings with trailing numbers as documented.
The CODE function approach suggested by Alan did work quite well. I had thought of that initially, but was put off by concerns about all the extra processing time it would take. In practice, processing time did not change appreciably; TM1 continues to surprise me with how ridiculously fast it is with certain operations.
Is there any way to break out of a WHILE loop? I couldn't find one, so I ended up getting that effect by setting the index counter to a terminal value in the statement where I wanted the break to occur.
-
- Site Admin
- Posts: 6647
- Joined: Sun May 11, 2008 2:30 am
- OLAP Product: TM1
- Version: PA2.0.9.18 Classic NO PAW!
- Excel Version: 2013 and Office 365
- Location: Sydney, Australia
- Contact:
Re: Error trapping in TM1 9.0?
Nor in any other version really; not like the On Error Goto construct in VB anyway.Eeyore wrote:Thank you both for the suggestions. I didn't think there was any real error trapping capability in 9.0.
Just set the counter to a value higher than the While test. For example:Eeyore wrote:Is there any way to break out of a WHILE loop? I couldn't find one, so I ended up getting that effect by setting the index counter to a terminal value in the statement where I wanted the break to occur.
l_LenOfString = Long(TheString);
l_Character=1;
While ( l_Character <= l_LenOfString);
... code to pull out the character and test it
If ( Test is passed );
l_Character = l_LenOfString + 1;
EndIf;
l_Character=l_Character+1;
End;
That sort of thing. It'll still do the code below the test one more time rather than breaking out straight away, but it's still roughly equivalent to a break.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.