Crispin,
I am not sure if it is just self-imposed or if I was told by someone when I was a young programmer, but I never, never, never chain with a partial key on a logical file. Strange things can happen and as we see from this thread, it is confusing to the programmers that follow behind you.
Maybe it comes down to programming "style."
In my book CHAIN is reserved for when I need to update a record in a file, the CHAIN should use a complete key that satisfies all fields in a unique logical file.
I use SETLL and READ/READE for everything else. (Sometimes the SETLL is enough and you never even need to do the read, performance bonus!)
Charlie
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Crispin
Sent: Thursday, March 28, 2013 2:12 PM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Re: CHAIN on a Partial Key
Charlie,
I've always thought of the "Random" in "Random Retrieval from a File" as a reference to how the programmer wants to access the data (as opposed to sequential - READ/READE) rather than what the OS will return.
In the OP's example, when the file has 2 keys I would expect CHAIN KEY1 FILEX; to always return the same record, no randomness to it, and that record should be the first record with the first key that satisfies the second keys collating sequence (or FIFO/LIFO/FCFO etc. as Chuck pointed out when there are duplicates) for a blank/zero key.
I personally can’t see how that could ever be affected with a subsequent release of the OS, it is the expected behavior for files with compound keys.
If it changed, I think there'd be a whole load of broken software our there...
Crispin.
The definition of Chain is a Random Retrieval from a File.
If IBM tells me something is random, I take that to heart.
Because, how the database retrieval works today might not be how it
works under a different version of the operating system. There are too
many variables to try and decipher. (does your file reuse deleted
records? If all logical files are deleted and rebuilt, the sequence
they are rebuilt in also can have an effect)
As others have suggested, to eliminated all doubt, sounds like you
should be using SETLL and READE.
Documentation is the IBM RPG ILE Programmer Reference.
http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frza
sd%2F
sc092508914.htm
Chain has been defined as random retrieval for as long as I can remember.
Charlie
--
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.