Rob Fitzpatrick
ProgressTalk.com Sponsor
A developer came to me with an ABL question (10.2B07). If a WHERE clause of a FOR EACH contains an equality match on a variable, and the variable's value gets changed within the FOR EACH, does the WHERE clause get re-evaluated to incorporate the new value? Let me explain with an example.
In this case, seq is a component of the primary index, and that index is being used (as per compile xref and -zqil). Based on the results returned, it appears that the first part of the WHERE clause, table.seq = v-i, becomes table.seq = 1 and remains so through all iterations of the loop. That would make sense to me, as the server would need to bracket on the index, and have that bracket remain consistent as it iterates through the matching records.
I'm not looking for thoughts on the business logic or quality of the code (I have my own! ). Just want to confirm that you can't change the equality match in this way from one iteration to the next. In other words, that the equality match remains static ( = 1, in this case) for all iterations of the FOR loop. I hope that makes sense.
I read the FOR statement info in the docs but didn't find a direct answer to this question. Thanks in advance for any help.
Code:
define variable v-i as integer initial 1 no-undo.
for each table
where table.seq eq v-i
and table.custnum eq 100 no-lock:
display table.lname
table.seq.
v-i = v-i + 1.
display v-i.
end.
In this case, seq is a component of the primary index, and that index is being used (as per compile xref and -zqil). Based on the results returned, it appears that the first part of the WHERE clause, table.seq = v-i, becomes table.seq = 1 and remains so through all iterations of the loop. That would make sense to me, as the server would need to bracket on the index, and have that bracket remain consistent as it iterates through the matching records.
I'm not looking for thoughts on the business logic or quality of the code (I have my own! ). Just want to confirm that you can't change the equality match in this way from one iteration to the next. In other words, that the equality match remains static ( = 1, in this case) for all iterations of the FOR loop. I hope that makes sense.
I read the FOR statement info in the docs but didn't find a direct answer to this question. Thanks in advance for any help.