× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



You pays your money - you takes your choice!

I prefer priming a DOW loop with a READ of whatever sort - I don't really like doing a LEAVE in the middle for EOF condition - seems too much like a GOTO abuse.

But this is personal taste for the most part - I agree with using the file name in the %eof() - keeps things clear. And ensures testing the right condition.

Here's a "priming" version of the 2nd one below - only 1 %eof test - even though this shows 2 reads - and I might add a %equal test - as someone else suggested - it's like what I do in embedded SQL - after an OPEN I check SQLCOD = 0, then do my first FETCH if successful. Then a DOW of SQLCOD there. I digress!!

firstkey setll file
firstkey reade file

do while not %eof(file)

if not SkipCondition
...do stuff...
endif

firstkey reade file
enddo


On 3/8/2016 9:03 AM, Joe Pluta wrote:
On 3/7/2016 10:22 AM, Wilson, Jonathan wrote:

firstkey setll file
do until %eof
firstkey reade file
if %eof
leave
endif
...do stuff...
enddo


I like this a lot, because it also allows for this:

firstkey setll file
do until %eof(file)

firstkey reade file
if %eof(file)
leave
endif
if SkipCondition
iter
endif

...do stuff...

enddo


I can insert a skip condition and if I don't want to process the record, I can just ITER to go get the next record. Also, I always put the filename in my %EOF. It may be overkill, but I've gotten into the habit.

Note that you can also put a check in prior to the loop to check for no records if that's an error condition:

firstkey setll file
if not %equal(file)
...no records, log error, exit...
endif
do until %eof(file)


Joe



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.