DATA : lv_path TYPE eps2filnam.
lv_path = 'usr/sap/folder/filewithimage.xls'.
DATA : ls_read_file TYPE string,
ls_all_data TYPE string.
OPEN DATASET lv_path FOR INPUT IN BINARY MODE.
IF sy-subrc IS INITIAL.
DO.
READ DATASET lv_path INTO ls_read_file.
IF sy-subrc IS NOT INITIAL.
EXIT.
ELSE.
CONCATENATE ls_all_data ls_read_file INTO ls_all_data.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET lv_path.
DATA : lt_file_data TYPE soli_tab.
IF ls_all_data IS NOT INITIAL.
lt_file_data = cl_bcs_convert=>string_to_soli( iv_string = ls_all_data ).
ENDIF.
DATA : lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL,
lo_document_exception TYPE REF TO cx_document_bcs VALUE IS INITIAL,
lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL,
lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL,
lv_recipient TYPE adr6-smtp_addr VALUE IS INITIAL,
lv_send_to_all TYPE char1 VALUE IS INITIAL.
CREATE OBJECT lo_document.
TRY.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_subject = 'Email subject'
i_text = 'Email body').
CATCH cx_document_bcs INTO lo_document_exception.
lo_document_exception->get_text( ).
ENDTRY.
IF lt_file_data IS NOT INITIAL.
TRY.
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'xls' " Document Class for Attachment
i_attachment_subject = 'File name' " Attachment Title
i_att_content_text = lt_file_data ). " Content (Text-Like)
CATCH cx_document_bcs INTO lo_document_exception.
lo_document_exception->get_text( ).
ENDTRY.
"pass the docuement to send request
lo_send_request->set_document( lo_document ).
"Create sender
lo_sender = cl_sapuser_bcs=>create( su-uname ).
"set sender
lo_send_request = cl_bcs=>create_persistent( ).
"assign sender
lo_send_request->set_sender( i_sender = lo_sender ).
"Create recipient
lv_recipient = '____@xyz.com'. " recipient address
"assign recipient
lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_recipient ).
"set recipient
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient " Recipient of Message
i_express = 'X' ). " Send As Express Message
"send email
lo_send_request->send(
i_with_error_screen = 'X'
RECEIVING
result = lv_send_to_all ).
COMMIT WORK.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |