01-12-2006 9:58 PM
Hi all,
I am writing a BDC rogram for transaction 'MM01'. For this I want to update data from an excel sheet to internal tabel.Just as we do from flat file to inetrnal table.Can any explainme how to do this.
Regards,
Vijay.
01-12-2006 10:52 PM
while using ALSM_EXCEL_TO_INTERNAL_TABLE
TYPES :ITAB TYPE ALSMEX_TABLINE.
DATA: ITAB TYPE STANDARD TABLE OF ITAB WITH HEADER LINE.
Data:filename type rlgrap-filename .
filename = 'D:\Documents and Settings\501030562\Desktop\Book1.xls'.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = filename
i_begin_col = 1
i_begin_row = 1
i_end_col = 1
i_end_row = 1
tables
intern = itab
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.
01-12-2006 10:00 PM
Hi Vijay,
Use "GUI_UPLOAD" Function module to download the data from the Excel file.
Then usual process.
Here is the Sample Code.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = v_string1 ( File Path)
FILETYPE = 'ASC' ( Type of the File)
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_WORK_XL. ( Internal Table name, Should match the stucture of the excel file spacing).
Thanks
Govind.
Message was edited by: Govindarajan Seenivasan
01-12-2006 10:00 PM
Hi Vijay,
One way is saving the Excel sheet as tab delimited file & then use FM GUI_UPLOAD or You can directly upload the excel sheet using file type 'DAT' in the same FM.
01-12-2006 10:02 PM
Hi Vijay,
First convert your XL file to a tabdelimited file or CSV file.
Then use "GUI_upload" function use filetype = 'ASC'.
Lanka
01-12-2006 10:05 PM
You can save the file as Tab delimited Text file and use GUI_UPLOAD as follows :
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_file
filetype = 'ASC'
has_field_separator = 'X'
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.
GUI_UPLOAD takes only 'ASC' or 'BIN' file types.
Vijay.
01-12-2006 10:08 PM
01-12-2006 10:09 PM
File -> save as -> do a dropdown for file types , select text tab delimited and save.
Vijay.
01-12-2006 10:11 PM
Hi,
Open XL sheet in Ms Excel and save it as Tab delimited file by checking at "save as type".
Lanka
01-12-2006 10:21 PM
HI I am sending you code. PLease check and tell me where I am going wrong.This is giving a short dump.The excel sheet is saved as Book1(txt file).
REPORT ZV_LOCALFILE_ITTABLE .
DATA : BEGIN OF itab OCCURS 0 ,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
END OF itab.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\Book1.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = itab
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
OTHERS = 17
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at itab.
write 😕 itab-carrid,itab-connid,itab-fldate.
endloop.
Regards,
Vijay
01-12-2006 10:24 PM
01-12-2006 10:25 PM
May be itz a type conversion error.
Declare a variable v_file type string.
v_file = filename
and use v_file for file name in GUI_UPLOAD.
Vijay.
Message was edited by: Vijay Ganga
01-12-2006 10:27 PM
u have to use GUI_DOWNLOAD
sorry ignore this , got confused
Message was edited by: chandrasekhar jagarlamudi
01-12-2006 10:28 PM
01-12-2006 10:29 PM
Your file and the itab structure should be same. My guess is that excel has the date in external format like 'MM/DD/YYYY' or 'DD-MM-YYYY', whereas your internal table is defined to accept the date as a 8 digit number. Change the definition of that field to fldat(10) or make sure the file contains the date in YYYYMMDD format.
Srinivas
01-12-2006 10:34 PM
I tried this it worked :
REPORT ZV_LOCALFILE_ITTABLE .
DATA : BEGIN OF itab OCCURS 0 ,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
END OF itab.
<b>DATA : V_STRING TYPE STRING.</b>
<b>V_STRING = 'C:\Temp\Book1.txt'.</b>
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
<b>filename = V_STRING</b>
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = itab
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
OTHERS = 17
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at itab.
write 😕 itab-carrid,itab-connid,itab-fldate.
endloop.
also change the date in file to YYYYMMDD format
Message was edited by: Vijay Ganga
01-12-2006 10:11 PM
Hi Vijay,
In Excel, Goto File-> Save as and then select the tab delimeited Text... and then save.
Thanks
01-12-2006 10:12 PM
u can use this FM directly 'ALSM_EXCEL_TO_INTERNAL_TABLE'
don't forget to delete first record as it will have header
01-12-2006 10:31 PM
I am uploading only one line of dat from excel sheet.
itab dfenition is :
DATA : BEGIN OF itab OCCURS 0 ,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
END OF itab.
the flat file data is AA 0017 03/06/2002.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = 'D:\Book1.xls'
i_begin_col = 1
i_begin_row = 1
i_end_col = 1
i_end_row = 1
tables
intern = itab
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.
It gave a short dump with exception no 1.
can u please tell what the error is.
Regards,
Vijay
01-12-2006 10:40 PM
See my previous post. That is exactly the problem. Your date input is the culprit.
01-12-2006 10:52 PM
while using ALSM_EXCEL_TO_INTERNAL_TABLE
TYPES :ITAB TYPE ALSMEX_TABLINE.
DATA: ITAB TYPE STANDARD TABLE OF ITAB WITH HEADER LINE.
Data:filename type rlgrap-filename .
filename = 'D:\Documents and Settings\501030562\Desktop\Book1.xls'.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = filename
i_begin_col = 1
i_begin_row = 1
i_end_col = 1
i_end_row = 1
tables
intern = itab
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.