04-07-2009 4:18 AM
Hi,
I have a requirement where in i need to check if the filepath entered by the user is valid, the filepath is where the internal table that i created in will be downloaded using GUI_DOWNLOAD.
I want to know if the directory exist: like C: or E:
and the file is in excel format.. .xls
Thanks
Edited by: Alvin Rosales on Apr 7, 2009 5:18 AM
04-07-2009 4:40 AM
Hi Alvin,
For checking whether the file path is valid, you can use the code as below:
call method cl_gui_frontend_services=>directory_exist
exporting
directory = im_dirname
receiving
result = x_directory
exceptions
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
others = 4.
case sy-subrc.
when 1.
" your exception handling here
when 2.
.....
endcase.
For checking the file format entered by the user, you can force the user to enter 'xls' after the dot (.) in the filename parameter itself on event AT SELECTION-SCREEN...
After you've validated the above you can use code below to download internal table data to the specified directory:
call method cl_gui_frontend_services=>gui_download
exporting bin_filesize = p_bin_filesize
filename = l_fullpath
filetype = p_filetype
write_lf = p_write_lf
trunc_trailing_blanks = p_trunc_blanks
trunc_trailing_blanks_eol = p_trunc_blanks_eol
append = p_append
codepage = p_codepage
importing filelength = p_filelength
changing data_tab = <l_data_tab>
exceptions file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
unknown_error = 5
others = 6.
Hope this helps,
Cheers,
Sougata.
04-07-2009 4:26 AM
Hi,
You can do validations using
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
CALL METHOD cl_gui_frontend_services=>directory_exist
CALL METHOD cl_gui_frontend_services=>file_exist
Regards,
jaya
04-07-2009 4:40 AM
Hi Jayapradha,
I use the FM and splitted the directory and the file name.. how can i use the call methods? Thanks
04-07-2009 4:33 AM
Hi Alvin,
Try to use the FM FILE_GET_NAME_USING_PATH and do manipulations with the help of sy-subrc value given by it
04-07-2009 4:40 AM
Hi Alvin,
For checking whether the file path is valid, you can use the code as below:
call method cl_gui_frontend_services=>directory_exist
exporting
directory = im_dirname
receiving
result = x_directory
exceptions
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
others = 4.
case sy-subrc.
when 1.
" your exception handling here
when 2.
.....
endcase.
For checking the file format entered by the user, you can force the user to enter 'xls' after the dot (.) in the filename parameter itself on event AT SELECTION-SCREEN...
After you've validated the above you can use code below to download internal table data to the specified directory:
call method cl_gui_frontend_services=>gui_download
exporting bin_filesize = p_bin_filesize
filename = l_fullpath
filetype = p_filetype
write_lf = p_write_lf
trunc_trailing_blanks = p_trunc_blanks
trunc_trailing_blanks_eol = p_trunc_blanks_eol
append = p_append
codepage = p_codepage
importing filelength = p_filelength
changing data_tab = <l_data_tab>
exceptions file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
unknown_error = 5
others = 6.
Hope this helps,
Cheers,
Sougata.
04-07-2009 5:01 AM
Hi Sougata,
Thanks for the reply just additional question in using the
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = g_path -
> will this be the filepath directory (example: C:\ )
RECEIVING
result = x_directory -
> what type of data will this be?
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
OTHERS = 4.
sorry for the followup question
04-07-2009 5:08 AM
Hi,
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = g_path -
> will this be the filepath directory (example: C:\ )
RECEIVING
result = x_directory -
> It is of type c (Contains 'X' or ' ').
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
OTHERS = 4.
Based on the value of x_directory, u can write code as below.
Ex:
if x_directory = 'X'.
write:/ 'Directory exists'.
else.
write:/ 'Directory not exists'.
endif.
06-06-2009 7:41 AM
From above code I am not getting How will you validate the FILE TYPE ?
04-07-2009 4:48 AM
Hi
You can simply use this FM.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
mask = '*.XLS'
CHANGING
file_name = pa_fname
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
Here Pa_fname is the parameter field on the selection screen where f4 help will be provided and this fm will be called and you can select the path where you want to store.
Regards
Nitin.
04-07-2009 4:56 AM
>
> Hi
>
> You can simply use this FM.
>
> CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
> EXPORTING
> static = 'X'
> mask = '*.XLS'
> CHANGING
> file_name = pa_fname
> EXCEPTIONS
> mask_too_long = 1
> OTHERS = 2.
>
>
> Here Pa_fname is the parameter field on the selection screen where f4 help will be provided and this fm will be called and you can select the path where you want to store.
>
> Regards
> Nitin.
But the person who will be running the program is also able to type whatever he feels like into the parameter and run the program! How do you know that he will click on the possible entries button (F4) and then choose the filename? Who is going to look over his shoulder and check??
04-07-2009 5:04 AM
hi,
User can enter anything on the selection screen and it will accept that, but f4 help is given so as to make the selection of the path easy and user friendly and to store the file in .xls format by default which was the doubt.
Thanks,
Nitin.