Application Development and Automation 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: 
Read only

Check if files exist using ABAP

Former Member
13,376

Hi All,

I'm currently using FM: FILE_GET_NAME_USING_PATH, and I'd like to do a check to see if the filepath with file (i.e. /com/tmp/file.txt) I am getting back exists or not.

Very simple question, just not sure what to do.

Thanks,

John

1 ACCEPTED SOLUTION
Read only

former_member195698
Active Contributor
5,890

Use OPEN DATASET. The file wil be opened in READ Mode.

If sy-subrc is 0 that means file exists.

Regards,

Aj

Hi All,

I'm currently using FM: FILE_GET_NAME_USING_PATH, and I'd like to do a check to see if the filepath with file (i.e. /com/tmp/file.txt) I am getting back exists or not.

Very simple question, just not sure what to do.

Thanks,

John

9 REPLIES 9
Read only

former_member195698
Active Contributor
5,891

Use OPEN DATASET. The file wil be opened in READ Mode.

If sy-subrc is 0 that means file exists.

Regards,

Aj

Read only

Former Member
0 Likes
5,889

Hi,

You will have to open the file using OPEN DATASET or GUI_UPLOAD. If this fails, it will return sy-subrc 4 which will show that file exists or not.

ashish

Read only

JozsefSzikszai
Active Contributor
0 Likes
5,889

hi John,

try the method DIRECTORY_EXIST of class CL_GUI_FRONTEND_SERVICES.

hope this helps

ec

Read only

0 Likes
5,889

looks like there is an FM as well:

PFL_CHECK_DIRECTORY

ec

Read only

Former Member
0 Likes
5,889

There is a class that provides methods to check, if a file exist or if a certain directory does exist

CALL METHOD cl_gui_frontend_services=>directory_exist

EXPORTING

directory = lv_path

RECEIVING

result = lv_valid

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

OTHERS = 5.

CALL METHOD cl_gui_frontend_services=>file_exist

EXPORTING

file = x_file_with_path

RECEIVING

result = y_file_exists

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

OTHERS = 5.

Hope that helps,

Michael

Read only

Former Member
0 Likes
5,889

Hi,

You can use FM EPS_OPEN_INPUT_FILE.

Regards,

Ferry Lianto

Read only

andreas_mann3
Active Contributor
0 Likes
5,889

use fm's EPS_GET_FILE_ATTRIBUTES

or EPS_GET_DIRECTORY_LISTING

A.

Read only

thokane
Explorer
0 Likes
5,889

Hi,

You may try the following class method

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST

EXPORTING 

          FILE                 = File_Path " e.g.'C:\Temp\file.dat'

RECEIVING

          result               = ret_code. " type i.

Read only

0 Likes
5,889

This message was moderated.