11-16-2007 5:26 AM
Hi ,
I amwriting a BDC Program..
How to import a Excel File by Browsing the Excel file from the Directory and Storing that values in the internal table.
Can any one send the code for this,
Points will be awarded.
Regards,
Jayasimha Jangam.
11-16-2007 5:30 AM
check this
type-pools : TRUXS.
PARAMETERS : P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.
DATA : VRAW TYPE TRUXS_T_TEXT_DATA .
<declare your int table as per excel say ITAB>
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FNAME
.
start-of-selection.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_LINE_HEADER =
i_tab_raw_data = VRAW
i_filename = P_FNAME
tables
i_tab_converted_data = ITAB
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
regards
shiba dutta
11-16-2007 5:32 AM
Hi,
Use this function module ALSM_EXCEL_TO_INTERNAL_TABLE
Reward points if it helps.
11-16-2007 5:32 AM
Hi,
Create a select parameter. at selection screen, use FM F4_FILENAME to get the dialog box.
see the sample code.
&----
*& Form display_dialog
&----
To display the pop up dialog box
----
*
----
FORM display_dialog.
Calling FM to display File Select dialog box
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
FIELD_NAME = ' '
IMPORTING
file_name = p_file .
ENDFORM. " display_dialog
FORM upload_data.
DATA : lt_itab TYPE STANDARD TABLE OF alsmex_tabline,
ls_itab TYPE alsmex_tabline,
ls_upload TYPE ty_upload_data.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 2
i_end_col = 5
i_end_row = 50000
TABLES
intern = lt_itab[]
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE i000 WITH text-t04.
LEAVE LIST-PROCESSING.
ENDIF.
CLEAR ls_itab.
LOOP AT lt_itab INTO ls_itab.
CASE ls_itab-col.
WHEN 1.
ls_upload-matnr = ls_itab-value.
WHEN 2.
PERFORM convert_to_decimal USING ls_itab-value.
ls_upload-bmeng = ls_itab-value.
WHEN 3.
ls_upload-idnrk = ls_itab-value.
WHEN 4.
PERFORM convert_to_decimal USING ls_itab-value.
ls_upload-menge = ls_itab-value.
WHEN 5.
ls_upload-meins = ls_itab-value.
ENDCASE.
AT END OF row.
APPEND ls_upload TO gt_upload.
CLEAR ls_upload.
ENDAT.
CLEAR ls_itab.
ENDLOOP.
Deleting the contents of internal table
FREE lt_itab.
11-16-2007 5:32 AM
11-16-2007 5:37 AM