09-11-2014 11:00 AM
Hello all,
i am trying to upload an excel file to internal table but i get an error.
i am using fm 'F4_FILENAME' to get the file and then i am using fm 'ALSM_EXCEL_TO_INTERNAL_TABLE' .
i have searched the net but i couldnt find a solution to that error.
here is my code :
DATA FILE_PATH LIKE RLGRAP-FILENAME.
DATA: it_raw TYPE truxs_t_text_data.
data : BEGIN OF itab OCCURS 0,
BSKODU like ZR52-BSKODU,
BSADI LIKE ZR52-BSADI,
GSBER LIKE ZR52-GSBER,
GBATARIH LIKE ZR52-GBATARIH,
GBITARIH LIKE ZR52-GBITARIH,
AKTIFPASIF LIKE ZR52-AKTIFPASIF,
MAIL LIKE ZR52-MAIL,
END OF ITAB.
START-OF-SELECTION.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'FILE_LOC' "
IMPORTING
file_name = FILE_PATH.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = FILE_PATH
I_BEGIN_COL = '1'
I_BEGIN_ROW = '2'
I_END_COL = '2'
I_END_ROW = '2'
TABLES
INTERN = ITAB
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2.
regards,
cem
09-11-2014 11:09 AM
Hi,
whats the error you get & whats the subrc value after the FM Call ?
09-11-2014 11:13 AM
09-11-2014 11:18 AM
The below parameters are integers, Pass values without ' ', like below
I_BEGIN_COL = 1
I_BEGIN_ROW = 2
I_END_COL = 10
I_END_ROW = 65536
09-11-2014 11:22 AM
09-11-2014 11:31 AM
HI Cem,
Please refer to the SAP note 933420 - ALSM_EXCEL_TO_INTERNAL_TABLE.
You can refer to the link below to have an idea how to fulfil your requirement:
Upload excel file from PC into SAP using ABAP inc .xls and .xlsx
Regards,
Ashvin
09-11-2014 11:36 AM
Also your internal table should be of the structure - ALSMEX_TABLINE.
Go to FM - ALSM_EXCEL_TO_INTERNAL_TABLE - Click on where used list, & if you see any programs using this FM, compare your inputs with that.
09-11-2014 11:47 AM
09-11-2014 11:52 AM
Hi,
Return Itab will be of type ALSMEX_TABLINE as suggested by Seema M, and This itab will have only three fields Row Column and Value. You may declare your Itab like
data: itab like alsmex_tabline occurs 0 with header line.
and Furthur loop this to retrieve data.
09-11-2014 12:02 PM
This may due to type conflict between XL data and internal table fields.
Declare all fields in itab as characters.
09-11-2014 12:06 PM
Hi cem,
Hope it helpful.
Declare internal table as
Data : ist_excel TYPE STANDARD TABLE OF alsmex_tabline,
wa_excel TYPE alsmex_tabline.
after FM.
LOOP AT ist_excel INTO wa_excel.
CASE wa_excel-col.
WHEN '0001'.
wa_itab-BSKODU = wa_excel-value.
ENDCASE.
AT END OF row.
append wa_itab to itab.
clear wa_itab.
ENDAT.
CLEAR wa_excel.
ENDLOOP.
Regards,
Venkat.
09-11-2014 12:07 PM
Hi
I recommend you to use the FM TEXT_CONVERT_XLS_TO_SAP as it is more reliable.
Regards
Vaibhav Juneja
09-11-2014 12:28 PM
Hi Cem,
check the below code & update your code it may be solve your issue.
TYPE-POOLS: TRUXS .
DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = FILE_PATH.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = IT_RAW
I_FILENAME = FILE_PATH
TABLES
I_TAB_CONVERTED_DATA = ITAB[].
Regards,
Mukesh
09-11-2014 12:28 PM
hi ,
i have use this fm and i have done it in following way , think you can define your itab with type ALSMEX_TABLINE
data :FILENAME TYPE RLGRAP-FILENAME,
IT_FILE LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SY-REPID
DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = FILENAME
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = FILENAME
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '42'
I_END_ROW = '100'
TABLES
INTERN = IT_FILE
* 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.
09-11-2014 12:44 PM
Hi Cem ,
Excel and internal table contents should be same sequences. Did u check for it ?
09-11-2014 12:49 PM
Hi Cem,
When i analyse your code you want to read only 2nd row from the excel sheet?
if you have more than 2 records plz change the parameters of the function module of I_BEGIN_ROW, I_BEGIN_COL,I_END_ROW and I_END_COLUMN and try this let us know what happan
Regards
Sudhakar
09-11-2014 1:11 PM
i can change these parameters that is no problem.but how will i updata z table from an excel file with 1000 or more records?
09-11-2014 12:49 PM
This FM will return a table of type ALSMEX_TABLINE, so record with horizontal and vertical index and a value, not what you expected. You MUST use the format specified in FM signature, then loop at this internal table to build your final table.
Create empty record AT NEW ROW, for every COL use an ASSIGN COMPONENT and map value to field of your format, AT END OF ROW append record to your table.
Also you may be required to use some conversion-exit or implicit correction from character values and be ready to catch format conversion errors.
Regards,
Raymond
09-11-2014 1:12 PM
09-11-2014 12:50 PM
thank you all for your answers.
i have solved the error now i can upload from excel to internl table but this fucntion doesnt require my needs.
becase excel file sometimes will have 1 record and sometimes will have 1000 records.
is there any function that i can use for this purpose?
09-11-2014 12:53 PM
hey,
if the no of colums are remains same in your case then you can use same fm and what you can do is you can ask user to add total no of rows at selection screen and use that variable for no of rows in fm .
Regards
Jaydeep
09-11-2014 12:55 PM
09-11-2014 12:56 PM
Hi Cem ,
I use this function.
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
i_line_header = 'X'
i_tab_raw_data = gv_raw " WORK TABLE
i_filename = p_fname
tables
i_tab_converted_data = gt_excel[] "ACTUAL DATA
exceptions
conversion_failed = 1
others = 2.
09-11-2014 12:58 PM
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = abap_true
i_tab_raw_data = git_raw
i_filename = p_file "File path
TABLES
i_tab_converted_data = git_excel "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.
09-11-2014 1:06 PM
09-11-2014 1:11 PM
09-11-2014 1:12 PM
Hi Cem,
Use FM TEXT_CONVERT_XLS_TO_SAP and check the below code it may be solve your issue.
TYPE-POOLS: TRUXS .
DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = FILE_PATH.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = IT_RAW
I_FILENAME = FILE_PATH
TABLES
I_TAB_CONVERTED_DATA = ITAB[].
Regards,
Mukesh
09-11-2014 1:12 PM
09-11-2014 1:14 PM
i have done this before but git_excel returns empty.
what am i doing wrong?
09-11-2014 1:17 PM
09-11-2014 1:20 PM
Hi,
Try by adding [] after your Itab
TABLES
i_tab_converted_data = git_excel[]
09-11-2014 1:24 PM
09-11-2014 1:22 PM
09-11-2014 1:30 PM
Hi Cem Unal,
The reason for your error is type conflict.In the structure for itab you are having around 5 to 6 fields and in the function module which you are using for uploading data from excel to internal table(ALSM_EXCEL_TO_INTERNAL_TABLE).Should be passed as below
* need changes to your code
Regards,
Chakradhar.