‎2007 Jul 19 10:35 AM
I m working on a BDC to upload a excel file....i donot want to hardcode the path within the program and i want to locate the file on execution.
Specifically the file to be uploaded is an excel file and the first row consists of heading which i donot want.
Its working fine with txt files but not in xls files..
kindly help
‎2007 Jul 19 10:46 AM
if you dont want to hard code the path for filename then try this
parameters : p_file like rlgrap-filename.
*Input Help for the Download Directory
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = v_repid
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
‎2007 Jul 19 10:39 AM
HI,
if the file is always the excel format
then you can use
ALSM_EXCEL_TO_INTERNAL_TABLE
or some times txt and some times excel then go gui_upload
and for the file path go for
f4_filename
reward points if helpful
thanks & regards,
venkatesh
‎2007 Jul 19 10:39 AM
Check out the sample example below
parameters : p_ifname type rlgrap-filename.
data : it_data type table of alsmex_tabline initial size 0,
is_data type alsmex_tabline.
Flatfile internal table.
types : begin of ty_tab,
zuonr type bsid-zuonr,
end of ty_tab.
data : it_tab type table of ty_tab initial size 0,
is_tab type ty_tab.
&----
*& Form upload_data_excel
&----
text
----
--> p1 text
<-- p2 text
----
form upload_data_excel.
If Input file name is not initial.
if not p_ifname is initial.
Upload EXCEL data into internal table
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_ifname
i_begin_col = 1
i_begin_row = 1
i_end_col = 256
i_end_row = 65356
tables
intern = it_data
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.
endif.
Append EXCEL Data into a internal table
loop at it_data into is_data.
at new row.
clear is_tab.
endat.
if is_data-col = '001'.
move is_data-value to is_tab-zuonr.
endif.
at end of row.
append is_tab to it_tab.
endat.
clear : is_data.
endloop.
Thanks
Seshu
‎2007 Jul 19 10:41 AM
Hi,
Use FM ALSM_EXCEL_TO_INTERNAL_TABLE
Remember it will not upload data as Text file does.
It will take data like.
ROW COLUMN and VALUE.
So acccordingly you have to arrange it.
Reward if useful!
‎2007 Jul 19 10:45 AM
Hi...
Plz check the code.
DATA : IT_EXCEL TYPE TABLE OF ALSMEX_TABLINE.
PARAMETERS: P_FILE TYPE RLGRAP-FILENAME.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = P_FILE
.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = P_FILE
i_begin_col = 1
i_begin_row = 2 "From 2nd row
i_end_col = 2
i_end_row = 4
tables
intern = IT_EXCEL
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.
<b>Reward if Helpful.</b>
‎2007 Jul 19 11:24 AM
HI narayana varma...
i used your logic its working fine but how will i move this data to my normal internal table.
‎2007 Jul 23 11:21 AM
Use TEXT_CONVERT_XLS_TO_SAP instead. itab is the format of your input file.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER =
i_tab_raw_data = it_raw
i_filename = fname
TABLES
i_tab_converted_data = itab
‎2007 Jul 19 10:46 AM
if you dont want to hard code the path for filename then try this
parameters : p_file like rlgrap-filename.
*Input Help for the Download Directory
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = v_repid
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.