‎2009 Mar 27 4:08 AM
Hi,
i have one excel. i want to upload in table.
can you help me.............
Regards,
k.karthikeyan.
‎2009 Mar 27 4:26 AM
Hi,
TYPE-POOLS truxs.
"internal table declared to be passed in the
"function module used to convert data from xls to sap
DATA: it_raw TYPE truxs_t_text_data.
*&---------------------------------------------------------------------*
*&Function module called to upload xls data into an internal table
*&---------------------------------------------------------------------*
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'
i_line_header = 'X'
i_tab_raw_data = it_raw
i_filename = p_file "file path
TABLES
i_tab_converted_data = it_upload[] "internal tsble into which data
"will get uploaded
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.
Then loop on to internal table it_upload,
And move the data from its work area into the
table fields and use Modify statement in the end
to modify the database table from that internal table,
And then close the loop.
Hope it helps
Regards
Mansi
‎2009 Mar 27 4:13 AM
‎2009 Mar 27 4:13 AM
‎2009 Mar 27 4:21 AM
Hello Karthikeyan,
Before posting a question, just give a search in SDN Forums
You would get wonderful forum discussion which gives you different kinds of discussions.
Hope you do that from now on.
Thanks,
Babu Kilari
‎2009 Mar 27 4:26 AM
Hi,
TYPE-POOLS truxs.
"internal table declared to be passed in the
"function module used to convert data from xls to sap
DATA: it_raw TYPE truxs_t_text_data.
*&---------------------------------------------------------------------*
*&Function module called to upload xls data into an internal table
*&---------------------------------------------------------------------*
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'
i_line_header = 'X'
i_tab_raw_data = it_raw
i_filename = p_file "file path
TABLES
i_tab_converted_data = it_upload[] "internal tsble into which data
"will get uploaded
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.
Then loop on to internal table it_upload,
And move the data from its work area into the
table fields and use Modify statement in the end
to modify the database table from that internal table,
And then close the loop.
Hope it helps
Regards
Mansi
‎2009 Mar 27 4:49 AM
First u need to fetch all the data in the excel into an internal table.for this u can use the FM:
Uploading the data in the file into internal table
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_filename = p_file "PATH where the excel is placed
TABLES
i_tab_converted_data = t_upload[] " internal table to which the
data should be loaded.this should be of the same structure as with the data in the excel.
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
now,
loop on the internal table into wa.
ztable-field1 = wa_upload-field1.
ztable-field2 = wa_upload-field2.
"
"so on..
MODIFY ZTABLE.
endloop.
‎2009 Mar 27 4:54 AM
Hi ,
Check this code
Table ceclaration- to read data from excel file
TYPES: BEGIN OF ty_exceldata ,
matnr(18) TYPE c,
menge(13) TYPE c,
END OF ty_exceldata .
Get data from excel file and put into internal table
DATA: it_exceldata TYPE STANDARD TABLE OF ty_exceldata ,
it_exceldata_copy TYPE STANDARD TABLE OF ty_exceldata .
Table to store Excel data
DATA: it_data TYPE kcde_cells OCCURS 0 WITH HEADER LINE.
----
Field Symbols Begin with <FS_XXXX> *
----
Field symbol to assign data to internal table
FIELD-SYMBOLS: <fs_source> TYPE ANY .
----
Constants Begin with C_ *
----
Constants declaration for data processing
CONSTANTS: c_scol TYPE i VALUE '1' , " Start Column
c_srow TYPE i VALUE '1' , " Start Row
c_ecol TYPE i VALUE '256' , " End Column
c_erow TYPE i VALUE '65536' . " End Row
----
----
Work Area for Internal tables Begin with WA_ *
----
Work area for internal table
DATA: wa_exceldata TYPE ty_exceldata ,
wa_exceldata_copy TYPE ty_exceldata .
DATA: w_index TYPE SY-TABIX.
Upload excel file data into internal table
PERFORM f003_upload_excel_file TABLES it_exceldata
USING pr_file
c_scol
c_srow
c_ecol
c_erow.
PERFORM f004_fillstructure .
&----
*& Form f003_upload_excel_file
&----
text: Upload Excel Data into Internal Table
----
FORM f003_upload_excel_file TABLES P_IT_EXCELDATA STRUCTURE wa_exceldata
USING P_PR_FILE TYPE rlgrap-filename
P_C_SCOL TYPE i
P_C_SROW TYPE i
P_C_ECOL TYPE i
P_C_EROW TYPE i.
Function module to read excel file and convert it into internal table
CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
EXPORTING
filename = p_pr_file
i_begin_col = p_c_scol
i_begin_row = p_c_srow
i_end_col = p_c_ecol
i_end_row = p_c_erow
TABLES
intern = it_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
Error in file upload
IF sy-subrc NE 0 .
MESSAGE e999 WITH text-003. " 003-Error While Uploading File.
EXIT .
ENDIF .
Uploaded Excel File is empty
IF it_data[] IS INITIAL .
MESSAGE e999 WITH text-004. " 004-No Data Found In Excel File.
EXIT.
ELSE .
SORT it_data BY row col .
Loop to fill data in Internal Table
LOOP AT it_data .
MOVE it_data-col TO w_index .
ASSIGN COMPONENT w_index OF STRUCTURE p_it_exceldata TO <fs_source> .
MOVE it_data-value TO <fs_source> .
AT END OF row .
Append data into internal table
APPEND p_it_exceldata .
CLEAR p_it_exceldata .
ENDAT .
ENDLOOP .
ENDIF .
ENDFORM. " f003_upload_excel_file
&----
*& Form f004_fillstructure
&----
Text: Process header and line item data to Fill Bapi Structure *
and Create Cash Journal Entry *
----
FORM f004_fillstructure .
Delete first line from internal table
DELETE it_exceldata[] INDEX c_counter .
ENDFORM. " f004_fillstructure