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: 

CL_DOCUMENT_BCS :Mails to Distribution List

Former Member
0 Kudos

Hi ,

I have to send emails to Distribution List using CL_DOCUMENT_BCS and display the Distribution list name as the sender. Is it possible?

Please provide some example code snippets.

Thanks & regards,

Lekshmi

2 REPLIES 2

Former Member
0 Kudos

you can use this class for your requirement and find appropriate method and do the coding

sample..code its may help you

DATA: send_request       TYPE REF TO cl_bcs.
  DATA: document           TYPE REF TO cl_document_bcs.
  DATA: sender             TYPE REF TO cl_sapuser_bcs.
  DATA: recipient          TYPE REF TO if_recipient_bcs.
  DATA: exception_info     TYPE REF TO if_os_exception_info,
        bcs_exception      TYPE REF TO cx_bcs.

*----------------------------------------------------------------------
*
* INTERNAL TABLES
*
*----------------------------------------------------------------------
*
  DATA: l_mailtext TYPE soli_tab.
  DATA: l_mailhex  TYPE solix_tab.
  DATA: iaddsmtp   TYPE bapiadsmtp OCCURS 0 WITH HEADER LINE.
  DATA: ireturn    TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

*----------------------------------------------------------------------
*
* VARIABLES
*
*----------------------------------------------------------------------
*
  DATA: mail_line  LIKE LINE OF l_mailtext.
  DATA: mailx_line LIKE LINE OF l_mailhex.
  DATA: bapiadsmtp         TYPE bapiadsmtp.

*----------------------------------------------------------------------
*
* CONSTANTS
*
*----------------------------------------------------------------------
*
  CONSTANTS:
    anydomain(12) TYPE c VALUE '@anydomain'.

  CLASS cl_cam_address_bcs DEFINITION LOAD.
  CLASS cl_abap_char_utilities DEFINITION LOAD.

  TRY.
* Create persistent send request
      send_request = cl_bcs=>create_persistent( ).

      DATA: first(1) TYPE c.
      CLEAR first.
      DATA: documents_line LIKE LINE OF documents.

      LOOP AT documents INTO documents_line.
        IF first IS INITIAL.
          MOVE 'X' TO first.
* Build the Main Document
          IF documents_line-content_hex[] IS INITIAL.
            document = cl_document_bcs=>create_document(
                                i_type    = documents_line-type
                                i_text    = documents_line-
content_text
                                i_subject = documents_line-subject ).
          ELSE.
            document = cl_document_bcs=>create_document(
                                i_type    = documents_line-type
                                i_hex     = documents_line-content_hex
                                i_subject = documents_line-subject ).
          ENDIF.
        ELSE.
          IF documents_line-content_hex[] IS INITIAL.
* Add Attachment
            CALL METHOD document->add_attachment
              EXPORTING
                i_attachment_type    = documents_line-type
                i_attachment_subject = documents_line-subject
                i_att_content_text   = documents_line-content_text.
          ELSE.
            CALL METHOD document->add_attachment
              EXPORTING
                i_attachment_type    = documents_line-type
                i_attachment_subject = documents_line-subject
                i_att_content_hex    = documents_line-content_hex.
          ENDIF.
        ENDIF.
      ENDLOOP.


* Add document to send request
      CALL METHOD send_request->set_document( document ).

* Get sender object
      sender = cl_sapuser_bcs=>create( sy-uname ).

* Add sender
      CALL METHOD send_request->set_sender
        EXPORTING
          i_sender = sender.


      DATA: recipients_line LIKE LINE OF recipients.
      LOOP AT recipients INTO recipients_line.
        IF recipients_line-c_address IS INITIAL.
* Create recipient
          CLEAR iaddsmtp.
          REFRESH iaddsmtp.
          CLEAR bapiadsmtp.
          CLEAR recipient.
* Read the E-Mail address for the user
          CALL FUNCTION 'BAPI_USER_GET_DETAIL'
            EXPORTING
              username = recipients_line-uname
            TABLES
              return   = ireturn
              addsmtp  = iaddsmtp.
          LOOP AT iaddsmtp WHERE std_no = 'X'.
            CLEAR bapiadsmtp.
            MOVE iaddsmtp TO bapiadsmtp.
          ENDLOOP.
* If no E-mail address was found, create one.
          IF bapiadsmtp-e_mail = ''.
            CONCATENATE recipients_line-uname
                        anydomain
                   INTO recipients_line-c_address.
          ELSE.
            MOVE bapiadsmtp-e_mail TO recipients_line-c_address.
          ENDIF.
        ENDIF.

        recipient = cl_cam_address_bcs=>create_internet_address(
recipients_line-c_address ).
* Add recipient with its respective attributes to send request
        CALL METHOD send_request->add_recipient
          EXPORTING
            i_recipient  = recipient
            i_express    = recipients_line-i_express
            i_copy       = recipients_line-i_copy
            i_blind_copy = recipients_line-i_blind_copy
            i_no_forward = recipients_line-i_no_foward.

      ENDLOOP.

* Set that you don't need a Return Status E-mail
      DATA: status_mail TYPE bcs_stml.
      status_mail = requested_status.
      CALL METHOD send_request->set_status_attributes
        EXPORTING
          i_requested_status = requested_status
          i_status_mail      = status_mail.

* set send immediately flag
      send_request->set_send_immediately( 'X' ).

* Send document
      CALL METHOD send_request->send( ).

      COMMIT WORK.

    CATCH cx_bcs INTO bcs_exception.
      RAISE EXCEPTION bcs_exception.

  ENDTRY.

aditya_aghor
Explorer
0 Kudos

hi Lek,

Have a look at reports in se38 which start with BCS_* . Normally you can only display the existing SAP users in the sender field. As a work around this you can code as following


*      replace sender_id by distribulistion list id
      sender = cl_cam_address_bcs=>create_internet_address( sender_id ). 
      call method send_request->set_sender
        exporting
          i_sender = sender.

Hope this helps