0 pts.
 Question on SETGT
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

Answer Wiki:
The setgt with 10013 will position the file pointer between 10015 and 10012. The read will get 10012.
Last Wiki Answer Submitted:  April 18, 2005  9:12 am  by  Preston   0 pts.
All Answer Wiki Contributors:  Preston   0 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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

 370 pts.

 

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.

 0 pts.

 

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

 108,215 pts.