Hi,
Solved.
I tried with below code.
if gt_useremail[] is not initial.
**Convert string to xstring
call function 'HR_KR_STRING_TO_XSTRING'
EXPORTING
unicode_string = lv_data_string
IMPORTING
xstring_stream = lv_xstring
EXCEPTIONS
invalid_codepage = 1
invalid_string = 2
others = 3.
if sy-subrc <> 0.
if sy-subrc = 1 .
elseif sy-subrc = 2 .
write:/ 'invalid string ' .
endif.
endif.
***Xstring to binary
call function 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring
TABLES
binary_tab = lit_binary_content.
**add attachment
clear l_attsubject .
l_attsubject = 'Export Sales'.
* Create Attachment
try.
lo_document->add_attachment( exporting
i_attachment_type = 'XLS'
i_attachment_subject =
l_attsubject
i_att_content_hex =
lit_binary_content ).
catch CX_document_BCS into lr_docu_exc.
endtry.
try.
lo_sender = cl_sapuser_bcs=>create( sy-uname ).
lo_send_request->set_sender(
exporting
i_sender = lo_sender ).
catch CX_SEND_REQ_BCS into lr_send_exc.
catch CX_ADDRESS_BCS into lr_addr_exc.
endtry.
**Set recipient
loop at gt_useremail into gw_useremail.
try.
lo_recipient = cl_cam_address_bcs=>create_internet_address(
gw_useremail-emailid ).
catch CX_ADDRESS_BCS into lr_addr_exc.
endtry.
try.
lo_send_request->add_recipient(
exporting
i_recipient = lo_recipient
i_express = 'X' ).
* catch CX_SEND_REQ_BCS into lr_send_exc.
call method lo_send_request->set_send_immediately
EXPORTING
i_send_immediately = 'X'.
catch CX_SEND_REQ_BCS into lr_send_exc.
ENDTRY.
endloop.
** Send email
try.
lo_send_request->send(
exporting
i_with_error_screen = 'X' ).
commit work.
if sy-subrc = 0. "mail sent successfully
write :/ 'Mail sent successfully'.
endif.
catch CX_SEND_REQ_BCS into lr_send_exc.
endtry.
* CLEAR : lo_recipient.
* commit work.
endif.
Regards
Amol Khochare