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: 

File exist in application server directory

Former Member
0 Kudos

Hi there,

On my SAP server, i have a directory created specifically to store input files generated from other external systems.

From my ABAP program, i need to check if any file exist on that application server directory. If yes, then i will proceed to read the input file and process it.

If it's empty, then output message that file is not available.

Are there any FM to do this?

2 REPLIES 2

Former Member
0 Kudos

Hi,

Please check this tread.

Thanks,

Kiran

Former Member
0 Kudos

you can use this code to do this...

  • Upload data from file

DATA: lv_filename TYPE string, "File name

lv_line TYPE string. "One line entry in a file

lv_filename = iv_file_name.

IF iv_location = gc_application.

IF iv_record_count IS SUPPLIED.

  • Open file

IF gv_file IS INITIAL.

OPEN DATASET lv_filename FOR INPUT IN TEXT MODE

ENCODING DEFAULT

IGNORING CONVERSION ERRORS.

IF sy-subrc <> 0.

RAISE file_open_error.

ENDIF.

gv_file = gc_check.

ENDIF.

  • Read data

DO iv_record_count TIMES.

READ DATASET lv_filename INTO lv_line.

IF sy-subrc <> 0.

  • Close file

CLOSE DATASET lv_filename.

IF sy-subrc NE 0.

RAISE file_close_error.

ENDIF.

CLEAR gv_file.

  • Exit from the loop

EXIT.

ENDIF.

IF iv_separator IS NOT INITIAL.

CALL FUNCTION 'Z_WM_SPLIT_DATA'

EXPORTING

iv_data = lv_line

iv_separator = iv_separator

CHANGING

ct_tab_data = ct_tab_data.

ELSE.

CHECK NOT lv_line IS INITIAL.

APPEND lv_line TO ct_tab_data .

ENDIF.

ENDDO.

ELSE.

  • Open file

OPEN DATASET lv_filename FOR INPUT IN TEXT MODE

ENCODING DEFAULT

IGNORING CONVERSION ERRORS.

IF sy-subrc <> 0.

RAISE file_open_error.

ENDIF.

  • Read data

DO.

READ DATASET lv_filename INTO lv_line.

IF sy-subrc <> 0.

EXIT.

ENDIF.

IF iv_separator IS NOT INITIAL.

CALL FUNCTION 'Z_WM_SPLIT_DATA'

EXPORTING

iv_data = lv_line

iv_separator = iv_separator

CHANGING

ct_tab_data = ct_tab_data.

ELSE.

CHECK NOT lv_line IS INITIAL.

APPEND lv_line TO ct_tab_data .

ENDIF.

ENDDO.

  • Close file

CLOSE DATASET lv_filename.

IF sy-subrc NE 0.

RAISE file_close_error.

ENDIF.

ENDIF.