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: 

Download an excel sheet into an internal table

Former Member
0 Kudos

Can any one tell me how to download an excel sheet into an internal table.. is there any function module...?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Rajesh,

I Have a example for the excel to internal table upload..

Check this..

&----


*& Form excel_upload

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM excel_upload .

DATA : l_f_index TYPE i.

FIELD-SYMBOLS : <l_fs> TYPE ANY.

  • Upload Excel file

IF p_rb2 = 'X'.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_fname2

i_begin_col = g_f_start_col

i_begin_row = g_f_start_row

i_end_col = g_f_end_col

i_end_row = g_f_end_row

TABLES

intern = g_t_intern

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.

ENDIF.

  • Populate data into Internal table

SORT g_t_intern BY row col .

LOOP AT g_t_intern .

MOVE g_t_intern-col TO l_f_index .

ASSIGN COMPONENT l_f_index OF STRUCTURE g_s_upld TO <l_fs> .

MOVE g_t_intern-value TO <l_fs>.

AT END OF row .

APPEND g_s_upld TO g_t_upld.

CLEAR g_s_upld .

ENDAT .

ENDLOOP .

LOOP AT g_t_upld INTO g_s_upld.

  • Convert the material to internal format.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

EXPORTING

input = g_s_upld-matnr

IMPORTING

output = g_s_upld-matnr

EXCEPTIONS

length_error = 1

OTHERS = 2.

IF sy-subrc EQ 0.

MODIFY g_t_upld FROM g_s_upld TRANSPORTING matnr.

ENDIF.

ENDLOOP.

ENDFORM. " excel_upload

Reward if usefull..

Regds,

Srini

3 REPLIES 3

gopi_narendra
Active Contributor
0 Kudos

Use the FM : ALSM_EXCEL_TO_INTERNAL_TABLE

Usage as below :

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_filename

i_begin_col = vf_start_col

i_begin_row = vf_start_row

i_end_col = vf_end_col

i_end_row = vf_end_row

TABLES

intern = if_intern.

IF if_intern[] IS INITIAL.

p_text = 'No Data Uploaded'.

ELSE.

SORT if_intern BY row col.

LOOP AT if_intern.

MOVE : if_intern-col TO vf_index.

ASSIGN COMPONENT vf_index OF STRUCTURE p_download TO <fs>.

MOVE : if_intern-value TO <fs>.

AT END OF row.

APPEND p_download.

CLEAR p_download.

ENDAT.

ENDLOOP.

ENDIF.

Regards

- Gopi

ferry_lianto
Active Contributor
0 Kudos

Hi,

You can also use FM TEXT_CONVERT_XLS_TO_SAP.

Please check this link for sample codes.

https://forums.sdn.sap.com/click.jspa?searchID=389598&messageID=2802611

Hope this will help.

Regards,

Ferry Lianto

Former Member
0 Kudos

Hello Rajesh,

I Have a example for the excel to internal table upload..

Check this..

&----


*& Form excel_upload

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM excel_upload .

DATA : l_f_index TYPE i.

FIELD-SYMBOLS : <l_fs> TYPE ANY.

  • Upload Excel file

IF p_rb2 = 'X'.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_fname2

i_begin_col = g_f_start_col

i_begin_row = g_f_start_row

i_end_col = g_f_end_col

i_end_row = g_f_end_row

TABLES

intern = g_t_intern

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.

ENDIF.

  • Populate data into Internal table

SORT g_t_intern BY row col .

LOOP AT g_t_intern .

MOVE g_t_intern-col TO l_f_index .

ASSIGN COMPONENT l_f_index OF STRUCTURE g_s_upld TO <l_fs> .

MOVE g_t_intern-value TO <l_fs>.

AT END OF row .

APPEND g_s_upld TO g_t_upld.

CLEAR g_s_upld .

ENDAT .

ENDLOOP .

LOOP AT g_t_upld INTO g_s_upld.

  • Convert the material to internal format.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

EXPORTING

input = g_s_upld-matnr

IMPORTING

output = g_s_upld-matnr

EXCEPTIONS

length_error = 1

OTHERS = 2.

IF sy-subrc EQ 0.

MODIFY g_t_upld FROM g_s_upld TRANSPORTING matnr.

ENDIF.

ENDLOOP.

ENDFORM. " excel_upload

Reward if usefull..

Regds,

Srini