To delete a file from the application server, use the DELETE DATASET statement:
Syntax
DELETE DATASET <dsn>.
This statement deletes the file <dsn>. The naming convention is described in the section
Opening a File.If the system deletes the file <dsn> successfully, SY-SUBRC is set to 0. If not, it is set to 4.
DATA FNAME(60) VALUE 'myfile'.
OPEN DATASET FNAME FOR OUTPUT.
OPEN DATASET FNAME FOR INPUT.
IF SY-SUBRC = 0.
WRITE / 'File found'.
ELSE.
WRITE / 'File not found'.
ENDIF.
DELETE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT.
IF SY-SUBRC = 0.
WRITE / 'File found'.
ELSE.
WRITE / 'File not found'.
ENDIF.
The output appears as follows:
File found
File not found
In this example, the file "myfile" is opened for write access as long as it does not already exist. The system finds the file when it is opened for read access. After the DELETE DATASET statement, the system can no longer find the file.