‎2007 Feb 23 4:49 PM
Hi All,
I have flat file in Excel format (***.xls) . Now i need to read .xls file into my internal table. so which procedure is best one. is it GUI_UPLOAD function with ASC format or any other best procedure for better efficiency. Plz help me out on this regard...
Thanking you...
‎2007 Feb 23 4:50 PM
Hi,
You can use the FM GUI_UPLOAD by passing the parameter HAS_FIELD_SEPARATOR = 'X'
OR
You can use the FM
TEXT_CONVERT_XLS_TO_SAP
Thanks,
Naren
‎2007 Feb 23 4:50 PM
Hi,
You can use the FM GUI_UPLOAD by passing the parameter HAS_FIELD_SEPARATOR = 'X'
OR
You can use the FM
TEXT_CONVERT_XLS_TO_SAP
Thanks,
Naren
‎2007 Feb 23 4:55 PM
Hi Chinna,
Use GUI_UPLOAD with FILETYPE as 'ASC' and HAS_FIELD_SEPARATOR as 'X' and specify FILENAME as string.
This is the efficent way of uploading excel into internal table.
data lv_filename type string value 'C:\MATERIALS.XLS'.
IF lv_filename IS NOT INITIAL.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_filename
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_data
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.
Thanks,
Vinay
‎2007 Feb 23 5:04 PM
Hi Chinna
You can use any one of the below 2 Function modules
<b>
ALSM_EXCEL_TO_INTERNAL_TABLE
GUI_UPLOAD</b>
*&---------------------------------------------------------------------*
*& Report Z_UPLOAD_EXAMPLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report z_upload_example.
parameters: exl_file type rlgrap-filename.
* exl_file = p_file.
data: begin of itab occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
matkl like mara-matkl,
wrkst like mara-wrkst,
end of itab.
data: begin of itab1 occurs 0.
include structure alsmex_tabline.
data: end of itab1.
*----------------------------------------------------------------------*
* AT S E L E C T I O N S C R E E N ON VALUE REQUEST
*----------------------------------------------------------------------*
at selection-screen on value-request for exl_file.
* To get the F4 help for file
perform get_filename.
*&---------------------------------------------------------------------*
*& Form GET_FILENAME
*&---------------------------------------------------------------------*
* This routine allows user to select the input file path
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_filename .
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
importing
file_name = exl_file.
.
endform. " get_filename
start-of-selection.
perform upload_data.
*&---------------------------------------------------------------------*
*& Form upload_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form upload_data .
data: v_file type string.
v_file = exl_file.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = exl_file
i_begin_col = 1
i_begin_row = 1
i_end_col = 4
i_end_row = 4
tables
intern = itab1
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " upload_data
end-of-selection.
sort itab1 by row.
loop at itab1.
case itab1-col.
when '0001'.
itab-matnr = itab1-value.
when '0002'.
itab-mtart = itab1-value.
when '0003'.
itab-matkl = itab1-value.
when '0004'.
itab-wrkst = itab1-value.
endcase.
at end of row.
append itab.
clear itab.
endat.
endloop.
loop at itab.
write :/ itab.
endloop.Regards
Naresh
‎2007 Feb 23 7:10 PM