E-mail BW Workbook as Attachment- ABAP.doc

March 23, 2018 | Author: Ravindra Babu | Category: Email, Software Engineering, Computer Programming, Software, Areas Of Computer Science


Comments



Description

E-mail BW Workbook as AttachmentFrom ABAP Program SDN Community Contribution (This is not an official SAP document.) Disclaimer & Liability Notice 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. © 2005 SAP AG The SAP Developer Network: http://sdn.sap.com 1 5 Summary Hope you would have seen the code sample E-mail BW Query Results From ABAP Program in HTML Format.com 2 . This has also been implemented as a Function Module interface. continuing with the email code samples.sap. By: Durairaj Athavan Raja Company: Atos Origin Middle East Date: 4th April 2006 © 2005 SAP AG The SAP Developer Network: http://sdn. presenting here a code sample to send BW workbook as attachment to emails.E-mail BW Workbook as Attachment From ABAP Program Applies To: BW 3. data: server type string .sap. content_type TYPE w3param-cont_type. text TYPE bcsy_text. create a Function group (if you are not familiar with creating function modules and function groups check this link http://help. document TYPE REF TO cl_document_bcs. bcs_exception TYPE REF TO cx_bcs.htm) 2. result_content TYPE string .sap. Copy paste the following code in the top include (global data) of the function group DATA: DATA: DATA: DATA: DATA: DATA: DATA: DATA: send_request TYPE REF TO cl_bcs. conlengths TYPE so_obj_len . return_code TYPE w3param-ret_code . data: bcs_message type string .com 3 . data: html type standard table of w3html . sent_to_all TYPE os_boolean. As a first step . © 2005 SAP AG The SAP Developer Network: http://sdn. data: wa_rec type ad_smtpadr .com/saphelp_nw04/helpdata/en/26/64f623fa8911d386e70000e82011b8/frameset.E-mail BW Workbook as Attachment From ABAP Program The CODE 1. data: content_length TYPE w3param-cont_len . conlength TYPE i . recipient TYPE REF TO if_recipient_bcs. port type string . sender TYPE REF TO if_sender_bcs. DATA: e_r_page TYPE REF TO cl_rsr_www_page. Import parameters: Tables: © 2005 SAP AG The SAP Developer Network: http://sdn.com 4 . Create the Function Module with parameters as shown in the following screen shots.E-mail BW Workbook as Attachment From ABAP Program 3.sap. file_data TYPE string . CLEAR: wb_tab. DATA: xl_content TYPE xstring . *"---------------------------------------------------------------------*"*"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. IF NOT recepients[] IS INITIAL . output. Copy paste the following code in the Source code section of the Function Module.com 5 . SELECT * FROM rsrwbstore INTO TABLE wb_tab WHERE workbookid = wb-workbookid.E-mail BW Workbook as Attachment From ABAP Program 4. wb_line . DATA: atta_sub TYPE sood-objdes . LOOP AT wb_tab INTO wb_line. APPEND 'Work book not found' TO return . SELECT SINGLE * FROM rsrwbindext INTO wb WHERE workbookid = workbookid AND objvers = 'A' AND langu = 'E' . atta_sub . wb_line LIKE LINE OF wb_tab . CLEAR wb . © 2005 SAP AG The SAP Developer Network: http://sdn. ELSE . DATA: wb_tab TYPE STANDARD TABLE OF rsrwbstore. IF sy-subrc NE 0. FUNCTION y_email_bwwb. CLEAR:file_data. wb_line . output TYPE string . DATA: wb TYPE rsrwbindext . REFRESH wb_tab .sap. MOVE: wb-title TO atta_sub . CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = xl_content TABLES binary_tab = binary_content. file_data = wb_line-clustd. CONCATENATE '<p><font color="#000080">Please find attached your BW workbook. conlengths = conlength . TRY. CALL FUNCTION 'SCMS_STRING_TO_FTEXT' EXPORTING text = result_content TABLES ftext_tab = text.com 6 . CLEAR result_content . send_request = cl_bcs=>create_persistent( ). ENDLOOP. conlength = STRLEN( result_content ) .sap. xl_content = output . CONCATENATE output file_data INTO output. REFRESH binary_content . CLEAR: xl_content .E-mail BW Workbook as Attachment From ABAP Program CLEAR file_data . REFRESH text . © 2005 SAP AG The SAP Developer Network: http://sdn.</font></p>' '<p><font color="#000080">Regards</font></p>' '<p><font color="#000080">BW Team</font></p>' INTO result_content . CLEAR send_request . . CLEAR wa_rec . LOOP AT recepients INTO wa_rec CLEAR recipient . CALL METHOD document->add_attachment EXPORTING i_attachment_type = 'XLS' i_attachment_subject = atta_sub i_att_content_hex = binary_content.sap. document = cl_document_bcs=>create_document( i_type = 'HTM' i_text = text i_length = conlengths i_subject = subject ). recipient = cl_cam_address_bcs=>create_internet_address( wa_rec ). ENDLOOP . CLEAR sender .send document --------------------------------------- © 2005 SAP AG The SAP Developer Network: http://sdn. ---------.E-mail BW Workbook as Attachment From ABAP Program CLEAR document . sender = cl_cam_address_bcs=>create_internet_address( sender_id ). * * add recipient with its respective attributes to send request CALL METHOD send_request->add_recipient EXPORTING i_recipient = recipient i_express = 'X'. CALL METHOD send_request->set_sender EXPORTING i_sender = sender. CALL METHOD send_request->set_send_immediately( 'X' ). CALL METHOD send_request->set_status_attributes EXPORTING i_requested_status = 'E' i_status_mail = 'E'. * add document to send request CALL METHOD send_request->set_document( document ).com 7 . ENDIF . APPEND 'Specify email address for sending' TO return . ENDIF . APPEND bcs_message TO return .sap. bcs_message = bcs_exception->get_text( ).com 8 . COMMIT WORK. CATCH cx_bcs INTO bcs_exception. APPEND 'Mail sent successfully ' TO return . IF sent_to_all = 'X'. Tips on passing parameters: Import Parameters: Tables parameter: Receipients table: © 2005 SAP AG The SAP Developer Network: http://sdn. ELSE . EXIT. ENDFUNCTION. 5. ENDTRY.E-mail BW Workbook as Attachment From ABAP Program CALL METHOD send_request->send( EXPORTING i_with_error_screen = 'X' RECEIVING result = sent_to_all ). ENDIF. sap. © 2005 SAP AG The SAP Developer Network: http://sdn.com 9 .E-mail BW Workbook as Attachment From ABAP Program And the resulting email will look like below. sap.com 10 . © 2005 SAP AG The SAP Developer Network: http://sdn.E-mail BW Workbook as Attachment From ABAP Program 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.
Copyright © 2024 DOKUMEN.SITE Inc.