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

Problem with OPEN DATASET

Former Member
0 Likes
880

Hi abapers,

the "open dataset"-command opens a datafile within the given directory. if this file already exists, the system clears all content of this file. Is there any chance to avoid this situation?

thx a lot for help,

marcel

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
844

thx a lot for fast answer,

my problem is, that in no cases it should be possible to change an existing datafile. Or if a user opens the same datafile, he should be able to choose, if he want to overwrite the existing file or to chooose an other filename.

is there any chance to solve that?

thanks a lot,

marcel

7 REPLIES 7
Read only

Former Member
0 Likes
844

use APPENDING MODE instead of just <b>FOR OUTPUT</b>

example :

Opening a File for Appending Data

To open a file so that you can append data to the end of it, use the FOR APPENDING addition in the OPEN DATASET statement:

Syntax

<b>OPEN DATASET <dsn> FOR APPENDING.</b>

regards

srikanth

Message was edited by: Srikanth Kidambi

Read only

Former Member
0 Likes
844

Hello,

OPEN the file in APPEND mode if you want to continue writing in the same file.

OPEN XXXXXX FOR APPENDING .

Regs,

Venkat Ramanan N

Read only

Former Member
0 Likes
844

hi,

Open dataset datasetname for <b>appending</b> .....

Use appending, instead of output, then the contents of the file will not be erased when the file exists. If the file is not exisitng, it creates a new file again.

Regards,

Sailaja.

Read only

Former Member
0 Likes
844

Hi ,

Did you try the option <b>APPPEDNING</b> ?

OPEN DATASET dsn.

Additions:

1. ... FOR INPUT

2. ... FOR OUTPUT

3. ... FOR APPENDING

4. ... IN BINARY MODE

5. ... IN TEXT MODE

6. ... AT POSITION p

7. ... TYPE ctrl

8. ... MESSAGE mess

9. ... FILTER f

Regards,

Varun .

Read only

Former Member
0 Likes
844

use OPEN DATASET dsn FOR APPENDING

Read only

Former Member
0 Likes
845

thx a lot for fast answer,

my problem is, that in no cases it should be possible to change an existing datafile. Or if a user opens the same datafile, he should be able to choose, if he want to overwrite the existing file or to chooose an other filename.

is there any chance to solve that?

thanks a lot,

marcel

Read only

0 Likes
844

if you are taking the file name from the selection screen,then you can do like this.

P_FILENAME Is your Selection-screen parameter to hold the file name on application server.

AT SELECTION-SCREEN.

*--Validate application server file.

<b> OPEN DATASET P_FILENAME <b>for INPUT</b> in TEXT MODE

encoding Default.

*--Here we are just checking the FILE already exists or not.by opening the file in INPUT MODE</b>

if sy-subrc = 0.

*--subrc = 0 means,already file exists. so you can give an information/error message to the user,that file already exists.

close dataset v_filename.

endif.

Regards

srikanth

Message was edited by: Srikanth Kidambi