Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Open Dataset - Edit Line

0 Likes
1,289

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

3 REPLIES 3
Read only

geert-janklaps
SAP Mentor
SAP Mentor
0 Likes
1,152

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

Read only

RaymondGiuseppi
Active Contributor
1,152

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.

Read only

Sandra_Rossi
Active Contributor
1,152

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?