Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP File Interface →  Statements for the ABAP File Interface 

DELETE DATASET

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


DELETE DATASET dset. 

Effect

The statement deletes the file specified in dset. dset expects a character-like data object containing the physical name of the file. The file can be opened or closed.


Note

When a file is deleted, automatic authorization checks are performed; self-programmed checks may also be necessary.

Security Note

Access to a file whose name dset is injected into a program from outside is a serious security risk. Any names passed to a program from outside must be checked thoroughly before being used. See Directory Traversal.

Return Value

sy-subrc Meaning
0 File has been deleted.
4 File could not be deleted.

Exceptions

Handleable Exceptions

CX_SY_FILE_AUTHORITY

  • Cause: No authorization for access to file
    Runtime error: OPEN_DATASET_NO_AUTHORITY (can be handled)

CX_SY_FILE_OPEN

  • Cause: File cannot be opened
    Runtime error: DATASET_CANT_OPEN (can be handled)


Example

Opens a file for writing and reading and then deletes the file.

DATA(dset) = 'test.dat'. 

OPEN DATASET dset FOR OUTPUT IN BINARY MODE. 
  ... 
CLOSE DATASET dset. 

... 

OPEN DATASET dset FOR INPUT IN BINARY MODE 
  ... 
CLOSE DATASET dset. 

DELETE DATASET dset.