2009 Mar 14 8:36 PM
Can anyone tell me the FM name to validate the a file/folder path? (C:\check\123.txt) in ABAP?
Regards,
Prathap
Edited by: Prathap on Mar 15, 2009 2:06 AM
2009 Mar 16 3:33 AM
Hi,
Use this code to validate the file path and then upload:-
PARAMETERS : p_file TYPE rlgrap-filename DEFAULT 'C:\TEST.XLS'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_file_process USING p_file. "get F4 help for file
AT SELECTION-SCREEN.
PERFORM validate_file_path USING p_file. "validate file path
START-OF-SELECTION.
PERFORM upload_data. "code to upload your data into internal table
*&---------------------------------------------------------------------*
*& Form F4_FILE_PROCESS
*&---------------------------------------------------------------------*
* -->P_FILE_PATH text
*----------------------------------------------------------------------*
FORM f4_file_process USING p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
IF sy-subrc NE 0.
MESSAGE e000(zsd).
ENDIF.
ENDFORM. " F4_FILE_PROCESS
*&---------------------------------------------------------------------*
*& Form VALIDATE_FILE_PATH
*&---------------------------------------------------------------------*
* -->P_FILE text
*----------------------------------------------------------------------*
FORM validate_file_path USING p_file.
DATA : lv_dir TYPE string,
lv_file TYPE string,
lv_result(1) TYPE c.
DATA : lv_filename TYPE string.
lv_filename = p_file.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = p_file
IMPORTING
stripped_name = lv_file "file name
file_path = lv_dir "directory path
EXCEPTIONS
x_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
" check existence of directory
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = lv_dir
RECEIVING
result = lv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF lv_result IS INITIAL. "lv_result is X if valid directory
MESSAGE 'Invalid Directory' TYPE 'E'.
ENDIF.
CLEAR lv_result.
" check file existence
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = lv_filename
RECEIVING
result = lv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF lv_result IS INITIAL. "lv_result is X if valid file path
MESSAGE 'Invalid File' TYPE 'E'.
ENDIF.
ENDFORM. " VALIDATE_FILE_PATH
Hope this helps you.
Regards,
Tarun
2009 Mar 14 9:10 PM
Hi,
use the method
file_exist from the class cl_gui_frontend_services...
this will return you wether you have the file on the specified path or not...
Regards,
Siddarth
2009 Mar 14 10:54 PM
I think the requirement is if the file exists in the location u specified on the selection screen:
If that is the case:
open dataset ( get right syntax (F1)
if sy-subrc = 0.
close dataset
else
write:/ 'check file'.
2009 Mar 15 12:07 AM
check these,
u can use one of these
DX_FILE_EXISTENCE_CHECK
CV120_DOC_FILE_EXISTENCE_CHECK
CV122_DOC_FILE_EXISTENCE_CHECK
кu03B1ятu03B9к
2009 Mar 15 6:17 AM
Hi,
You can use method CL_GUI_FRONTEND_SERVICES=>FILE_EXIST
Or you can also refer FM's:
CONV_UTIL_CHECK_FILE_EXISTENCE
CV120_DOC_FILE_EXISTENCE_CHECK
CV122_DOC_FILE_EXISTENCE_CHECK
DX_FILE_EXISTENCE_CHECK
PFL_CHECK_OS_FILE_EXISTENCE
Or when you simply upload a file using any FM, just check sy-subrc. If not equal to 0, then display message Invalid Directory or File Name.
Hope this helps you.
Regards,
Tarun
2009 Mar 15 7:23 AM
hi prathap , the sample code for validating the presentation and application server files.
&---------------------------------------------------------------------*
*& Form validate_server_file
*&---------------------------------------------------------------------*
FORM validate_server_file.
DATA: l_file TYPE tpfht-pffile.
CLEAR l_file.
l_file = p_file.
CALL FUNCTION 'PFL_CHECK_OS_FILE_EXISTENCE'
EXPORTING
fully_qualified_filename = l_file
IMPORTING
file_exists = l_true.
IF l_true = space.
flag1 = 'X'.
STOP.
ENDIF.
ENDFORM. " validate_server_file
*&---------------------------------------------------------------------*
*& Form validate_presentation_server
*&---------------------------------------------------------------------*
FORM validate_presentation_server .
DATA: result,
xfile TYPE string.
xfile = p_file.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = xfile
RECEIVING
result = result.
IF result NE 'X'.
flag1 = 'X'.
STOP.
ENDIF.
ENDFORM. "validate_presentation_serverthanks ,
chinnaiya
2009 Mar 15 7:40 AM
Ignore this message
Edited by: kartik tarla on Mar 15, 2009 1:11 PM
2009 Mar 16 3:33 AM
Hi,
Use this code to validate the file path and then upload:-
PARAMETERS : p_file TYPE rlgrap-filename DEFAULT 'C:\TEST.XLS'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_file_process USING p_file. "get F4 help for file
AT SELECTION-SCREEN.
PERFORM validate_file_path USING p_file. "validate file path
START-OF-SELECTION.
PERFORM upload_data. "code to upload your data into internal table
*&---------------------------------------------------------------------*
*& Form F4_FILE_PROCESS
*&---------------------------------------------------------------------*
* -->P_FILE_PATH text
*----------------------------------------------------------------------*
FORM f4_file_process USING p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
IF sy-subrc NE 0.
MESSAGE e000(zsd).
ENDIF.
ENDFORM. " F4_FILE_PROCESS
*&---------------------------------------------------------------------*
*& Form VALIDATE_FILE_PATH
*&---------------------------------------------------------------------*
* -->P_FILE text
*----------------------------------------------------------------------*
FORM validate_file_path USING p_file.
DATA : lv_dir TYPE string,
lv_file TYPE string,
lv_result(1) TYPE c.
DATA : lv_filename TYPE string.
lv_filename = p_file.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = p_file
IMPORTING
stripped_name = lv_file "file name
file_path = lv_dir "directory path
EXCEPTIONS
x_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
" check existence of directory
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = lv_dir
RECEIVING
result = lv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF lv_result IS INITIAL. "lv_result is X if valid directory
MESSAGE 'Invalid Directory' TYPE 'E'.
ENDIF.
CLEAR lv_result.
" check file existence
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = lv_filename
RECEIVING
result = lv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF lv_result IS INITIAL. "lv_result is X if valid file path
MESSAGE 'Invalid File' TYPE 'E'.
ENDIF.
ENDFORM. " VALIDATE_FILE_PATH
Hope this helps you.
Regards,
Tarun
2009 Mar 16 3:49 AM
Hi,
One of the methods is,
data: w_result type abap_bool.
call method cl_gui_frontend_services=>file_exist
exporting
file = p_file "File name
receiving
result = w_result "Result
exceptions
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
others = 4.
if w_result eq 'X'.
"File exists
else.
"File not exists
endif.Regards,
Mannoj Kumar P