In RPG ILE, I have an externally described file. I am chaining out to the logical file with a key & find the first record. Now, I want to know if the second record I'm looking for is before or after the first record in the file.
Software/Hardware used:
ASKED:
October 29, 2008 8:13 PM
UPDATED:
September 16, 2010 11:16 PM
I am sure you have a good reason for asking this, but I am not sure why this is necessary. Would you not be better off abandoning the chain, which the last time I looked did not guarantee to retrieve the first or last or any record identified by the key, but instead do a setll (or setgt) on the file and reade (or readpe) to get the records you are really after?
I was guessing that even though the program access the records through a logical with chains or a read loop the programmer needs to know which record arrived in the physical file first. Obviously a timestamp field would be ideal.
The following is true ONLY if your file does not reuse deleted records and has never been re-organized.
When a file contains multiple records with exactly the same key, your chain will return the record with the lowest record number first. A subsequent READE operation will return a record with a higher record number, same key. You can prove this by inspecting the RRN returned in the file info data structure.
It is not necessary to do a SETLL and READE instead of a chain. Same results either way. We had this discussion in our shop a last year and ran a test.
Once your file has been re-organized, this techinque will not work because there is not guarantee that the lowest record number in the original file will still be the lowest in the re-org’ed file. The keys will be just fine – no worries there.
WoodEngineer is right.
If the entire key is the same – not just the fields used for this access.
Otherwise it’s get the RRN.
But It’s a shame we haven’t gotten feedback from Stckrb
I want to know if the second record I’m looking for is before or after the first record in the file.
Please define “before” and “after”.
If you are using CHAIN, are you CHAINing by a key value or by relative record number? If you are CHAINing by key, the only rational meaning of “before” and “after” is “lower key” and “higher key”.
Is the file defined in RPG as ‘K’eyed? Or are you expecting to get the second record from a different open data path? Does the file have a FIFO or LIFO attribute? Is it opened as SEQONLY(*YES)? How are you expecting to get the second record? How will you recognize the second record?
Overall, the question doesn’t seem to make any sense.
More explanation is clearly required. A lot of questions can be asked to try to come up with a meaningful answer.
Tom
Jun an SQL against your physicl file. The SQL shall be something like this
I hope it helps.
DanF
You guys ..
.
But It’s a shame we haven’t gotten feedback from Stckrb
October 31, 2008
But in September 2010 you act like you can elicit a response.
Phil
“But in September 2010 you act like you can elicit a response.”
A discussion doesn’t require a response from the OP. Although it can be necessary in order to give an appropriate answer to a question, technical details around the issue can be even more valuable for the “Wiki”.
Besides, I haven’t seen a huge differences in getting responses from 2008 and from 2010!
Tom