Friday, October 18, 2013

SAP ABAP how to delete a file from the frontend

+
Hi Folks,
here an easy one: delete a file from the front end  (typically the PC of the user using the sapgui).
The function that does this is: GUI_DELETE_FILE

Enjoy it!

REPORT ZDEL

parameters: p_file type rlgrap-filename .
at selection-screen on value-request for p_file .

  CALL FUNCTION 'F4_FILENAME'
  EXPORTING
   PROGRAM_NAME = SYST-CPROG
   DYNPRO_NUMBER = SYST-DYNNR
   FIELD_NAME = 'P_FILE'
  IMPORTING
   FILE_NAME = p_file
.
start-of-selection .

  CALL FUNCTION 'GUI_DELETE_FILE'
   EXPORTING
   FILE_NAME = p_file
  EXCEPTIONS
   FAILED = 1
   OTHERS = 2
.
IF SY-SUBRC <> 0.
  write:/ 'file:' , p_file , ' not removed'.
ENDIF.

write:/ 'file:' , p_file , 'removed'.