Page 1 of 1

Testing for Elements using wildcard chars

Posted: Thu Jun 25, 2009 11:29 am
by hbell
Version 9.1.3

I have a TI process that needs to test for the presence in a dimension of elements that match a pattern (eg: "210EXAFR*"). I cannot use DIMIX because that requires a complete element name - and I have no way of predicting what the balance of the element name might be. I have tried to use the TI function to create a Subset using MDX in the hope that I could then measure the Subsiz ... but if there is nothing matching my string this just seems to return an error which causes my process to crash (and I'm not aware of a means of error-trapping in a TI process).

Anyone know a way around that?

thanks ...........hugh

Re: Testing for Elements using wildcard chars

Posted: Thu Jun 25, 2009 11:47 am
by John Hobson
I may be missing something here but can you not just cycle through the dimension elements using a counter

Then have a variable like

sTest = Dimnm(Dim, Counter)

Then use string rules to test if the the first 8 characters of sTest are equal to "210EXAFR".

If so drop them into a subset.

Looks like it should work to me.

Re: Testing for Elements using wildcard chars

Posted: Thu Jun 25, 2009 11:48 am
by lotsaram
I can see 2 possible solutions to your problem:

1/ Insert a temporary element into your dimension that contains your search string, eg. "210EXAFR_ztemp_delete", then create your MDX subset, test for subset size, subtract one then delete the temp element from the dimension

2/ Abandon SubsetCreateByMDX approach and loop through the dimension testing each element with SCAN and incrementing your count whenever SCAN is non-zero

Either one of these approaches will work but the first is probably faster. If SubsetCreateByMDX returns a null set this is interpreted by TI as a major error and the process will terminate. The most effective way to trap this error is to ensure that the subset has at least one member.

Re: Testing for Elements using wildcard chars

Posted: Thu Jun 25, 2009 12:10 pm
by hbell
... thanks for the responses. I had resisted the scan approach as the dimension could easily get into the 10s of 1,000s and I was concerned about response times. However, it probably is the safest route. Adding the deletable dummy element is ingenious. I had wondered whether the MDX line could be put into its own process and whether the calling process would then be able to trap a failed return without the whole thing going belly-up ..

Re: Testing for Elements using wildcard chars

Posted: Thu Jun 25, 2009 5:43 pm
by Wim Gielis
hbell wrote:... thanks for the responses. I had resisted the scan approach as the dimension could easily get into the 10s of 1,000s and I was concerned about response times. However, it probably is the safest route. Adding the deletable dummy element is ingenious. I had wondered whether the MDX line could be put into its own process and whether the calling process would then be able to trap a failed return without the whole thing going belly-up ..
Hi

When a dimension contains a lot of members, you may want to try out some tricks (don't know whether they're faster than a simple loop though). Lotsaram's first suggestion is the best, though.

- create a (temporary) subset that you delete afterwards, containing the elements that match the first letter for instance. This could possibly reduce the number of iterations in the loop greatly. Don't know if this helps.
- IF there's some kind of logic in the creation of elements, you may want to loop backwards (descending on index number). This has helped me once to greatly reduce the execution time of a loop.
- if sorting the elements in the dimension is not an issue in this case, you could first sort the elements, and escape the loop whenever appropriate.

HTH,

Wim