Reading a file twice in CL

0 pts.
Tags:
AS/400
Database
DB2 Universal Database
RPG
I declared a file in CL. I read all the records, i.e End Of File has reached. Now again i want to read he file from beginning within the same program.I tried with OVRDBF and POSDBF.But could not succeed.Can any body help me?
ASKED: November 3, 2005  6:53 AM
UPDATED: November 18, 2009  3:14 PM

Answer Wiki

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

Hi,

If you have V5.3 installed on your AS/400 then you declare the same file twice.

I have not yet tried on older versions.

Best of luck.

Discuss This Question: 8  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
  • Shellvacation
    You might try the position database file command before reusing the file. POSDBF OPNID(FILENAME) POSITION(*START) Good Luck!
    0 pointsBadges:
    report
  • Brami06
    You may want to create a second CLP that performs the reads to the file and call this from the original CLP. This way when you exit the called program, files are closed. When you call the program a second time, the file will be able to be read from the beginning without any problems. I had a similar situation recently and this worked flawlessly not to mention it broke the CLP down into managable modules (I was reading about 4 different files)
    0 pointsBadges:
    report
  • TheQuigs
    Prior to V5R3, when you do a RCVF and it hits end of file, the system closes the file. You cannot read the same file from the same invocation of the CL again.
    0 pointsBadges:
    report
  • Tektom
    I agree with the poster that said it's cleaner to break the process into several steps. If you must stay within the same program for some reason, you can use TFRCTL to re-invoke the program you are in, allowing you to re-open and re-process the file. To keep track of whether you're reading the file the first time or the second, you can change the job's switch settings - CHGJOB SWS('10000000') - to indicate you're in the second invocation.
    0 pointsBadges:
    report
  • Kumari
    Thank You so much for all your messages. My AS400 machine version is V5R1. I tried with TFRCTL and it worked fine. Thank You So much guys.
    0 pointsBadges:
    report
  • TomLiotta
    It doesn't matter what version you have. Once a CL program reaches end-of-file for any declared file, that file cannot be read again in that program. If your version supports multiple DCLFs, you can read through each one to end-of-file. This is covered in the fundamentals of CL programming. Read the manual. Tom
    125,585 pointsBadges:
    report
  • bvining
    V6R1 has the CLOSE CL command which does allow a CL program to close a database file upon reaching end-of-file (or at any other time for that matter). The next RCVF operation to the "closed" file will cause the file to be implicitly reopened for further use
    6,240 pointsBadges:
    report
  • Cwc
    Although this is quite an old thread, now that it has been resurrected, here's another method that I ran across a while back and saved for future reference. The key is to not let the file pointer reach the end of file condition. Thus, by knowing the number of records in the file, you can avoid doing the last read that wil cause end of file. To reposition the file pointer in CL program. 1. Use the Number of current records (NBRCURRCD) parameter of the Retrieve Member Description (RTVMBRDR) command to determine the number of active records in the member. 2. Override the database file to SHARE(*YES). This establishes an open data path (ODP) and allows the Position Database File (POSDBF) command to function properly. 3. Use the Open Database File (OPNDBF) to establish a file ID link that can be referenced by POSDBF. 4. Count the records as you process them. 5. When the record counter matches the number of active records, you have processed the last record. Use the POSDBF command to reset the file pointer to the first record. Be aware that this technique won’t work correctly if other jobs are adding records to the file, or deleting records from the file, at the same time.
    4,290 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