Question on SETGT

pts.
Tags:
Programming Languages
RPG
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: 3  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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • 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:
    report
  • 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:
    report
  • 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:
    report

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following