Page 1 of 1

forcase loop with where

Posted: December 28th, 2019, 3:50 pm
by AriSilva
The help says it executes 1 or more times, even if the where condition is not satisfied.
Don't you think this is a little bit tricky? For example
forcase BRUMA_75_DOMICS_DICT where DD00_SETOR = setor do
.....
endfor;
Even if there are no cases in the file where DD00_SETOR = setor, the loop is executed once.
So, in order to catch only the cases where DD00_SETOR = setor, process and count them, you have to duplicate the where condition inside the for loop with a
if DD00_SETOR <>setor then next; endif;
It seems to me that the syntax to force at least one execution should be something like
forcase
.....
where ...
endfor;

Like the do ... while

Re: forcase loop with where

Posted: December 30th, 2019, 8:14 am
by Gregory Martin
When the help says that it "executes one or more statements," it means that you can have one or more than one statement within the loop. There is no guarantee that any statement in the loop will be executed, however, either because there are zero cases, or because of a where condition. For example this will not execute anything:
forcase MY_DICT where 1 = 0 do
Hopefully that clarifies things.

Re: forcase loop with where

Posted: January 6th, 2020, 11:36 am
by AriSilva
My fault, I read "one or more statements" and understood "one or more times"
My program had a bug and I thought that it was because of the forcase loop.