Question on SETGT

5 pts.
Programming Languages
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

The setgt with 10013 will position the file pointer between 10015 and 10012. The read will get 10012.

Discuss This Question: 7  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • astradyne
    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 pointsBadges:
  • TheQuigs
    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 pointsBadges:
  • TomLiotta
    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
    125,585 pointsBadges:
  • TooOldToRockNRollTooYoungToDie
    Given the example, would the record retrieved be the same (10012) after a SETLL 10013 and after a SETLL 10012?
    10 pointsBadges:
  • GregManzo
    No, a SETLL to 10013 will read 10012 as the next record, but a SETLL to 10012 will read the next lower key: 10011.
    2,970 pointsBadges:
  • azohawk This documentation shows a diagram near the bottom for ascending, but the principle would be the same.  I find the visualization helpful.  We are all presuming what was not explicitly stated in the OP that the key field is in fact EMPNO.
    4,065 pointsBadges:
  • ToddN2000
    Another sure way to prove what is going on it to run the program using the debug process and run it step by step to tack the values being read in. 
    136,350 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: