Vous êtes sur la page 1sur 3

Sending Mail using Oo (3) - Result of a report


Sending Mail using Oo (3) - Result of a report
created by Frédéric Girod on Jun 3, 2013 11:14 AM, last modified by Frédéric Girod on Jun 3, 2013 11:17 AM

Version 2

A simple example how to send the result of a report, in HTML, thru a mail.      

DATA : obj_mime_helper   TYPE REF TO cl_gbt_multirelated_service ,         obj_bcs           TYPE REF TO cl_bcs ,         obj_doc_bcs       TYPE REF TO cl_document_bcs ,         obj_recipient     TYPE REF TO if_recipient_bcs ,         w_status          TYPE bcs_rqst ,         is_soli           TYPE soli ,         it_soli           TYPE TABLE OF soli ,         it_html           TYPE html_table ,         it_listobj        TYPE table_abaplist ,

        obj_sender        TYPE REF TO if_sender_bcs .

    We used only two additional data : IT_LISTOBJ (the result of a report) IT_HTML (the result of the report in HTML)        

Selection Screen
PARAMETERS p_prog TYPE syrepid .

    We only asked the report name, we supposed it's a simple report, not a report with a dynpro. Maybe you could ask for a transaction and find the report behind the transaction code.        

Call the report and catch the result
* Perform the program and export the restult in memory.    SUBMIT (p_prog ) VIA SELECTION-SCREEN AND RETURN EXPORTING LIST TO MEMORY.

  This command will call the selection screen of the report, and get the result in memory, you will not see the result in the screen.    
* Catch the memory of the report result.    CALL FUNCTION 'LIST_FROM_MEMORY'      TABLES        listobject = it_listobj      EXCEPTIONS        not_found  = 1        OTHERS      = 2.

  This function will put the memory into an internal table : IT_LISTOBJ  
* Transform the report result in HTML format    CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'      TABLES        html       = it_html        listobject = it_listobj . * Put the HTML into the table of the mail.    it_soli = it_html .

Sending Mail using Oo (3) . SE93.    obj_bcs->send ( ).    CALL METHOD obj_bcs . To get the report corresponding of this transaction you can used the trans.girod@scn.Result of a report   This function will convert the memory into HTML code.      ROLLBACK WORK . I used the transaction VA05n. * Set the subject of the mail.sap.         Result   For the example. * Set the HTML body of the mail    CALL METHOD obj_mime_helper ->set_main_html      EXPORTING        content      = it_soli        filename    = ''        description = 'Hello world' .         2/3 Send the mail   This part is identical of the previous program   * Create the main object of the mail. * Commit Work.    ENDIF.com' ).    obj_bcs = cl_bcs => create_persistent( ). * Send the mail.    CREATE OBJECT obj_mime_helper . * Set the email address    obj_recipient = cl_cam_address_bcs =>create_internet_address(                      i_address_string =   'frederic.    MOVE 'N' TO w_status .    IF sy-subrc EQ space .      COMMIT WORK AND WAIT .> set_status_attributes      EXPORTING        i_requested_status = w_status.    obj_doc_bcs = cl_document_bcs =>create_from_multirelated(                    i_subject           = 'Mail example'                    i_importance        = '9'                " 1 / 5 / 9                    i_multirel_service = obj_mime_helper ). Here it's the report : SD_SALES_ORDERS_VIEW   Start the program :   The standard selection screen of the transaction VA05n   .    ELSE. * Change the status.    obj_bcs->set_document (               i_document = obj_doc_bcs ).    obj_bcs->add_recipient (               i_recipient = obj_recipient ).

Result of a report 3/3   When we execute the program nothing appends.Sending Mail using Oo (3) . and we have to leave the report to send the mail. to check it was used by the program :     Fred .   The mail looks like :     I have created an display variant.