‎2006 May 31 7:43 AM
Hi all,
I am using WS_DOWNLOAD to download to local PC.But when any value like 'sdfhbhb' is entered in the file path the system does not prompt any exception from the FM.
Is there any FM to validate the path.
Pls post ur Ideas.
Thanks,
Stock
‎2006 May 31 7:45 AM
Hi stock,
1. use GUI_DOWNLOAD FM
instead of ws_download.
regards,
amit m.
‎2006 May 31 7:47 AM
Hi,
use <b>GUI_DOWNLOAD</b> or <b>CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD</b> method.
regards
vijay
‎2006 May 31 7:56 AM
Hi,
First take the valid file path from the user .
Using this
CONSTANTS :
lc_dft_ext TYPE string VALUE 'XLS',
lc_file_flt TYPE string VALUE '*.xls',
lc_int_drc TYPE string VALUE 'C:\'.
DATA : lv_win_title TYPE string,
lv_file_name TYPE string,
lv_dft_fname TYPE string,
lv_fname TYPE string,
lv_path TYPE string.
CLEAR: lv_fname,
lv_path,
lv_file_name,
lv_win_title,
lv_dft_fname.
--
IF xv_indicator = lc_s.
lv_win_title = text-045.
lv_dft_fname = text-038.
ELSE.
lv_win_title = text-044.
lv_dft_fname = text-033.
ENDIF.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = lv_win_title
default_extension = lc_dft_ext
default_file_name = lv_dft_fname
file_filter = lc_file_flt
initial_directory = lc_int_drc
prompt_on_overwrite = lc_true
CHANGING
filename = lv_fname
path = lv_path
fullpath = lv_file_name
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0 OR lv_fname IS INITIAL
OR lv_path IS INITIAL
OR lv_file_name IS INITIAL.
CLEAR xyv_filepath.
ELSE.
*---FilePath
xyv_filepath = lv_file_name.
ENDIF.
<b>there are many method in this cl_gui_frontend_services realeted to this.
u can use FILE_EXIST method to validate the existence of the file
that is cl_gui_frontend_services=>FILE_EXIST
</b>
Then use download.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_file_name
filetype = lc_file_type
write_field_separator = lc_true
codepage = '4103'
TABLES
data_tab = lit_head_sum
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
I think u can use
Mark Helpfull answers
Regards
Manoj
‎2006 May 31 8:07 AM
Hai Stock
using GUI_DOWNLOAD instead of WS_DOWNLOAD F.M
Before Download your internal Table into PC Flat file
the filename must exist in your given path
otherwise create on flie in the PC then do the bellow code
Check the following Code
data : v_ecc6_filename type string.
data : begin of it_mara occurs 0,
matnr like mara-matnr,
mbrsh like mara-mbrsh,
mtart like mara-mtart,
meins like mara-meins,
end of it_mara.
select
matnr
mbrsh
mtart
meins
from mara
into table it_mara
where mtart = 'ROH'.
v_ecc6_filename = 'C:\Down_Load.txt'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\new.txt'
FILETYPE = 'ASC'
TABLES
DATA_TAB = it_mara
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
if sy-subrc <> 0.
endif.
Thanks & reagrds
Sreenivasulu P
‎2006 May 31 8:12 AM
Hi,
I tried with GUI_DOWNLOAD,but it short dumps on invalid file name as 'jfdbvjb' .Also I do not want to hardcode any directory(eg. C:\) or filename(eg.Download) or file extension(eg. .xls,.dat) in the program.
Pls post ur ideas.
Thanks ,
Stock
‎2006 May 31 8:13 AM
‎2006 May 31 8:19 AM
Hi again,
1. Also I do not want to hardcode any directory(eg. C:\) or filename(eg.Download) or file extension(eg. .xls,.dat) in the program.
For this, just copy paste this program.
2. It will give selection
for selecting the filename
and download to that file.
3.
REPORT abc.
DATA : file_name TYPE string.
data : t001 like table of t001 with header line.
*----
SELECTION SCREEN
*----
PARAMETERS : p_file LIKE rlgrap-filename
OBLIGATORY.
*----
AT SELECTION SCREEN
*----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CLEAR p_file.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_file.
*----
START OF SELECTION
*----
START-OF-SELECTION.
select * from t001 into table t001.
file_name = p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = file_name
TABLES
DATA_TAB = t001
.
regards,
amit m.
‎2006 May 31 8:30 AM
Hi,
The code :
PARAMETERS: p_local LIKE rlgrap-filename DEFAULT
'J:\prod\sales\event\', "Upload File
p_pc_dwn LIKE rlgrap-filename DEFAULT
'J:\prod\sales\archive\'. "Download to Local File
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_local.
CLEAR p_local.
PERFORM f_search_path.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pc_dwn.
CLEAR p_pc_dwn.
PERFORM f_search_path_dwn.
START-OF-SELECTION.
perform f_data_into_itab.
PERFORM f_chk_upload_file.
form f_data_into_itab.
*logic to put data into internal table i_upload.
endform.
FORM f_chk_upload_file.
DATA : l_lcl_path LIKE rlgrap-filename.
IF NOT p_local IS INITIAL.
REFRESH i_upload.
CLEAR i_upload.
CLEAR v_local_file.
MOVE p_local TO v_local_file.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = 'IBM'
filename = v_local_file
filetype = 'DAT'
TABLES
data_tab = i_upload
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
WRITE : p_pc_dwn TO l_lcl_path.
*CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
CODEPAGE = 'IBM'
FILENAME = l_lcl_path
FILETYPE = 'ASC'
TABLES
data_tab = i_upload
FIELDNAMES =
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
OTHERS = 10
.
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = l_lcl_path
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
IMPORTING
FILELENGTH =
tables
data_tab = i_upload
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDFORM. " f_chk_upload_file
FORM f_search_path_dwn.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_pc_dwn.
ENDFORM. " f_search_path_dwn
I have used search help,inspite of that I require to add validation to it.
thanks,
stock
‎2006 May 31 8:35 AM
Hi, here is an example on how to use GUI_DONLOAD and also FILE_SAVE_DIALOG:
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: so_tplnr FOR iloa-tplnr OBLIGATORY,
so_stand FOR t499s-stand,
so_anln1 FOR anlc-anln1.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
PARAMETERS: p_posdep RADIOBUTTON GROUP rb1,
p_pladep RADIOBUTTON GROUP rb1.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b3.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
CHANGING
filename = file_name
path = file_path
fullpath = full_path
user_action = act
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF act = 0.
var1 = full_path.
p_file = var1.
ENDIF.
END-OF-SELECTION.
PERFORM download_to_pc.
FORM download_to_pc.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = var1
filetype = 'ASC'
write_field_separator = 'X'
CHANGING
data_tab = it_download[]
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.