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

Internal Table data to Excel Sheet

Former Member
0 Likes
1,811

Hi All,

I have an internal table have some data , which I have to populate and save excel sheet on presentation server and application server both according to options, with column heading and header text through program.

could any one help me how to do it, if possible a sample code.

thanks

bobby

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,133

Hi!

Use GUI_DOWNLOAD function module to download your file on presentation server.

Use OPEN DATASET and CLOASE DATASET statements to open your internal table on Application server.

Regards

Abhijeet

6 REPLIES 6
Read only

Former Member
0 Likes
1,133

Hi,

use both FM -

GUI_DOWNLOAD - Presentation server

For application server first we need to use the

OPEN_DATASET or read_DATASET and these FM.

SAP_CONVERT_TO_CSV_FORMAT'

TEXT_CONVERT_XLS_TO_SAP

'DX_FILE_WRITE'

Refer to this thread for more info-

Thanks & Regards,

Chandralekha.

Read only

Former Member
0 Likes
1,133

HI bobby,

Transferring Data from ABAP Internal Table to Excel Sheet

If you wish to transfer data from ABAP internal table to EXCEL you can use the following function module.

MS_EXCEL_OLE_STANDARD_DAT

This function module populates an existing excel sheet with the data from the ABAP internal table. Please find below code which shows hwo to declare and populate the import and important parameters. In the next section we will see in depth how this function module operates.

REPORT ZEX_DATATOEXCEL .

Parameters: P_file like RLGRAP-FILENAME.

data : begin of int_head occurs 0,

Filed1(20) type c, " Header Data

end of int_head.

data : begin of int_data occurs 0,

Field1(20) type c, " Data

Field2(20) type c,

Field3(20) type c,

Field4(20) type c,

end of int_data.

int_head-Filed1 = 'Sales Ord'.

APPEND int_head.

CLEAR int_head.

int_head-Filed1 = 'Sold-to-Party'.

APPEND int_head.

CLEAR int_head.

int_head-Filed1 = 'Purchase Ord'.

APPEND int_head.

CLEAR int_head.

int_head-Filed1 = 'Ship-to-Party'.

APPEND int_head.

CLEAR int_head.

int_data-field1 = '1JOHN'.

int_data-field2 = '2TOM'.

int_data-field3 = '3BRAD'.

int_data-field4 = '4PETER'.

Append int_data.

Clear int_data.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

file_name = p_file " path offile where u need to download

  • CREATE_PIVOT = 0

  • DATA_SHEET_NAME = ' '

  • PIVOT_SHEET_NAME = ' '

  • PASSWORD = ' '

  • PASSWORD_OPTION = 0

TABLES

  • PIVOT_FIELD_TAB =

data_tab = int_data "internal table with data

fieldnames = int_head "internal table with header

EXCEPTIONS

file_not_exist = 1

filename_expected = 2

communication_error = 3

ole_object_method_error = 4

ole_object_property_error = 5

invalid_filename = 6

invalid_pivot_fields = 7

download_problem = 8

OTHERS = 9

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

thanks

karthik

Read only

Former Member
0 Likes
1,134

Hi!

Use GUI_DOWNLOAD function module to download your file on presentation server.

Use OPEN DATASET and CLOASE DATASET statements to open your internal table on Application server.

Regards

Abhijeet

Read only

Former Member
0 Likes
1,133

Hi,

Check out:

Regards,

Ranjit

Read only

Former Member
0 Likes
1,133

HI,

You can transfer data to a excel sheet using FM ' GUI_DOWNLOAD'.

Here is a sample code for this,

TYPES : BEGIN OF ls_test,

line type string,

END OF ls_test.

DATA : lw_test type ls_test,

li_test TYPE STANDARD TABLE OF ls_test,

int1 TYPE C,

int2 TYPE c.

DATA : gv_tab(1) TYPE c

VALUE cl_abap_char_utilities=>horizontal_tab .

int1 = '1'.

int2 = '2'.

CONCATENATE int1 gv_tab int2 gv_tab '=SUM(A1:B1)'

INTO lw_test-line .

APPEND lw_test to li_test.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'E:\EXCELFORM.XLS'

FILETYPE = 'ASC'

tables

data_tab = li_test

.

Read only

Former Member
0 Likes
1,133

hi do like this ...

if r_applser = 'X'.

loop at itab .

open dataset for output in text mode encoding default .

if sy-subrc ne 0.

exit.

endif.

output+0(10) = itab-field1 .

output+10(10) = itab-field2 .

output+20(10) = itab-field3 .

output+30(10) = itab-field4.

transfer output to p_file .

endloop.

elseif r_presser = 'X'.

call function'GUI_DOWNLOAD'

exporting

filename = p_file

tables

data_tab = head_test .

endif.