Suppose if my logical file has records arranged in descending order of key field..say the LF has the following records
EMPNO
10020
10015
10012
10011
10008
10005
10004
Now if I do SETGT with search argument as 10013, will the file pointer position on 10015 and the read operation will read 10015, the next read will read 10012 and so on.
Please confirm the above.
Thanks
Software/Hardware used:
ASKED:
April 16, 2005 9:49 PM
UPDATED:
October 22, 2009 6:52 AM
Sorry, I have to disagree with Preston’s answer.
The SETGT will position the file pointer to the first key value that is greater than the value passed.
In the example used in the question, a key value of 10013 will position at 10020 – the first record with a key greater than 10013.
The first record read will be 10020 followed by 10015, 10012, etc.
This is the problem with using SETGT on a descending key. You would probably be better off using SETLL if you want to start at 10012.
All the best
Jonathan
Preston is actually correct. The value is greater, but the key is previous, hence RPG will return 10012 as the next record. Try a quick example if you don’t believe it. IBM was smart enough to build in the logic for this into DB2 (and OS/400) when you’re dealing with descending keys.
Effectively, SETGT and SETLL do not position “at” records; they position between records. That’s why SETLL works as it does with ascending keys and SETGT works as it does with descending keys. Depending on ascending or descending, the two op-codes work the same way.
Tom