Application Development 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: 

BAPI to delete an excel file on local pc from R/3

Former Member
0 Kudos

In our requirement, we have an excel file in Local pc(in network). We want to delete this excel file from R/3 .

Is their any RFC/BAPI for deleting this excel file.Could you suggest any?

1 ACCEPTED SOLUTION

valter_oliveira
Active Contributor
0 Kudos

Check class cl_gui_frontend_services, methods DIRECTORY_LIST_FILES and FILE_DELETE.

Regards,

Valter Oliveira

5 REPLIES 5

valter_oliveira
Active Contributor
0 Kudos

Check class cl_gui_frontend_services, methods DIRECTORY_LIST_FILES and FILE_DELETE.

Regards,

Valter Oliveira

0 Kudos

Thanks, can you suggest any function module/BAPI which can retrieve this deleted excel file again on the same path.

0 Kudos

For that I would create a "backput directory" and use method FILE_COPY of the same class. Before delete, copy the files to this directory. To undo delete, copy from this directory to the starting place.

Regards,

Valter Oliveira.

0 Kudos

Could you please advice some RFCs/BAPI name in place of classes and their methods.... It would be more helpful to us.

0 Kudos

I could suggest you FM GUI_DELETE_FILE that probably do the same.

But please don't be "afraid" of method. They are faster than function modules. Check this example.


CLASS cl_gui_frontend_services DEFINITION LOAD.
DATA: data_tab TYPE STANDARD TABLE OF file_info.
DATA: wa TYPE file_info.
DATA: w_count TYPE i.

CALL METHOD cl_gui_frontend_services=>directory_list_files
  EXPORTING
    directory        = p_dirin
    files_only       = 'X'
    directories_only = space
  CHANGING
    file_table       = data_tab
    count            = w_count.
IF sy-subrc NE 0.
  EXIT.
ENDIF.

LOOP AT data_tab INTO wa.

  CONCATENATE p_dirin wa-filename INTO w_filename.
  CONCATENATE p_dirout wa-filename INTO w_copyout.
      
  CALL METHOD cl_gui_frontend_services=>file_copy
    EXPORTING
      SOURCE               = w_filename
      DESTINATION          = w_copyout
      overwrite            = 'X'
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      wrong_parameter      = 3
      disk_full            = 4
      access_denied        = 5
      file_not_found       = 6
      destination_exists   = 7
      unknown_error        = 8
      path_not_found       = 9
      disk_write_protect   = 10
      drive_not_ready      = 11
      not_supported_by_gui = 12
      OTHERS               = 13.
  CHECK sy-subrc EQ 0.

  CALL METHOD cl_gui_frontend_services=>file_delete
    EXPORTING
      filename = w_filename
    CHANGING
      rc       = w_rc.
ENDLOOP.

Regards,

Valter Oliveira.