Reading a file in Reverse Order in CL Program

25 pts.
Tags:
AS/400 database
CL Program
Database Files
) In CL program how can we read a data base file in reverse order.

Answer Wiki

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

Can you give us the business case for this.
There may be a better design.

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.

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
  • TomLiotta
    CL is not a database processing language, so it shouldn't be used for processing database files. Use an appropriate language. If reverse reading is needed in CL, then create a VIEW (or LF) that presents the rows in reverse order (descending order) and read the VIEW. Tom
    125,585 pointsBadges:
    report
  • Splat
    Depending on what exactly you mean by 'reverse order', OPNQRYF may be the answer to your question.
    7,635 pointsBadges:
    report
  • TomLiotta
    If we're talking about reading a file through a reversed index or key, then OPNQRYF is a perfectly valid solution. I'm not aware of any OPNQRYF function or parameter that will provide a simple reverse reading of a file, though. Record numbers don't seem to be available to OPNQRYF. Of course, if the file is ordered by a key value, then reading by descending keys will give the same result as reading the file in reverse (with CL). Tom
    125,585 pointsBadges:
    report
  • Chraghuveer
    [...] 8. CharlieBrowne, TomLiotta, and Splat are awaiting a response in order to help a member read a file in reverse order in CL Program. [...]
    0 pointsBadges:
    report
  • jainamit
    just use the Keyfield of opnqryf as *descend.
    380 pointsBadges:
    report
  • Sai4AS400
    Hi Tom, How to create a LF that represents the records in Reverse Order.i mean what steps i do need to follow while creating LF in this Case?..please reply me.
    1,420 pointsBadges:
    report
  • TomLiotta
    An indexed (keyed) logical file is created for reading by key in reverse by specifying the DESCEND keyword. But that's not necessarily the same as "reverse order" for a physical file. If "reverse order" means "reverse arrival sequence", then there is no specification for it. And "arrival sequence" for a file defined with REUSEDLT(*YES) has even less practical meaning because there's no way to determine what the actual arrival sequence was without relying on a data column such as a timestamp (or a journal entry sequence that covers the life of the file). -- Tom
    125,585 pointsBadges:
    report
  • dinuas400
    Using OPNQRYF and OVRDBF we can achieve this requirment....
    510 pointsBadges:
    report
  • TomLiotta

    Using OPNQRYF and OVRDBF we can achieve this requirment….

    That is only true if an appropriate field matches the forward-order of the file. Since OPNQRYF does not support a 'relative record number' feature, it can't be used to provide a reverse order.

    However, if some field value is naturally ascending in the forward-order of the file, then that field can be specified as DESC to present the records in descending sequence.

    That is rarely the case, so, in general, OPNQRYF can't help.

    Still, as has already been mentioned, "reverse order" needs to be defined before a valid answer is possible.

    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