Read & Write Flat file

100 pts.
Tags:
AS/400 flat file
Flat files
RPG/400
I want to read & write same flat file(CSV).For eg.If I have flat file structure in this way 1'PL','ABC'  2 'PL','DEF'  3'PP','BGC' In this I am reading only PL type of records.If it is PL type like 'ABC'then i am doing some processing & writing 'PL','RIC' record in to the same.After writing the record pointer will come at the end of file,but for the second read my pointer should be at 'DEF'.How will i set my pointer at 2 differant levels in same flat file for read & write .

Answer Wiki

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

Discuss This Question: 4  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
    How will i set my pointer at 2 differant levels in same flat file for read & write . Generally, you don't. That's not how updating usually works for streamfiles. There are two general methods.
    1. Open the file for reading. Open a second temporary file for writing. Read the data from the first file and copy to the second file. When you reach a point where you want to insert or delete or modify, then output the data to the second file as you want the change to be. Continue reading from one and writing to the other until you process the entire input file. Close the two files. Delete or rename the first file. Rename the second file to the original name and set its appropriate ownership and authority.
    2. Or read the entire file into memory. Make the updates in memory. When finished, copy your memory back out to the file.
    Some of that helps to explain why many database files will have more fixed-length records and fields. The database management layer handles the parts about repositioning within the file, and it is far easier when each record has the same length. This type of data processing is far better suited for database files. You can read and reposition in the file. See for example the lseek()--Set File Read/Write Offset API, but it's almost certain you don't want to use it for what you're asking about. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    BTW, the term "flat file" has at least three relatively common meanings. They are all distinctly different from the others. A .CSV file usually designates a particular organization of a streamfile. Streamfiles are one of the three common types of "flat files" On AS/400s, that usually means that the file resides in the /root file system (or a similar file system). If that isn't what you intend, then please give a more complete description of the file. Especially, what file system does it reside in? Tom
    125,585 pointsBadges:
    report
  • Rr22
    Thanks for the Reply.According to my requirement I want to read same flat file.I am writing in this differant types of records in this like PL,PR etc...The main requirement is one PL can be attached to other PL type of records & then again that PL can be attached to others PL.I have to run the loop till the the last level.So i am writing and reading records in same flat file.Please suggest.
    100 pointsBadges:
    report
  • TomLiotta
    So i am writing and reading records in same flat file. Again, what file system is your 'flat file' in? If it is a program-described 'flat file' in the /QSYS.LIB file system, or just a file with a single field in the record format, you can potentially get it done with some messy programming. However, you would probably do best by doing all of the work in temporary database files. Once you have the records in database files the way you want them, you can simply convert them to .CSV format. The conversion could be as easy as a single CPYTOIMPF command. It would be far easier doing it that way. 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