Advertising:

Create e-mail with classic classes and methods

From SAP Knowledge Base
Revision as of 15:11, 21 December 2024 by Unirab (talk | contribs)

Kategorie:Codeschnipsel

 
 DATA: send_request       TYPE REF TO cl_bcs,
       document           TYPE REF TO cl_document_bcs,
       sender             TYPE REF TO cl_sapuser_bcs,
       sender2            TYPE REF TO if_sender_bcs,
       receiver           TYPE REF TO if_recipient_bcs,
       mail_text_tab      TYPE soli_tab,
       subject            TYPE so_obj_des,
       distribution_list  TYPE TABLE OF sodlienti1,
       recipient          TYPE adr6-smtp_addr,
       size               TYPE so_obj_len,
       binary_content     TYPE solix_tab,
       data_tab_as_string TYPE string,
       att_name           TYPE sood-objdes.

 go_send_request = cl_bcs=>create_persistent( ).
 
 CONCATENATE 'Subject' sy-datum INTO subject SEPARATED BY space.
 
 APPEND 'Mail text in e-mail' TO mail_text_tab.
 
 document = cl_document_bcs=>create_document( i_type    = 'RAW'
                                              i_text    = mail_text_tab
                                              i_subject = subject ).
 
 "Attachment: tab data as string to .xls
 "new column: CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
 "new row: CL_ABAP_CHAR_UTILITIES=>CR_LF
 
 cl_bcs_convert=>string_to_solix( EXPORTING iv_string   = data_tab_as_string
                                            iv_codepage = '4103' "suitable for MS Excel, leave empty
                                            iv_add_bom  = 'X' "for other doc types
                                  IMPORTING et_solix  = binary_content
                                            ev_size   = size ).
        
 go_document->add_attachment( EXPORTING i_attachment_type = 'xls'
                                        i_attachment_subject  = att_name             
                                        i_attachment_size     = size    
                                        i_att_content_hex     = binary_content ).
    
 go_send_request->set_document( go_document ).
 
 "Add sender variant 1
 sender = cl_sapuser_bcs=>create( sy-uname ).
 "Add sender variant 2
 sender2 = cl_cam_address_bcs=>create_internet_address( i_address_string = sender ).
 
 send_request->set_sender( go_sender ). "send_request->set_sender( sender2 )
 
 "Add receivers variant 1:
 LOOP AT distribution_list INTO DATA(recpt).
  recipient = recpt-full_name.
  receiver = cl_cam_address_bcs=>create_internet_address( recipient ).
  send_request->add_recipient( receiver ).
 ENDLOOP.
  "Add recievers variant 2:
 receiver = cl_distributionlist_bcs=>getu_persistent( i_dliname = distributionlist 
                                                      i_private = abap_false ).
 send_request->add_recipient( receiver ).
 
 send_request->send( ).
 
 COMMIT WORK.

This is a wiki created in the spare time of a private person working in the SAP ERP area. The aim is to collect knowledge for the own use. The wiki is maintained to the best of knowledge and belief.
All products shown, including in form of screenshots, belong to SAP SE. Their trademarks are, among others: SAP®,ABAP®,SAP Fiori®,SAP HANA®,SAP NetWeaver®,SAP® R/3®,SAP S/4HANA®,SAP S/4HANA® Cloud