Tuesday, May 6, 2008

Sample ABAP Program to Delete a file from the application server

REPORT ZDELETE.
*----------------------------------------------------------------------*
* Delete a file on the application server.
*----------------------------------------------------------------------*
PARAMETERS: P_DIR LIKE RLGRAP-FILENAME
DEFAULT '/usr/sap/trans/',
P_FILE1 LIKE RLGRAP-FILENAME.

DATA: P_FILE(128).
DATA: W_ANS.


START-OF-SELECTION.
CONCATENATE P_DIR P_FILE1 INTO P_FILE.
*----------------------------------------------------------------------*
* check file exists
*----------------------------------------------------------------------*
OPEN DATASET P_FILE FOR INPUT.
IF SY-SUBRC NE 0.
MESSAGE E899(BD) WITH P_FILE 'does not exist'.
EXIT.
ELSE.

CALL FUNCTION 'POPUP_CONTINUE_YES_NO'
EXPORTING
DEFAULTOPTION = 'N'
TEXTLINE1 = P_DIR
TEXTLINE2 = P_FILE1
TITEL = 'ARE YOU SURE YOU WANT TO DELETE'
* START_COLUMN = 25
* START_ROW = 6
IMPORTING
ANSWER = W_ANS
EXCEPTIONS
OTHERS = 1.

ENDIF.
CLOSE DATASET P_FILE.
CHECK W_ANS = 'J'.
*----------------------------------------------------------------------*
* delete
*----------------------------------------------------------------------*

DELETE DATASET P_FILE.

IF SY-SUBRC NE 0.
MESSAGE E899(BD) WITH 'Invalid file name' P_FILE.
ELSE.
CLOSE DATASET P_FILE.
MESSAGE I899(BD) WITH P_DIR P_FILE1 'DELETED'.
ENDIF.

No comments:

Blog Archive