|
Gerardo,
This will work nicely assuming you are writing to a Windows-style text
file. (i.e. a text file where lines are terminated with the CR and LF
characters.)
I won't reiterate what Vern already said, and you've already discovered,
but there are a few extra things that are probably worth noting:
1) When you write data (with the write API) it writes at the spot in the
file where things are currently positioned. When a file is opened, the
file position will default to byte 0 (the start of the file) so when you
write, it'll overwrite from the start. In your case, you are clearing the
file (O_TRUNC does that) so this works nicely.
2) If you wanted to add your data to an existing file, you can add the
O_APPEND flag to your open() call. This will force writes to be at the end
of the file instead of the start.
3) Or, if you want to overwrite existing data _and_ be able to write at
the end in a single open, the lseek() API can be used to set the position,
so you can set it at the start of the file, or the end of the file, or at
any arbitrary byte position in between. If you do that, write() will write
the data at whichever point you set it at.
Please do remember that this is a stream file, not a record-based file.
So the system doesn't know that the file is organized into records. When
you overwrite stuff, you are overwriting a range of bytes in the file, not
a "record." This can make a huge difference if the length of the record
doesn't match the one you're overwriting!
-SK
On 10/15/2014 12:49 PM, Gerardo Alberto Martinez Rosales wrote:
Thx VernThis is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
That is the solution, I was looking
To create a new line in file IFS
The solution is
crlf s 2 inz(x'0d25)
Open ......
Eval data = ('line one' + crlf)
Callp write(.....
Eval data = ('line two' + crlf)
Callp write(......
Callp close(dd)
Thx very much
Again Vern.
Regards.
On Oct 15, 2014 11:25 AM, "Vernon Hamberg" <vhamberg@xxxxxxxxxxxxxxx>
wrote:
Geraldo
--
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.