forcase loop with where

Discussions about editing and cleaning data
Post Reply
AriSilva
Posts: 386
Joined: July 22nd, 2016, 3:55 pm

forcase loop with where

Post by AriSilva » December 28th, 2019, 3:50 pm

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
Best
Ari

Gregory Martin
Posts: 1338
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: forcase loop with where

Post by Gregory Martin » December 30th, 2019, 8:14 am

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.

AriSilva
Posts: 386
Joined: July 22nd, 2016, 3:55 pm

Re: forcase loop with where

Post by AriSilva » January 6th, 2020, 11:36 am

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.
Best
Ari

Post Reply