E-Mail BW Query Results From ABAP Program in HTML Format
E-Mail BW Query Results From ABAP Program in HTML Format
This document may discuss sample coding or other information that does not include SAP official interfaces
and therefore is not supported by SAP. Changes made based on this information are not supported and can
be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods
suggested in this document, and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of
this technical article or code sample, including any liability resulting from incompatibility between the content
within this document and the materials and services offered by SAP. You agree that you will not hold, or seek
to hold, SAP responsible or liable with respect to the content of this document.
Applies To:
BW 3.5
Summary
BW provides a mechanism for sending query results as email using Information Broadcasting. But user
requirements sometime get really innovative & difficult to handle with the standard delivered tools. If you need
the ability to execute a BW query and send the results as a HTML email from an ABAP program, you can use
the following code sample. This has been implemented as a Function Module interface.
The CODE
1. As a first step , create a Function group (if you are not familiar with creating function modules and
function groups check this link
http://help.sap.com/saphelp_nw04/helpdata/en/26/64f623fa8911d386e70000e82011b8/frameset.htm)
2. Copy paste the following code in the top include (global data) of the function group
3. Create the Function Module with parameters as shown in the following screen shots.
Import parameters:
Tables:
4. Copy paste the following code in the Source code section of the Function Module.
FUNCTION y_email_qresults.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(SENDER_ID) TYPE AD_SMTPADR
*" REFERENCE(SUBJECT) TYPE SO_OBJ_DES
*" TABLES
*" QUERY_PARAMS TYPE RRXW3TQUERY
*" RECEPIENTS TYPE BCSY_SMTPA
*" RETURN TYPE TABLE_OF_STRINGS OPTIONAL
*"----------------------------------------------------------------------
DATA: tmp_str TYPE string .
result_content = e_r_page->n_sx_output-string.
CLEAR tmp_str .
CONCATENATE
'<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'
cl_abap_char_utilities=>cr_lf
'<script type="text/javascript"
src="/sap/bw/Mime/BEx/JavaScript/JSBW_C_Std.js"></script>'
cl_abap_char_utilities=>cr_lf
INTO tmp_str .
CLEAR tmp_str .
CLEAR: conlength,conlengths .
REFRESH text .
CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
EXPORTING
text = result_content
TABLES
ftext_tab = text.
TRY.
CLEAR send_request .
send_request = cl_bcs=>create_persistent( ).
CLEAR document .
document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = text
i_length = conlengths
i_subject = subject ).
CLEAR sender .
sender = cl_cam_address_bcs=>create_internet_address( sender_id ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
CLEAR wa_rec .
recipient = cl_cam_address_bcs=>create_internet_address(
wa_rec ).
COMMIT WORK.
EXIT.
ENDTRY.
ELSE .
ENDFUNCTION.
Import Parameters:
Tables parameter:
Receipients table:
Query_params table
Author Bio
Durairaj Athavan Raja works as Business System Analyst with Atos Origin Middle East and has
been involved in SAP development for over 8 years. He is a big fan of SDN.