Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

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

$
0
0

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

 

 

 

Data

 

 

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.


 

This function will convert the memory into HTML code.

 

 

 

 

Send the mail

 

This part is identical of the previous program

 

* Create the main object of the mail.
   CREATE OBJECT obj_mime_helper.


* Set the HTML body of the mail
   CALL METHOD obj_mime_helper->set_main_html
     EXPORTING
       content     = it_soli
       filename    = ''
       description = 'Hello world'.


* Set the subject of the mail.
   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 ).
   obj_bcs = cl_bcs=>create_persistent( ).
   obj_bcs->set_document(
              i_document = obj_doc_bcs ).


* Set the email address
   obj_recipient = cl_cam_address_bcs=>create_internet_address(
                     i_address_string 'frederic.girod@scn.sap.com' ).
   obj_bcs->add_recipient(
              i_recipient = obj_recipient ).


* Change the status.
   MOVE 'N' TO w_status.
   CALL METHOD obj_bcs->set_status_attributes
     EXPORTING
       i_requested_status = w_status.


* Send the mail.
   obj_bcs->send( ).



* Commit Work.
   IF sy-subrc EQ space.
     COMMIT WORK AND WAIT.
   ELSE.
     ROLLBACK WORK.
   ENDIF.

 

 

 

 

Result

 

For the example, I used the transaction VA05n. To get the report corresponding of this transaction you can used the trans. SE93.

Here it's the report : SD_SALES_ORDERS_VIEW

 

Start the program :

report_1.png

 

The standard selection screen of the transaction VA05n

 

report_2.png

 

When we execute the program nothing appends, and we have to leave the report to send the mail.

 

The mail looks like :

 

Capture d’écran 2013-06-03 à 10.59.26.png

 

I have created an display variant, to check it was used by the program :

Capture d’écran 2013-06-03 à 10.59.58.png

 

 

Fred


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>