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

Delete Dataset File not working

Former Member
0 Likes
4,938

Hi All,

I am trying to delete file from application server (AL11) directory after processing using DELETE DATASET FILE is not working , after processing also file still exists.

My code is like this,

&----


*& Form backup_file

&----


  • The file has been processed. Go ahead and copy it to the

  • backup directory and delete it from the processing directory.

----


FORM backup_file .

DATA: lv_oldfile TYPE string,

lv_backup TYPE string,

l_rc TYPE i.

IF p_appl = 'X'. "Unix file

lv_oldfile = wa_files-filename.

  • Replace the directory name with the backup directory.

REPLACE p_dir IN wa_files-filename WITH p_back.

  • Tack date/time onto the end of the file name to avoid duplicate

  • files

CONCATENATE wa_files-filename

'_'

sy-datum

'_'

sy-uzeit

INTO wa_files-filename.

OPEN DATASET wa_files-filename FOR OUTPUT

IN TEXT MODE

ENCODING DEFAULT.

IF sy-subrc NE 0.

f_backup_error = 'X'.

EXIT.

ELSE.

  • Write the file contents to the new backup file.

LOOP AT itab_input INTO wa_input.

TRANSFER wa_input TO wa_files-filename.

ENDLOOP.

ENDIF.

  • Close the backup file.

CLOSE DATASET wa_files-filename.

  • Delete the original file from the processing directory.

if sy-subrc = 0.

DELETE DATASET lv_oldfile.

endif.

endform.

Thanks Everyone!

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,522

Check the value of sy-subrc after delete statement.

Check whether you have authorization for delete

check link:[http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3d5c358411d1829f0000e829fbfe/content.htm]

Hi All,

I am trying to delete file from application server (AL11) directory after processing using DELETE DATASET FILE is not working , after processing also file still exists.

My code is like this,

&----


*& Form backup_file

&----


  • The file has been processed. Go ahead and copy it to the

  • backup directory and delete it from the processing directory.

----


FORM backup_file .

DATA: lv_oldfile TYPE string,

lv_backup TYPE string,

l_rc TYPE i.

IF p_appl = 'X'. "Unix file

lv_oldfile = wa_files-filename.

  • Replace the directory name with the backup directory.

REPLACE p_dir IN wa_files-filename WITH p_back.

  • Tack date/time onto the end of the file name to avoid duplicate

  • files

CONCATENATE wa_files-filename

'_'

sy-datum

'_'

sy-uzeit

INTO wa_files-filename.

OPEN DATASET wa_files-filename FOR OUTPUT

IN TEXT MODE

ENCODING DEFAULT.

IF sy-subrc NE 0.

f_backup_error = 'X'.

EXIT.

ELSE.

  • Write the file contents to the new backup file.

LOOP AT itab_input INTO wa_input.

TRANSFER wa_input TO wa_files-filename.

ENDLOOP.

ENDIF.

  • Close the backup file.

CLOSE DATASET wa_files-filename.

  • Delete the original file from the processing directory.

if sy-subrc = 0.

DELETE DATASET lv_oldfile.

endif.

endform.

Thanks Everyone!

4 REPLIES 4
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,523

Check the value of sy-subrc after delete statement.

Check whether you have authorization for delete

check link:[http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3d5c358411d1829f0000e829fbfe/content.htm]

Read only

Former Member
0 Likes
2,522

Try to use OPEN DATA before using DELETE. Check this: http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3d28358411d1829f0000e829fbfe/content.htm

Thanks

Satyasuresh Donepudi

Read only

Former Member
0 Likes
2,522

HI,

You have to check the value of Sy-subrc after the delete statement,

and the value present in the variable lv_oldfile that if there is correct

value in the variable populated or not.

Moreover after assigning the value to variable lv_oldfile in the step

lv_oldfile = wa_files-filename.

then you should use this variable lv_oldfile only for open dataset and close dataset also.

Hope ir helps

Regards

Mansi

Read only

Former Member
0 Likes
2,522

Hi Thanvi,

First open the dataset for output for lv_oldfile. and then use DELETE DATASET lv_old file.

You cannot delete the file unless you open the file for output.