Application Development and Automation 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: 
Read only

EXCEL TO INTERNAL TABLE

Former Member
0 Likes
804

report zagexcel.

data: g_t_excel_data like alsmex_tabline occurs 0 with header line.

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

filename = 'C:\Documents and Settings\ics001187\Desktop\book1.xls'

i_begin_col = 1

i_begin_row = 1

i_end_col = 40

i_end_row = 15000

tables

intern = g_t_excel_data.

*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.

sort g_t_excel_data.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
733

hI,

tRY the below code:

TYPE-POOLS: truxs.

TYPES: BEGIN OF ty_dataupload, "Input file load structure

col01(60) TYPE c,

col02(60) TYPE c,

col03(60) TYPE c,

END OF ty_dataupload.

DATA: it_raw TYPE truxs_t_text_data .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_line_header = ' '

i_tab_raw_data = it_raw "work table

i_filename = p_file

TABLES

i_tab_converted_data = g_t_datatab[] "internal table to store the the data

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

Regards

hI,

tRY the below code:

TYPE-POOLS: truxs.

TYPES: BEGIN OF ty_dataupload, "Input file load structure

col01(60) TYPE c,

col02(60) TYPE c,

col03(60) TYPE c,

END OF ty_dataupload.

DATA: it_raw TYPE truxs_t_text_data .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_line_header = ' '

i_tab_raw_data = it_raw "work table

i_filename = p_file

TABLES

i_tab_converted_data = g_t_datatab[] "internal table to store the the data

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

Regards

4 REPLIES 4
Read only

former_member188827
Active Contributor
0 Likes
733

wat do u want 2 kno?

Read only

Former Member
0 Likes
733


HI,

define the internal table in which you are reading excel data as follows:
1. DATA declaration
data: g_t_excel_data like alsmex_tabline occurs 0 with header line,

2. call Function module 
Function to get the excel data from the file into internal table
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_pcfile
i_begin_col = 1
i_begin_row = 2
i_end_col = 14
i_end_row = 65536
TABLES
intern = g_t_excel_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
message 'Error opening specified file' type 'E'.
endif.

3. by using field-symbols transfer your data to internal table ITAB (same as your data structure) as follows:-

data: g_index like sy-tabix,
loop at g_t_excel_data.
move : g_t_excel_data-col to g_index.
assign component g_index of structure ITAB to <fs>.
move : g_t_excel_data-value to <fs>.

*at end of row append record
at end of row.
append ITAB.
clear ITAB
clear <fs>.
endat.
endloop. 

refer to this code. hope it might help u

regards

ravish

<b>plz dont forget to reward if useful</b>

Read only

Former Member
0 Likes
733

HI

To upload

first use FM ALSM_EXCEL_TO_INTERNAL_TABLE and then move the date to internal table and

There are two function modules you can use: (1) 'ALSM_EXCEL_TO_INTERNAL_TABLE' or

(2) 'KCD_EXCEL_OLE_TO_INT'. Very similar but the first function module (ASLM) used in for foreground processing.

<b>1st report</b>

<b>2nd sample report</b>

 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.


***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
LOOP AT it_datatab INTO wa_datatab.
WRITE:/ wa_datatab-col1,
wa_datatab-col2,
wa_datatab-col3.
ENDLOOP.


 ]]>

To download a file from internal table to excel

 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
]]>

Check this link

[Removed by the moderator.]

Reward all helpfull answers

Regards

Pavan

Read only

Former Member
0 Likes
734

hI,

tRY the below code:

TYPE-POOLS: truxs.

TYPES: BEGIN OF ty_dataupload, "Input file load structure

col01(60) TYPE c,

col02(60) TYPE c,

col03(60) TYPE c,

END OF ty_dataupload.

DATA: it_raw TYPE truxs_t_text_data .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_line_header = ' '

i_tab_raw_data = it_raw "work table

i_filename = p_file

TABLES

i_tab_converted_data = g_t_datatab[] "internal table to store the the data

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

Regards