×
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.
Why doesn't a failed CHAIN (which sets off %FOUND) also set on %EOF?
Because CHAIN jumps straight to a particular record. Either that record is
there or it isn't. It has no concept of whether it's at the end of the
file or not. Wait... that's not entirely true. If it succeeds in reading a
record it knows it's not at the end of the file :) But, when it fails, it
doesn't know.
Rather that doing a SetLL/ReadE combo to start the loop it used to be
shorthand to code a Chain with:
Chain ( SomeKey ) File;
DoW Not %Eof( File );
// do something
ReadE ( SomeKey ) File;
EndDo;
Don't think of %EOF or %FOUND as a replacement for the indicators declared
in your program. Think of them as a replacement for the HI-LO-EQ positions
of the source record.
CHAIN always set the "HI" indicator, which meant "%FOUND". READ and READE
always set the "EQ" indicator which meant "%EOF". When they designed the
BIFs they followed the same philosophy. Granted, they probably should've
looked at how RPG programmers used this capability instead of just copying
the way it's always worked -- BUT that's what they did.
Anyway, assuming that you followed that logic :) you can do what you
always did:
chain (SomeKey) File;
*IN67 = not %found;
dow not *in67;
// do something
ReadE ( SomeKey ) File;
*IN67 = %eof;
EndDo;
Even better, using the BIFs you can also use a named indicator!
D success s 1N
. . .
chain (SomeKey) File;
success = %found;
dow success;
// do something
ReadE ( SomeKey ) File;
success = not %eof;
EndDo;
Always better to use meaningful names!
Any possibility of getting Chain to set the %EOF indicator as well as
the %FOUND indicator? Or would that break existing code?
If you're going to "fix" it, I'd suggest that it'd be better if they
actually worked like functions and RETURNED whether they were successful
or not. That way you could code your loop as follows:
setll (SomeKey) File;
dow (%READE (SomeKey) File);
// do something
EndDo;
That makes the loop far more elegant, and eliminates the need for the
awkward "priming read" and "read again at the end of the loop". If
they're going to change it anyway, wouldn't that be better?
As an Amazon Associate we earn from qualifying purchases.
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.