Professional Documents
Culture Documents
2005 SAP AG
Applies To:
BW 3.5
Summary
Hope you would have seen the code sample E-mail BW Query Results From ABAP Program in HTML
Format, continuing with the email code samples, presenting here a code sample to send BW workbook as
attachment to emails. This has also been implemented as a Function Module interface.
By: Durairaj Athavan Raja
Company: Atos Origin Middle East
Date: 4th April 2006
2005 SAP AG
send_request
TYPE REF TO cl_bcs.
text
TYPE bcsy_text.
document
TYPE REF TO cl_document_bcs.
sender
TYPE REF TO if_sender_bcs.
recipient
TYPE REF TO if_recipient_bcs.
bcs_exception
TYPE REF TO cx_bcs.
sent_to_all
TYPE os_boolean.
conlength TYPE i ,
conlengths TYPE so_obj_len ,
result_content TYPE string .
DATA: e_r_page TYPE REF TO cl_rsr_www_page.
data: content_length
TYPE
w3param-cont_len ,
content_type TYPE
w3param-cont_type,
return_code
TYPE
w3param-ret_code .
data: html type standard table of w3html .
data: server type string ,
port type string .
data: wa_rec type ad_smtpadr .
data: bcs_message type string .
2005 SAP AG
Tables:
2005 SAP AG
4. Copy paste the following code in the Source code section of the Function Module.
FUNCTION y_email_bwwb.
*"---------------------------------------------------------------------*"*"Local Interface:
*" IMPORTING
*"
REFERENCE(SENDER_ID) TYPE AD_SMTPADR
*"
REFERENCE(SUBJECT) TYPE SO_OBJ_DES
*"
REFERENCE(WORKBOOKID) TYPE RSSGUID25
*" TABLES
*"
RECEPIENTS TYPE BCSY_SMTPA
*"
RETURN TYPE TABLE_OF_STRINGS OPTIONAL
*"---------------------------------------------------------------------DATA: binary_content
TYPE solix_tab.
DATA: xl_content TYPE xstring .
DATA: atta_sub TYPE sood-objdes .
DATA: wb TYPE rsrwbindext .
DATA: wb_tab TYPE STANDARD TABLE OF rsrwbstore,
wb_line LIKE LINE OF wb_tab ,
file_data TYPE string ,
output TYPE string .
IF NOT recepients[] IS INITIAL .
CLEAR wb .
SELECT SINGLE * FROM rsrwbindext INTO wb
WHERE workbookid = workbookid AND objvers = 'A' AND langu = 'E' .
IF sy-subrc NE 0.
APPEND 'Work book not found' TO return .
ELSE .
CLEAR: wb_tab, wb_line , atta_sub .
MOVE: wb-title TO atta_sub .
REFRESH wb_tab .
SELECT * FROM rsrwbstore INTO TABLE wb_tab
WHERE workbookid = wb-workbookid.
CLEAR:file_data, output, wb_line .
LOOP AT wb_tab INTO wb_line.
2005 SAP AG
TRY.
CLEAR send_request .
send_request = cl_bcs=>create_persistent( ).
2005 SAP AG
recipient = cl_cam_address_bcs=>create_internet_address(
wa_rec ).
*
2005 SAP AG
Tables parameter:
Receipients table:
2005 SAP AG
2005 SAP AG
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.
2005 SAP AG
10