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: 

FM to mail a excel file generated by XML

Former Member
0 Kudos

Hi All,

I have a requirement to generate fancy excel file as attachment in mail.

Please help with some FM to send mail with excel as attachment,

I have used a code like the sample code given below.

*&----


**& Report ZTEST_NP_EXCEL_XML

**&

**& Download the formatted excel file using XML

*&----


report Z_IXML.

TABLES USR02.

TYPES XMLLINE(1024) TYPE C.

DATA IT_XML TYPE XMLLINE OCCURS 0.

DATA WA_XML TYPE XMLLINE.

DATA FNAME(60) TYPE C VALUE '/ft/D02/001/test.xls'.

\ Build-up of xml in internal table

\\* Opening tags

APPEND '<?xml version="1.0"?>' TO IT_XML.

APPEND '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"'

TO IT_XML.

APPEND 'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">'

TO IT_XML.

APPEND ' <Worksheet ss:Name="Tabelle1">' TO IT_XML.

APPEND ' <Table>' TO IT_XML.

\\* The actual data from table USR02

SELECT * FROM USR02.

APPEND ' <Row>' TO IT_XML.

CONCATENATE ' <Cell><Data ss:Type="String">'

USR02-BNAME '</Data></Cell>' INTO WA_XML.

APPEND WA_XML TO IT_XML.

CONCATENATE ' <Cell><Data ss:Type="String">'

USR02-TRDAT '</Data></Cell>' INTO WA_XML.

APPEND WA_XML TO IT_XML.

APPEND ' </Row>' TO IT_XML.

ENDSELECT.

\*Closing tags

APPEND ' </Table>' TO IT_XML.

APPEND ' </Worksheet>' TO IT_XML.

APPEND '</Workbook>' TO IT_XML.

DATA: window_title TYPE string,

fullpath TYPE string,

path TYPE string,

user_action TYPE i,

default_extension TYPE string,

default_file_name TYPE string,

file_filter TYPE string,

filename TYPE string,

initialpath TYPE string.

    • File selection

MOVE '.XLS' TO default_extension.

MOVE 'XLS files (.XLS)|.XLS' TO file_filter.

*

*

CALL METHOD cl_gui_frontend_services=>file_save_dialog

EXPORTING

default_extension = default_extension

default_file_name = default_file_name

file_filter = file_filter

initial_directory = initialpath

CHANGING

filename = filename

path = path

fullpath = fullpath

user_action = user_action

EXCEPTIONS

cntl_error = 1

error_no_gui = 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.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = fullpath

filetype = 'ASC'

TABLES

data_tab = it_xml

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Please help

I am giving a sample code how

2 REPLIES 2

Former Member
0 Kudos

Hi Supratik,

Please refer to these two links:

Hope this will resolve your issue.

narsingh1
Explorer
0 Kudos

Hi, I have a similar requirement. Did you get any solution?

Regards,

Narsingh