*&---------------------------------------------------------------------*
*& Report ZRPMM_PO
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
report zrpmm_po no standard page heading.
tables eket.
select-options so_eindt for eket-eindt.
*-----------------------------------------
*DATA: LV_VALUE
*PREPARE MAIL OBJECT
data: lo_send_request type ref to cl_bcs. "VALUE IS INITIAL.
class cl_bcs definition load.
data: lo_document type ref to cl_document_bcs . "VALUE IS INITIAL. "DOCUMENT OBJECT
data : it_text type bcsy_text. "TABLE FOR BODY
data : wa_text like line of it_text. "WORK AREA FOR MESSAGE BODY
data: lo_sender type ref to if_sender_bcs. "VALUE IS INITIAL. "SENDER
data: lo_recipient type ref to if_recipient_bcs." VALUE IS INITIAL. "RECIPIENT
**SELECTION SCREEN
parameters : p_email type adr6-smtp_addr. "EMAIL INPUT
parameters: p_sub type char50. "EMAIL SUBJECT
parameters : p_send as checkbox. "SEND IMMEDIATELY FLAG
***ATTACHMENT DATA
data : lv_string type string,
lv_data_string type string,
lv_xstring type xstring.
data: lit_binary_content type solix_tab,
l_attsubject type sood-objdes.
start-of-selection.
"CREATE OBJECT FOR SENDING EMAIL
lo_send_request = cl_bcs=>create_persistent( ).
*****************************START OF BOCY***************************************************
"MESSAGE BODY
wa_text-line = '<HTML><BODY>'.
append wa_text to it_text.
wa_text-line = 'DEAR RECEPIENT,'.
append wa_text to it_text.
wa_text-line = '<BR></BR>'.
append wa_text to it_text.
wa_text-line = 'PLEASE FIND THE PO DETAILS AS REQUESTED IN THE ATTACHMENT.'.
append wa_text to it_text.
wa_text-line = '<BR></BR>'.
append wa_text to it_text.
wa_text-line = 'THANKS & REGARDS , SENDER'.
append wa_text to it_text.
wa_text-line = '</BODY></HTML>'.
append wa_text to it_text.
clear wa_text.
*************************END OF BODY*******************************************************
lo_document = cl_document_bcs=>create_document(
exporting "CREATE DOCUMENT
i_type = 'HTM' "TYPE OF DOCUMENT HTM, TXT ETC
i_text = it_text "EMAIL BODY INTERNAL TABLE
i_subject = p_sub ). "EMAIL SUBJECT HERE P_SUB INPUT PARAMETER
* PASS THE DOCUMENT TO SEND REQUEST
lo_send_request->set_document( lo_document ).
***SET ATTACHMENT
select ebeln,
ebelp,
eindt from eket
into table @data(gt_eket)
where eindt in @so_eindt.
*
loop at gt_eket into data(gs_eket).
concatenate gs_eket-ebeln gs_eket-ebelp gs_eket-eindt into lv_string separated by
cl_abap_char_utilities=>horizontal_tab.
concatenate lv_data_string lv_string into lv_data_string separated by cl_abap_char_utilities=>newline.
endloop.
***CONVERT STRING TO XSTRING
call function 'HR_KR_STRING_TO_XSTRING'
exporting
* CODEPAGE_TO = '8300'
unicode_string = lv_data_string
* OUT_LEN =
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 .
concatenate 'INNERCIRCLE_EXCEL' sy-datum into l_attsubject.
* 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 data(lx_document_bcs).
endtry.
try.
lo_sender = cl_sapuser_bcs=>create( sy-uname ). "SENDER IS THE LOGGED IN USER
* SET SENDER TO SEND REQUEST
lo_send_request->set_sender(
exporting
i_sender = lo_sender ).
* CATCH CX_ADDRESS_BCS.
****CATCH EXCEPTION HERE
endtry.
**SET RECIPIENT
lo_recipient = cl_cam_address_bcs=>create_internet_address( p_email ). "HERE RECIPIENT IS EMAIL INPUT P_EMAIL
try.
lo_send_request->add_recipient(
exporting
i_recipient = lo_recipient
i_express = 'X' ).
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
**CATCH EXCEPTION HERE
endtry.
"SCHEDUEL WHEN YOU WANT SEND THE EMAIL
try.
call method lo_send_request->set_send_immediately
exporting
i_send_immediately = p_send. "HERE SELECTION SCREEN INPUT P_SEND
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
**CATCH EXCEPTION HERE
endtry.
try.
** SEND EMAIL
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 BCS_EXCEPTION .
*CATCH EXCEPTION HERE
endtry.