2021 Feb 17 12:02 PM
Hey,
i have a Question of using OPEN DATASET .
I just want to append a special Test to a line in an already existing '.TXT' file.
TXT File Example.
Line 1: ABC
Line 2: DEF
Line 3: JKL
Now i want to append 'GHI' to Line 2.
I just tried to read the line, concatenated 'GHI' and TRANSFER it again, but the following line got overwritten by this.
So there ist only
Line 1: ABC
Line 2: DEFGHI
left. Can you help me how to insert Text into special lines without overwriting the following?
Best regards
Hey,
i have a Question of using OPEN DATASET .
I just want to append a special Test to a line in an already existing '.TXT' file.
TXT File Example.
Line 1: ABC
Line 2: DEF
Line 3: JKL
Now i want to append 'GHI' to Line 2.
I just tried to read the line, concatenated 'GHI' and TRANSFER it again, but the following line got overwritten by this.
So there ist only
Line 1: ABC
Line 2: DEFGHI
left. Can you help me how to insert Text into special lines without overwriting the following?
Best regards
2021 Feb 17 1:49 PM
Hi,
Can you share the code you're using to append data to the file?
I guess you should first read the full file into e.g. an internal table, modify your internal table as desired and then write the file to the application server again based on the contents of your internal table.
Best regards,
Geert-Jan Klaps
2021 Mar 03 3:44 PM
The file opened by OPEN DATASET is a flat file without any index or the like.
" ABC<clrf>DEF<clrf>JKL<clrf><eof>
Depending on your code, you got
" ABC<clrf>DEFGHI<clrf><clrf><eof>
or
" ABC<clrf>DEFGHI<clrf><eof>
You can append new text at the end of the file, but not in the middle, so you should read the whole file (usually in an internal table splitting data at <crlf> with the IN TEXT MODE) insert/replace the text in your code and send the whole data back to the file.
2021 Mar 03 5:25 PM
You can't insert in the middle of the file, you may only append at the end.
Even if someone invented an API to insert some text in the middle of the file, the whole file should be rewritten on the disk because the rest of the file is shifted.
Don't you want to use a database table instead?
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |