Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add email to report?

Former Member
0 Kudos

Does anyone know how to add an additional email address to a variant? I have a report that gets generated and send out daily just wants to add an additional email to that report.

Any comments or suggestion is highly appreciated.

6 REPLIES 6

p291102
Active Contributor
0 Kudos

Send mail via SAP ABAP Code

* Data Declarations

DATA: LT_MAILSUBJECT     TYPE SODOCCHGI1.

DATA: LT_MAILRECIPIENTS  TYPE STANDARD TABLE OF SOMLREC90 WITH HEADER LINE.

DATA: LT_MAILTXT         TYPE STANDARD TABLE OF SOLI      WITH HEADER LINE.

* Recipients

LT_MAILRECIPIENTS-REC_TYPE  = 'U'.

LT_MAILRECIPIENTS-RECEIVER = 'testl@gmail.com'.

APPEND LT_MAILRECIPIENTS .

CLEAR LT_MAILRECIPIENTS .

* Subject.

LT_MAILSUBJECT-OBJ_NAME = 'TEST'.

LT_MAILSUBJECT-OBJ_LANGU = SY-LANGU.

LT_MAILSUBJECT-OBJ_DESCR = 'Mail Subject'.

* Mail Contents

LT_MAILTXT = 'This is a test mail'.

APPEND LT_MAILTXT. CLEAR LT_MAILTXT.

* Send Mail

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

  EXPORTING

    DOCUMENT_DATA              = LT_MAILSUBJECT

  TABLES

    OBJECT_CONTENT             = LT_MAILTXT

    RECEIVERS                  = LT_MAILRECIPIENTS

  EXCEPTIONS

    TOO_MANY_RECEIVERS         = 1

    DOCUMENT_NOT_SENT          = 2

    DOCUMENT_TYPE_NOT_EXIST    = 3

    OPERATION_NO_AUTHORIZATION = 4

    PARAMETER_ERROR            = 5

    X_ERROR                    = 6

    ENQUEUE_ERROR              = 7

    OTHERS                     = 8.

IF SY-SUBRC EQ 0.

  COMMIT WORK.

*   Push mail out from SAP outbox

  SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.

ENDIF.


Message was edited by: Matthew Billingham

Former Member
0 Kudos

Hello John,

First identify how the email IDs are added to the existing program. If it is hard-coded inside the program, add your new email ID in the same way or if it is maintained as a Distribution list, then get the distribution list name and goto the Transaction SBWP -> click on the button 'Distribution lists' -> enter the distribution list name and click on 'Find'. From the result which is shown in the bottom you can edit the list by adding the new Email ID, this will result in sending email to the additional ID from the next cycle.

Let me know if you have any other questions.

Thanks

Nivash

former_member209120
Active Contributor
0 Kudos

Hi John Jay

First debug your code, and find, where you are getting mail address (from table or distribution list etc..)

According that change mail address....

First confirm where you are getting this address.

Former Member
0 Kudos

Hi,

First thing you have to do is to debug your code and find from where your email address is added. Or else try the below logic.

DATA: o_bcs           TYPE REF TO cl_bcs,
       o_send_req      TYPE REF TO cl_send_request_bcs,
       o_doc_bcs       TYPE REF TO cl_document_bcs,
       o_recpnt        TYPE REF TO if_recipient_bcs,
       o_bcs_excp      TYPE REF TO cx_bcs.

DATA:  t_msg           TYPE STANDARD TABLE OF solisti1.

DATA: v_int_address   TYPE ad_smtpadr,       
       v_sent          TYPE os_boolean,       
       v_rec_wo_err    TYPE bcsy_re,          
       v_orig          TYPE bcsy_ercp,        
       v_notif_desc    TYPE zaplx_tno_descrp
       v_objdesc       TYPE so_obj_des.

     TRY .

         o_bcs       = cl_bcs=>create_persistent( ).
         o_send_req  = o_bcs->send_request.
         CALL METHOD o_send_req->set_link_to_outbox( abap_true ).

         REFRESH t_msg.

         SET LANGUAGE sy-langu.
        
           "Message body
         x_msg-line = 'Hi,'.
         APPEND x_msg TO t_msg.

         x_msg-line = 'This is the message body'.
         APPEND x_msg TO t_msg.     

         o_doc_bcs = cl_document_bcs=>create_document(
         i_type    = c_doc_type
         i_text    = t_msg
         i_subject = v_objdesc  ).
         CALL METHOD o_bcs->set_document( o_doc_bcs ).

        "Add email address from internal table
         LOOP AT t_email INTO x_email.

           "Translate to lower case
           TRANSLATE x_email-address TO LOWER CASE.

           "Passing the email address.
           CLEAR o_recpnt.

           v_int_address = x_email-address.

           o_recpnt = cl_cam_address_bcs=>create_internet_address(
           v_int_address ).

           CALL METHOD o_bcs->add_recipient
             EXPORTING
               i_recipient = o_recpnt
               i_express   = abap_true.

         ENDLOOP.

         "Send email
         IF o_recpnt IS NOT INITIAL .

           CALL METHOD o_bcs->send_without_dialog
             IMPORTING
               e_sent_to_all           = v_sent
               e_recipients_with_error = v_rec_wo_err
               e_orig_recs_with_error  = v_orig.

         ENDIF.

       CATCH cx_bcs INTO o_bcs_excp.

         RAISE no_mail_send

     ENDTRY.

Regards,

Riju Thomas.

former_member219162
Contributor
0 Kudos

Hello John,

Look at the SAP Program "BCS_EXAMPLE_7". This program is a sample program by SAP where email is sent and along with it an attached excel file is sent. For your purpose, you can ignore the excel sheet attachment. But you would get an overall understanding of how email address can be put in a selection screen and then saved as a variant. So when your job runs with the variant, additional email would be sent. In fact, you can create a Distribution list in this way. Reead the program comments and you will get it.

Thanks.

VijayaKrishnaG
Active Contributor
0 Kudos

This message was moderated.