11-28-2007 3:22 PM
Hi All,
Please give me the code to upload data from front end to internal table only using GUI_UPLOAD.
Thanks,
Kumar
11-28-2007 3:26 PM
DATA : filename TYPE string.
filename = 'c:/folder/file.xls'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
filetype = 'ASC'
TABLES
data_tab = itab "internal
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.
IF sy-subrc <> 0.
MESSAGE 'Error While Opening The File' TYPE 'I'.
ENDIF.
Lokesh
11-28-2007 4:30 PM
Hi Kumar,
Are u want to upload exel sheet , GUI_UPLOAD doe's not upload exel sheet
use this function module to uload exel sheet , this function module can upload exel sheet ASLM_EXCEL_TO_INTERNAL_TABLE in this function module there is 5 imort parameters and 1 table parameter.
Give values like this,
file name -- enter your file name.
brow -- Enter bigining row for example if you want to upload from first row itself give it 1.
bcol -- Enter begining col for example if you want to upload from first col
like this fill ecol, erow.
Plz Reward your Reward points will helps me a lot,
Mahi.
11-28-2007 4:40 PM
Check this program , reward points if helpful
*
&----
*
*& Report ZEXCEL_UPLOAD *
*& *
&----
*& *
*& *
&----
report ZEXCEL_UPLOAD message-id ZMSG.
tables :T001.
data : begin of ITAB occurs 0,
BUKRS like T001-BUKRS,
BUTXT like T001-BUTXT,
ORT01 like T001-ORT01,
LAND1 like T001-LAND1,
WAERS like T001-WAERS,
end of ITAB.
data : WA_T001_EXCEL like ITAB.
data : IT_T001_EXCEL like standard table of WA_T001_EXCEL.
data IT_TEXT like ITAB occurs 0 with header line.
data : IT_RETURN like standard table of ALSMEX_TABLINE,
WA_RETURN like ALSMEX_TABLINE,
WA_RETURNS like ALSMEX_TABLINE.
data : V_FILE type STRING,V_MASK(10) type C.
selection-screen begin of block B1 with frame title TEXT-001.
parameters P_FILE like RLGRAP-FILENAME .
selection-screen end of block B1.
selection-screen begin of block B2 with frame title TEXT-002.
parameter : R_TXT radiobutton group G1 default 'X' user-command C1,
R_EXCEL radiobutton group G1.
selection-screen end of block B2.
at selection-screen on value-request for P_FILE.
if R_TXT = 'X'.
V_MASK = '*TXT'.
elseif R_EXCEL = 'X'.
V_MASK = '*XLS'.
endif.
call function 'KD_GET_FILENAME_ON_F4'
exporting
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
MASK = V_MASK
changing
FILE_NAME = P_FILE.
at selection-screen.
translate P_FILE to upper case.
if R_TXT = 'X'.
search P_FILE for '*TXT'.
if SY-SUBRC <> 0.
message E011.
endif.
endif.
if R_EXCEL = 'X'.
search P_FILE for '*XLS'.
if SY-SUBRC <> 0.
message E012.
endif.
endif.
start-of-selection.
V_FILE = P_FILE.
if R_TXT = 'X'.
call function 'GUI_UPLOAD'
exporting
FILENAME = V_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
tables
DATA_TAB = IT_TEXT.
if SY-SUBRC eq 0.
message I013 with V_FILE.
loop at IT_TEXT .
write 😕 IT_TEXT-BUKRS color 4, IT_TEXT-BUTXT color 3,IT_TEXT-ORT01
color 5,
IT_TEXT-LAND1 color 2,IT_TEXT-WAERS color 1.
endloop.
endif.
elseif R_EXCEL = 'X'.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
FILENAME = P_FILE
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 4
I_END_ROW = 2
tables
INTERN = IT_RETURN.
if SY-SUBRC eq 0.
message I014 with P_FILE.
sort IT_RETURN by ROW COL.
loop at IT_RETURN into WA_RETURNS.
WA_RETURN = WA_RETURNS.
case WA_RETURN-COL.
when 1.
WA_T001_EXCEL-BUKRS = WA_RETURN-VALUE.
when 2.
WA_T001_EXCEL-BUTXT = WA_RETURN-VALUE.
when 3.
WA_T001_EXCEL-ORT01 = WA_RETURN-VALUE.
when 4.
WA_T001_EXCEL-LAND1 = WA_RETURN-VALUE.
endcase.
at end of ROW.
append WA_T001_EXCEL to IT_T001_EXCEL.
clear : WA_RETURN, WA_T001_EXCEL.
endat.
endloop.
endif.
loop at IT_T001_EXCEL into WA_T001_EXCEL.
write 😕 WA_T001_EXCEL-BUKRS color 1, WA_T001_EXCEL-BUTXT color 2,
WA_T001_EXCEL-ORT01 color 3,WA_T001_EXCEL-LAND1 color 4.
endloop.
endif.
11-28-2007 7:07 PM
hi,
i am using GUI_UPLOAD for uploading data from front end to internal table and here below is the code.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = I_TEMP_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT_master
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.
IF SY-SUBRC = 0.
ENDIF.
And here the SUBRC value i am getting is 13 why i am getting this..? and in my system i cannot use other function modules other then GUI_UPLOAD.
Please help me out in solving this.
Thanks,
Kumar
11-29-2007 3:26 AM
Hi Kumar,
You do not have the necessary authorization to access the file from the current folder.
Could you please move the file to some other folder or drive & check.
What is the path you have given in l_temp_file ?
Best regards,
Prashant
11-29-2007 6:08 AM
Hi
ABAP code for uploading an Excel document into an internal table. See code below for structures. The
code is based on uploading a simple Excel spreadsheet or for an actual Excel file click here.
There are also a couple of alternatives which use fucntion modules 'KCD_EXCEL_OLE_TO_INT_CONVERT'
and 'ALSM_EXCEL_TO_INTERNAL_TABLE' but the method below is by far the simplest method to used.
A big thanks to Jayanta for bringing this method to my attention.
*..............................................................
*: Description :
*: ----------- :
*: This is a simple example program to get data from an excel :
*: file and store it in an internal table. :
*: :
*: :
*: SAP Version : 4.7 :
*:............................................................:
REPORT zupload_excel_to_itab.
TYPE-POOLS: truxs.
PARAMETERS: p_file TYPE rlgrap-filename.
TYPES: BEGIN OF t_datatab,
col1(30) TYPE c,
col2(30) TYPE c,
col3(30) TYPE c,
END OF t_datatab.
DATA: it_datatab type standard table of t_datatab,
wa_datatab type t_datatab.
DATA: it_raw TYPE truxs_t_text_data.
* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_raw " WORK TABLE
i_filename = p_file
TABLES
i_tab_converted_data = it_datatab[] "ACTUAL DATA
EXCEPTIONS
conversion_failed = 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.
***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
LOOP AT it_datatab INTO wa_datatab.
WRITE:/ wa_datatab-col1,
wa_datatab-col2,
wa_datatab-col3.
ENDLOOP.
<b>Reward if usefull</b>