Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to import an Excel file

Former Member
0 Kudos

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.

5 REPLIES 5

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Use this function module ALSM_EXCEL_TO_INTERNAL_TABLE

Reward points if it helps.

former_member200338
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

Hi

Use the FM 'ALSM_EXCEL_TO_INTERNAL_TABLE'.

Thanks

Vasudha

Former Member
0 Kudos

hi,

the following thread my give answer

reward points if useful

regards,

pavan