This gets my vote too. I've always done a priming loop for the same reason Vern lists. Most of the time, I invoke a sub-procedure to do all the work (...do stuff...) so it is a very simple loop.
Us Dr. Pepper guys have to stick together Vern.
Roger Harman
COMMON Certified Application Developer - ILE RPG on IBM i on Power
________________________________________
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxx> on behalf of Vernon Hamberg <vhamberg@xxxxxxxxxxxxxxx>
Sent: Tuesday, March 8, 2016 9:16 AM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Re: READE Question
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
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.