F How to check a file exist or not using cl_gui_frontend_services Class | CodeTheta

How to check a file exist or not using cl_gui_frontend_services Class

February 28, 2024

Code :
REPORT zvp_file_exist.

DATAlv_file TYPE string.
DATAlv_result TYPE string.

lv_file 'C:\Users\CODETHETA\Desktop\demo.txt'.

CALL METHOD cl_gui_frontend_services=>file_exist
  EXPORTING
    file                 lv_file
  RECEIVING
    result               lv_result
  EXCEPTIONS
    cntl_error           1
    error_no_gui         2
    wrong_parameter      3
    not_supported_by_gui 4
    OTHERS               5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

IF lv_result 'X'.
  WRITE'File Exist'.
ELSE.
  WRITE'File Not Exist'.
ENDIF.

IDE Used To Test This Code : ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.

Post a Comment