‎2010 Aug 16 11:50 AM
Hi all,
My requirement is to upload flat file from presentation server, if in case if end user changes xyz.pdf to xyz.txt,
i have to check the file type, if it is a text file, then i have to do further processing.
Thanks in advance.
‎2010 Aug 16 11:54 AM
In the method: CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG pass '*.txt' to FILE_FILTER.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select Source File'
default_filename = '*.txt'
multiselection = ' '
file_filter = '*.txt'
CHANGING
file_table = l_itab
rc = l_subrc.Edited by: Suhas Saha on Aug 16, 2010 4:38 PM
‎2010 Aug 16 12:57 PM
Hi,
The end user can rename the pdf file as text file @ presentation server and if this file is uploaded using fm gui_upload, system gives to dump..
‎2010 Aug 16 12:57 PM
Hi,
The end user can rename the pdf file as text file @ presentation server and if this file is uploaded using fm gui_upload, system gives dump..
‎2010 Aug 16 1:16 PM
Check this:
PARAMETERS: p_file TYPE string.
AT SELECTION-SCREEN.
DATA: l_file TYPE pc_path,
l_extn TYPE char3.
IF sy-ucomm = 'ONLI'. "Execute Button(F8)
l_file = p_file. "Assign seln-scr param
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = l_file
IMPORTING
extension = l_extn
EXCEPTIONS
invalid_drive = 1
invalid_extension = 2
invalid_name = 3
invalid_path = 4
OTHERS = 5.
IF sy-subrc = 0.
IF l_extn NE 'TXT'.
MESSAGE 'Please use .TXT file only' TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.BR,
Suhas
‎2010 Aug 16 1:34 PM
Hi Suhas,
I dont think the problem is with the matter of extension, if so your earlier solution will work fine.
The end user can rename the pdf file as text file @ presentation server and if this file is uploaded using fm gui_upload, system gives to dump..
Does that do anything with the content ?
‎2010 Aug 16 2:09 PM
Hello Keshav,
OP's requirement:
i have to check the file type, if it is a text file, then i have to do further processing.
In the earlier post, we can restrict the user to select .TXT files only. But he can jolly well change the extension to .DOC, .XLS, .PDF in the selection-screen.
The OP wants to check that while executing the report only .TXT file needs to be processed.
BR,
Suhas
‎2010 Aug 16 2:33 PM
Stupid me ... i was thinking that the user will change the extension at system level and then upload
‎2010 Aug 16 1:02 PM
Hi Vemkatesh,
try this way.
PARAMETERS : p_infile TYPE rlgrap-filename. "Input
AT SELECTION-SCREEN.
IF p_pcfile CP '*.xls'.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' "Excel file upload Function module
ELSEIF p_pcfile CP '*.csv' OR p_pcfile CP '*.txt'.
CALL FUNCTION 'GUI_UPLOAD'. "* Text File and CSV file Open Upload Function Module
ENDIF.
Prabhudas
‎2010 Aug 16 1:07 PM
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = pa_fich
filetype = 'ASC'
TABLES
data_tab = ti
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
YES_batch = 4
unkYESwn_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
DATA: lfs_file TYPE file_table,
l_fname_tab LIKE table of lfs_file,
l_rc TYPE i,
l_p_def_file TYPE string,
l_p_file TYPE string,
l_user_act TYPE i.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
DEFAULT_FILENAME = l_p_def_file
CHANGING
FILE_TABLE = l_fname_tab
RC = l_rc
USER_ACTION = l_user_act
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_YES_GUI = 3
YEST_SUPPORTED_BY_GUI = 4
others = 5 .
IF sy-subrc = 0
AND l_user_act <> CL_GUI_FRONTEND_SERVICES=>ACTION_CANCEL.
LOOP AT l_fname_tab INTO lfs_file.
l_p_file = lfs_file.
EXIT.
ENDLOOP.
Elseif l_user_act EQ cl_gui_frontend_services=>action_cancel.
l_p_file = l_p_def_file.
ENDIF.
l_p_def_file = pa_fich.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = l_p_file
FILETYPE = 'ASC'
TABLES
DATA_TAB = ti
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
YES_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
YES_AUTHORITY = 6
UNKYESWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_YEST_ALLOWED = 9
SEPARATOR_YEST_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKYESWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17.
I think it will helps u when the user dynamically entered file type pass that variable to file type.just try it.
‎2010 Aug 16 1:04 PM
Do 2 gui uploads, one for the pdf file and one for the txt file.
Fit each one of these between TRY, and, 'ENDTRY'.... then you shouldn't get dump and one of the uploads will work?
‎2010 Aug 16 1:52 PM
Hi,
try this FM GUI_GET_FILE_INFO inorder to get tthe attributes of a file..
I hope this answer will help you.
Regards,
Kiran
‎2010 Aug 25 12:05 PM
Hi,
Anyone provide solution to this issue, or any other way to solve this issue...
Thanks.
‎2010 Aug 25 12:49 PM
Hi,
Upload the files in Binary mode. Filetype = BIN. Read first line of data tab and try to identify if it is pdf.
Kind Regards
Michael