25 pts.
 In a single CL Program, can we read a database file more than once?
In a single CL Program, can we read a database file more than once

Software/Hardware used:
AS400
ASKED: March 22, 2011  8:03 AM
UPDATED: March 22, 2011  6:11 PM

Answer Wiki:
you can use POSDBF to reposition the file to *START to re-read it
Last Wiki Answer Submitted:  March 22, 2011  11:25 am  by  BigKat   7,185 pts.
All Answer Wiki Contributors:  BigKat   7,185 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

You don’t tell us what version your system is at, so it’s hard to know the right answer. If you’re at v6.1 or later, review Reading a file twice in CL before anything else.

If you’re at V5R4 or earlier, then a single CL program cannot read the same file again after reaching end-of-file. That’s simply the way it works. CL is a control language not a database processing language.

You can work around it it two general ways.

You can split your program into two programs — one for an outer control structure and the other for the file-processing portion. The outer control code would call the inner program twice (or as many times as needed.)

Or you can use RTVMBRD or a similar function to retrieve the number of records in the file before you start to read it. As you read records, keep count of them and compare your count to the number of records in the file’s member. Stop reading after you have counted as many are in the file. If you try to read one more than that, end-of-file will be reached and you can’t go beyond that. But if you stop just before end-of-file is signaled, you can reposition back to *START and read again.

Tom

 108,135 pts.