AS/400 Scenario

770 pts.
AS/400 Records
Q. I have a file with millions of records and I want to read the last record from that file.But the conditions are as follows(assume): 1. The file do not have any key field. 2. The file do not give any RRN Number(Assume). 3. We are not allow to use the loop till EOF as we have millions of records. So taking care of the above conditions how to read the last record from the file.

Software/Hardware used:

Answer Wiki

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

Thank you for visiting ITKE.

We are happy to help you with solving specific IT questions, but need as
much information as possible to do so. Let us know about the problem you
are trying to solve, how you are approaching it and what work you’ve
done so far, and we can help guide you in the right direction.

Discuss This Question: 9  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.
  • TomLiotta
    The setup seems almost academic. To require the reading of just the last record out of millions seems to indicate a database structure that needs to be fixed. What language are you allowed to use? You might use OVRDBF POSITION(*END) before calling your program, and then use a read-previous operation in your chosen language. There are also language-specific alternatives. Tom
    125,585 pointsBadges:
  • BigKat
    no almost about it Tom, that question has to be pure homework
    9,460 pointsBadges:
  • TomLiotta
    @BigKat: I'd like to be sure. A number of real-life encounters in the past couple years have made me more cautious -- admins(!) who don't know how to look at messages, don't know where joblogs are nor how to generate them, you name it. So, I figure it's okay to refer to a "read-previous operation" without saying how to do it. The worst that would happen is a search in a reference guide, and that's probably the best thing to learn anyway. And if it becomes a dialog, enough info should come out to be sure. Tom
    125,585 pointsBadges:
  • ankit2002
    Guys I tried this it was giving the right result. *HIVAL SETGT Filename READP Filename Name DSPLY
    770 pointsBadges:
  • Splat
    You could use the INFDS to retrieve the number of records in the file then retrieve the last record by RRN. Please note, this wouldn't work if your file is defined as REUSEDLT(*YES).
    12,915 pointsBadges:
  • TomLiotta
    ...this wouldn’t work if your file is defined as REUSEDLT(*YES). Of course, no other method would work either. That is, without something to key on, e.g., a timestamp, the only way to find a 'last record' is to use the highest available RRN. The INFDS works just as well for that as anything else. By 'key on', I simply mean a value that can be recognized. It doesn't need to be an index key. But the restrictions say that records cannot be read in order to test their values. The only thing available that I can think of is highest RRN. If REUSEDLT(*YES) is in effect, it still goes straight back to thinking that it's a database that is in trouble and needs to be rearchitected. Tom
    125,585 pointsBadges:
  • Yorkshireman
    So if its homework - and that seems likely, as any IBM i system with a file of that nature wouldn't have a file like that, then we contribute to the frovolity by answering. But it is intriguing. Probably aimed at PC geekdom, where they get themselves into such troubles. you could postulate access by disk address if you're geeky - read the FAT, go to a location - that would be geeky. I could suggest an obvious DB2 solution to such a question, but I'll keep quiet. Oh wait - 2 solutions.
    6,085 pointsBadges:
    Only way to learn something new is to try yourself. Internet is a great option these days for answers for home work questions.
    3,175 pointsBadges:
  • Kellyd
    SQL? select * from tablename where idColumn in (select maidcolumn ) from table ) select * from tablename where idColumn in (select max ( idcolumn ) from table )
    100 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: