Page 1 of 1

Error trapping in TM1 9.0?

Posted: Tue Jan 26, 2010 4:22 pm
by Eeyore
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.

Re: Error trapping in TM1 9.0?

Posted: Tue Jan 26, 2010 11:58 pm
by paulsimon
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

Re: Error trapping in TM1 9.0?

Posted: Wed Jan 27, 2010 12:08 am
by Alan Kirk
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.
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.

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.)

Re: Error trapping in TM1 9.0?

Posted: Mon Feb 01, 2010 4:49 pm
by Eeyore
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.

Re: Error trapping in TM1 9.0?

Posted: Mon Feb 01, 2010 5:29 pm
by Alan Kirk
Eeyore wrote:Thank you both for the suggestions. I didn't think there was any real error trapping capability in 9.0.
Nor in any other version really; not like the On Error Goto construct in VB anyway.
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.
Just set the counter to a value higher than the While test. For example:

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.