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

validate whether a file path or directory exists on application server

Former Member
0 Likes
5,966

hi,

I need to validate if a directory or file path exist on application server. How do we do that?

thanks.

Use this fm.

FILE_GET_NAME

If sy-subrc NE 0.

Message 'File not found' type 'E'.

Endif.

9 REPLIES 9
Read only

Former Member
0 Likes
2,660

Hi,

OPEN DATASET P_FILENAME for INPUT in TEXT MODE .
If SY-SUBRC EQ 0. 
 * File Exists
ELSE.
* File does not exit.
ENDIF.
or 

Check this Fm 'RZL_READ_DIR' 
                    'RZL_READ_FILE'

Read only

GauthamV
Active Contributor
0 Likes
2,660

Use this fm.

FILE_GET_NAME

If sy-subrc NE 0.

Message 'File not found' type 'E'.

Endif.

Read only

Former Member
0 Likes
2,660

DATA:

ltp_bom TYPE sychar01,

ltp_encoding TYPE sychar01,

ltp_codepage TYPE cpcodepage.

  • Processing --------------------------------------------------------- *

TRY.

CALL METHOD cl_abap_file_utilities=>check_utf8

EXPORTING

file_name = itp_filename

max_kb = -1

all_if_7bit_ascii = abap_true

IMPORTING

bom = ltp_bom

encoding = ltp_encoding.

CATCH cx_sy_file_open .

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

RAISING file_open_error.

CATCH cx_sy_file_authority .

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

RAISING file_authority_error.

CATCH cx_sy_file_io .

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

RAISING file_io_error.

ENDTRY.

Read only

Former Member
0 Likes
2,660

priyanka,

You can put the open data set in try --- catch block and validate.

TRY.

OPEN DATASET P_FILENAME for INPUT in TEXT MODE .

CATCH cx_sy-file_open*

perform error_message.

ENDTRY

Read only

Former Member
0 Likes
2,660

Hi ,

use the fm.

FILE_GET_NAME.

Regards

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
2,660

Hi,

Refer:

Hope this helps you.

Regards,

Tarun

Read only

Former Member
0 Likes
2,660

Hi ,

You can try using these two Function Modules:

To have an f4 help on the application server file

:F4_DXFILENAME_TOPRECURSION

And to validate the path use:

FILE_GET_NAME_USING_PATH

Hope it helps

Regards

Mansi

Read only

Subhankar
Active Contributor
0 Likes
2,660

Hi

Use the FM RZL_READ_DIR to get the file details of a directory.

Then you can check your file is exist or not.

Read only

Former Member
0 Likes
2,660

Hi,

You can use this FM:

CALL FUNCTION 'EPS_GET_FILE_ATTRIBUTES'

EXPORTING

file_name =

dir_name =

EXCEPTIONS

OTHERS = 3.

IF sy-subrc NE 0.

c_error = 'X'.

ENDIF.