‎2008 Mar 11 8:48 AM
I want to create a file in a particular location. I am getting Runtime error if there already exists a file with the same name and with more than 35 MB of size.
The runtime error is as follows.
Runtime Errors DATASET_NOT_OPEN
Exceptn CX_SY_FILE_OPEN_MODE
If there exists a file already with the same name and lesser size, The program could able to recreate the file with the new data, the problem exists only if the existing file is Larger.
Following is the code I am using.
open dataset p_outf1 for output in text mode encoding default.
x
x
x
transfer excel to p_outf1.
x
x
close dataset p_outf1.
Please advice, helpfull answers are rewarded.
Thanks,
Veeru.
‎2008 Mar 11 8:51 AM
Hi,
Do like this
*--Local Variables
DATA : l_erfile TYPE string.
*--Clear file
CLEAR : l_erfile.
l_erfile = p_erfile.
*--Open dataset for output mode to transfer the error log
OPEN DATASET l_erfile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
IF NOT it_erfile[] IS INITIAL.
LOOP AT it_erfile INTO st_erfile.
TRANSFER st_erfile TO l_erfile.
CLEAR : st_erfile.
ENDLOOP.
ENDIF.
ENDIF.
Regards,
Prashant
‎2008 Mar 11 8:52 AM
Hi,
This is the code that i have used in my development and it is working fine with any size of the file i normally overwrite it. sometimes it consists of huge data and sometimes it does not contain any data.
OPEN DATASET target FOR OUTPUT IN TEXT MODE.
IF sy-subrc <> 0.
WRITE:/ 'Cannot open ',target ,/ 'error = ', sy-subrc.
STOP.
ENDIF.
LOOP AT itbl.
TRANSFER itbl TO target.
ENDLOOP.
CLOSE DATASET target.
Try this if it can help u
Reward if helpful
‎2008 Mar 11 8:53 AM
Hello,
If the File is already existing with the same name then use APPENDING key word
... FOR APPENDING
Effect
OPEN ... FOR APPENDING tries to open the file in 'append' mode. If the file is already open, the system moves to the end of the file. When you open a file using FOR APPENDING, attempting to read the file sets SY-SUBRC to 4. The system display the end of the file.
Note
You can only use one of the additions 1 to 3 in a single statement.
If you want to recreate the file then delete the file before recreating using
DELETE DATASET dsn.
Effect
Deletes the file specified in the field dsn.
The return code is set as follows:
SY-SUBRC = 0:
File deleted.
SY-SUBRC = 4:
File does not exist or could not be deleted.
Possible reasons:
1) The file does not exist.
2) The file is a directory.
3) The R/3 System has no search authorization
for a component of the file name.
4) The R/3 System has no search authorization
for the directory which contains the file.
5) A component of the search path is not a
directory.
6) The file is a symbolic link which cannot be
resolved (endless loop ?).
7) The file is a program which is currently
running.
Note
The system automatically performs an authorization check. If the user does not have the appropriate authorization, a runtime error occurs. You can check the existence of an authorization with the function module AUTHORITY_CHECK_DATASET.
Catchable runtime errors
The following runtime errors can occur with this variant:
DATASET_CANT_OPEN: Unable to open file.
OPEN_DATASET_NO_AUTHORITY: You are not authorized to access a file.
Hope this will helps you.
Cheers,
Vasanth