25 pts.
 Reading a file in Reverse Order in CL Program
) In CL program how can we read a data base file in reverse order.

Software/Hardware used:
ASKED: March 23, 2011  3:28 AM
UPDATED: March 26, 2011  12:16 AM

Answer Wiki:
Can you give us the business case for this. There may be a better design.
Last Wiki Answer Submitted:  March 23, 2011  7:46 pm  by  CharlieBrowne   32,905 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,905 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

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

 108,145 pts.

 

Depending on what exactly you mean by ‘reverse order’, OPNQRYF may be the answer to your question.

 5,670 pts.

 

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

 108,145 pts.

 

just use the Keyfield of opnqryf as *descend.

 380 pts.

 

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.

 900 pts.

 

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

 108,145 pts.