Up to what depth or level can you do for OpenVMS IF-THEN-ELSE?
Just the other day, I found out (for good!) that OpenVMS IF-THEN-ELSE has a limit on the depth or level that will work properly. What is the meaning of this?
Simply, if you have many conditions to check, and you do a multiple IF-THEN-ELSE, or what we would also call a NESTED IF in Object-Oriented Programming (OOP), the limit of level or depth that you can do in OpenVMS is?
15.
Yes, 15.
I found out about this the hard way. I have been running a script for many days already, actually months, and I had no clue whatsoever. I just know that some checks, especially those recently added, well, they don't seem to work. I thought they do, and the error is happening intermittently. And that would be harder to troubleshoot.
But one fine day, as I was requested to run the same OpenVMS script more and more, like it was every week, then daily, and recently, many times in a day.
That gave me more chance to see why the script is 'intermittently ' -- or so I thought -- failing. When I scrolled the screen back up, I saw some 'invalid IF' error. I put some 'write sys$output' on each check to know where the failure is happening.
Before that (the 'write sys$output'), I was having a hard time scrolling back and forth, up and down, what could be causing the 'invalid IF', but found none.
Finding none, I thought of putting the 'write sys$output' line on each check, before each check is done.
Et voila!
The check continues to print the check, but I found that after the 15th IF under ELSE, the 'invalid IF' error is thrown. That gave me the idea, so I split the IF-THEN-ELSE clauses into different sets.
First set is up to 15 IF-ELSE, then a check is added to verify the placeholder if having a value, which is supposed to be populated when a match is found. So if no value is assigned, the second set of 15 IF-THEN-ELSE clauses is entered.
I don't have more than 30 conditions to check, so if I have, it will be from 31 to 45 IF-THEN-ELSE clauses.
So there you have it. 15.
How many levels of IF-THEN-ELSE clauses can you nest together? Up to 15 only.
I hope that this helps all fellow OpenVMS enthusiasts out there, encountering the same issue as I did, but found the fix in time.
Thank you and till then!