Wednesday, December 22, 2010
& Upload and excel file into an internal table using the following function module: ALSM_EXCEL_TO_INTERNAL_TABLE
REPORT  upload_excel NO STANDARD PAGE HEADING.
DATA: itab LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
TYPES: BEGIN OF t_record,
name1 LIKE itab-value,
name2 LIKE itab-value,
age   LIKE itab-value,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
DATA: gd_currentrow TYPE i.
PARAMETER p_infile LIKE rlgrap-filename.

START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename                = p_infile
i_begin_col             = '1'
i_begin_row             = '2'  "Do not require headings
i_end_col               = '14'
i_end_row               = '31'
TABLES
intern                  = itab
EXCEPTIONS
inconsistent_parameters = 1
upload_ole              = 2
OTHERS                  = 3.
IF sy-subrc <> 0.
MESSAGE e010(zz) WITH text-001. "Problem uploading Excel Spreadsheet
ENDIF.
SORT itab BY row col.
READ TABLE itab INDEX 1.
gd_currentrow = itab-row.
LOOP AT itab.
IF itab-row NE gd_currentrow.
APPEND wa_record TO it_record.
CLEAR wa_record.
gd_currentrow = itab-row.
ENDIF.
CASE itab-col.
WHEN '0001'.                              "First name
wa_record-name1 = itab-value.
WHEN '0002'.                              "Surname
wa_record-name2 = itab-value.
WHEN '0003'.                              "Age
wa_record-age   = itab-value.
ENDCASE.
ENDLOOP.
APPEND wa_record TO it_record.
* Display report data for illustration purposes
LOOP AT it_record INTO wa_record.
WRITE:/     sy-vline,
(10) wa_record-name1, sy-vline,
(10) wa_record-name2, sy-vline,
(10) wa_record-age, sy-vline.
ENDLOOP.

0 comments:

Post a Comment

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.