January 23, 2008, 10:48 AM
TewyMaximum Number of IF THEN ELSE Pairs?
Can anyone tell me what the maximum number of IF THEN ELSE pairs in a defined field is?
A search in the technical documentation library for 7.6.x release indicates it is still 16, but I have used more than that with no problems.
I have hit the limit (found when the code errored) but although I could try to find the actual limit by removing lines one by one, I was hoping someone here would know.
BTW it's not possible for me to use a DECODE in this instance.
Thanks
January 23, 2008, 11:24 AM
LeahTo my knowledge that hasn't changed. Are you using it in a define or a compute? I've had to play games with defines to get it to work for me. Don't have the example in my mind though.
January 23, 2008, 11:33 AM
susannahyou can get around that limit, you probably figured that out already.
NEWFIELD/A..=IF.....
ELSE 'XXXX';
NEWFIELD/A...=IF NEWFIELD NE 'XXX' THEN NEWFIELD ELSE
IF ...
ELSE 'XXXX';
...repeat the 2nd bit, redefining the same field name. And when your fex references the fieldname, focus always grabs the last defined one. handy trick.
January 23, 2008, 11:37 AM
hammo1j2 choices -
either rewrite your IF THEN ELSE expression as nested ifs if it is possible to divide the conditions equally or.
-or to retain the same if then else if logic which works like a filter since the tests in each if may not be mutually exclusive
-* needed expression too big with 100 max is 25 say
val = if expr1 then result1
else if expr2 then result2
...
else if expr100 then result100
else resultdefault ;
-* becomes
valgroup1/i2 = if expr1 then 1
else if expr2 then 1
...
else if expr24 then 1
else 0 ;
val1 = if expr1 then result1
else if expr2 then result2
...
else if expr24 then result24
else 0 ;
valgroup2/i2 = if valgroup1 eq 1 then 1
else if expr25 then 2
else if expr26 then 2
...
else if expr48 then 2
else 0 ;
val2 = if valgroup1 eq 1 then val1
else if expr25 then result25
else if expr26 then result26
...
else if expr48 then result48
else 0 ;
and so on...
Try it and you will soon get the idea
January 23, 2008, 11:39 AM
hammo1jSuzannah's method is better and simpler if you can define an else that is not in the possible values so use that!
January 24, 2008, 04:23 AM
TewyThanks for the replies, I already have it set up in the way Susannah suggests, so it is working.
It was just before the code came up with the this is too long error, I had it working with at least 40 IF THEN ELSE statements!
After reading the documentation, I have split it up so there's only 16 per defined field now, and it works fine, I was just wondering if anyone else had more insight into this.
Thanks Again
January 24, 2008, 05:05 AM
GamPI seem to remember that it was not the amount of if-then-else's but more a matter of how much memory it occupies. There is a certain amount of memory reserved for computational elements, and it goes per element. But I can't really remember how much memory that is.
Anyway, the problem is solved easily enough by splitting up, so you don't hit this memory limit any more.