While what you quoted doesn't say this, I'm guessing a Chain that results in no hit, does not change the file position. So with your read before the chain having already read successfully, it set the file position, the failed Chain did not move it, so the read after the Chain "works" and reads the next record.
So the line from the documentation that backs up what I just said comes right before what you quoted:
"When the CHAIN operation is successful, the file specified in name is positioned such that a subsequent read operation retrieves the record logically following or preceding the retrieved record."
Specifically, it's saying that the file is positioned after a successful chain. So if it's not successful, it's not positioned. That's my take. Keep in mind that I don't recall the last time I coded a Chain and then a Read to follow it.
Kurt Anderson
Sr. Programmer/Analyst - Application Development, Service Delivery Platform
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Vernon Hamberg
Sent: Friday, December 18, 2015 9:18 AM
To: RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>
Subject: CHAIN not found and subsequent READ - docs wrong?
Y'all
The ILE RPG Reference has this to say about a CHAIN that does not complete -
"When the CHAIN operation is not completed successfully (for example, an error occurs or no record is found), the file specified in name must be repositioned (for example, by a CHAIN or SETLL operation) before a subsequent read operation can be done on that file."
Now I've seen that when record-not-found happens, that I can do a READ without repositioning, no problem. Here's the scenario -
READ keyedfile fileds;
CHAIN somekey keyedfile fileds; (%found(keyedfile) = *OFF)
READ keyedfile fileds;
The 2nd READ returns the record that follows the one returned by the first READ - so the READ continues from where things were before the failed CHAIN.
That seems NOT to be how the documentation says it should work - I did not have to do another successful CHAIN or SETLL - "successful" is my word added as my assumption.
Confirm or deny, anyone?
Cheers
Vern
--
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.
As an Amazon Associate we earn from qualifying purchases.