10-07-2008 4:47 AM
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?
10-07-2008 4:56 AM
10-07-2008 6:50 AM
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.