Abap how to create an excel file sample

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.


source
http://abaplovers.blogspot.com/2008/05/abap-internal-table-to-excel-sheet.html
0 comments:

Post a Comment

message

Labels

NuffNang

Search google

Blog Archive

My Blog List

Twitter

Message

Followers