‎2007 Dec 21 10:32 AM
hi experts,
i want to upload data from flat file ( notepad) to internal table and from there to database table. for that i have written the following code ,
But the data is not uploaded , instead it gives an error 5 i.e. 'INVALID type' (given in Exceptions of function module GUI_UPLOAD)
the code is as below............
Could anybody modify it ?
REPORT ZSB_GUI_UPLOAD.
TABLES : ZSB_TAB1.
DATA: w_tab TYPE ZSB_TAB1.
DATA: i_tab TYPE STANDARD TABLE OF ZSB_TAB1.
DATA : v_subrc(2),
v_recswritten(6).
PARAMETERS: p_file(80) DEFAULT 'C:\1\UPLOAD.TXT'.
DATA: filename TYPE string,
w_ans(1) TYPE c.
filename = p_file.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Upload Confirmation'
DIAGNOSE_OBJECT = ' '
text_question = 'upload ?'
text_button_1 = 'yes'(001)
ICON_BUTTON_1 = ' '
text_button_2 = 'NO'(002)
ICON_BUTTON_2 = ' '
default_button = '2'
DISPLAY_CANCEL_BUTTON = 'X'
USERDEFINED_F1_HELP = ' '
START_COLUMN = 25
START_ROW = 6
POPUP_TYPE =
IV_QUICKINFO_BUTTON_1 = 'YES'
IV_QUICKINFO_BUTTON_2 = 'NO'
IMPORTING
answer = w_ans
TABLES
PARAMETER =
EXCEPTIONS
TEXT_NOT_FOUND = 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 w_ans = 1.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
FILETYPE = 'dat'
*has_field_separator = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = i_tab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *
IF sy-subrc <> 0.
v_subrc = sy-subrc.
MESSAGE e899(ZMSG) WITH 'File Open Error' v_subrc.
ENDIF.
INSERT ZSB_TAB1 FROM TABLE i_tab.
COMMIT WORK AND WAIT.
MESSAGE i899(ZMSG) WITH sy-dbcnt 'Records Written to ZSB_TAB1'.
‎2007 Dec 21 10:37 AM
Hai,
Use File Type as 'ASC' instead of 'dat'.
This solves your problem.
‎2007 Dec 21 10:45 AM
Hi,
Remove the FILETYPE assignment line and execute.
Since you are uploading from notepad,its type is ASC and GUI_UPLOAD has the default type as ASC,hence you dont need to declare the filetype.
Thanks,
Swaminathan PJ
‎2007 Dec 21 10:58 AM
hi
file type should be ASC instead of dat in your below code
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
FILETYPE = 'dat'
Thanks
Siva kumar
‎2007 Dec 21 2:21 PM
Hi,
i trued ur code just make the small modification.
data: begin of itab occurs 0,
matnr like mara-matnr,
end of itab.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\Book1.TXT'
FILETYPE = 'ASC' "Change DAT to ASC
has_field_separator = 'X' "Uncommented so that if the line is balnk it wont put #
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
SYST FIELDS ARE NOT SET BY THIS FUNCTION SO DISPLAY THE ERROR CODE *
IF sy-subrc = 0.
MESSAGE e899(ZMSG) WITH 'File Open Error' sy-subrc.
ENDIF.
regards,
karthik
‎2007 Dec 21 2:32 PM
last statement sy-subrc, it should ne 0.
IF sy-subrc ne 0.
MESSAGE e899(ZMSG) WITH 'File Open Error' sy-subrc.
ENDIF.
it might be mistake, chekc it now and value of FILETYPE always capitals.
‎2011 Feb 16 1:11 PM