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 exist local file

Former Member
0 Likes
1,386

Ho to everybody

I would ask you if exist a function to check if it is available a file in local pc.

I tried with this script but it doen't work

v_path = 'c:\Windowsss\notepad.exe'.

DATA msg_text(50).

OPEN DATASET v_path FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE MESSAGE msg_text.

IF sy-subrc NE 0.

WRITE: 'File cannot be opened for reason : ', msg_text.

EXIT.

ELSE.

CLOSE DATASET v_path.

ENDIF.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,223

Use class CL_GUI_FRONTEND_SERVICES and the method FILE_EXIST

CLASS cl_gui_frontend_services DEFINITION LOAD.
PARAMETERS: p_file TYPE char80.

DATA: l_string TYPE string,
      l_result.

l_string = p_file.
l_result = cl_gui_frontend_services=>file_exist( l_string ).

WRITE l_result.

Edited by: Ramiro Escamilla on Nov 12, 2009 8:12 AM

Add example

5 REPLIES 5
Read only

Former Member
0 Likes
1,224

Use class CL_GUI_FRONTEND_SERVICES and the method FILE_EXIST

CLASS cl_gui_frontend_services DEFINITION LOAD.
PARAMETERS: p_file TYPE char80.

DATA: l_string TYPE string,
      l_result.

l_string = p_file.
l_result = cl_gui_frontend_services=>file_exist( l_string ).

WRITE l_result.

Edited by: Ramiro Escamilla on Nov 12, 2009 8:12 AM

Add example

Read only

0 Likes
1,223

thanks a lot Escamilla good replay

Read only

0 Likes
1,223

Hi,

OPEN DATASET is used for applicatio server file read. For reading files on presentation server, use method FILE_EXISTS of class CL_GUI_FRONTEND_SERVICES.

Regards,

Nilesh.

Read only

Former Member
0 Likes
1,223

Hi Giorgio,

Please make use of method FILE_EXIST of class CL_GUI_FRONTEND_SERVICES. A small code snippet for your reference.

FORM validate_pre_file USING fp_name TYPE rlgrap-filename.

DATA : l_result,

l_filename TYPE string.

l_filename = fp_name.

CLEAR l_result.

CALL METHOD cl_gui_frontend_services=>file_exist

EXPORTING

file = l_filename

RECEIVING

result = l_result

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE s007 DISPLAY LIKE c_e.

LEAVE LIST-PROCESSING.

ELSEIF l_result IS INITIAL.

MESSAGE s008 DISPLAY LIKE c_e.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " validate_pre_file_hdr

Please set it to resolved if it helps you.

Regards

Abhii...

Read only

Former Member
0 Likes
1,223

Hi ,

Use the method CALL METHOD cl_gui_frontend_services=>file_open_dialog .

Thank you,

Gangadhar.S