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: 

Create a program to send email notification for the PO data from ekpo table

karthikreddy8174
Explorer
0 Kudos

How to create a program that send email notification for the PO from ekpo table

Pull the all PO data and line item data

which are passed particular due date ,let's say 5 days

5 REPLIES 5

nikola_moraca
Explorer
0 Kudos

1. You need to retrieve data you need from EKPO table using SELECT statement.

Usually you will use internal table to store it in runtime.

2. You can use this code snip for sending mail and check that mail server is enabled and use ti_lines parameter to store your data and send it over email.

TYPES: BEGIN OF ty_lines,
         line TYPE char255,
       END OF ty_lines.
DATA:  ti_lines TYPE STANDARD TABLE OF ty_lines,
       wa_lines TYPE ty_lines.
DATA:  title TYPE string.
* APPEND LINES TO ti_lines (body) and add a title (subject)
CALL FUNCTION 'EFG_GEN_SEND_EMAIL'
    EXPORTING
      i_title              = title
      i_sender             = <sender_email>
      i_recipient          = <receiver_email>
      i_flg_commit         = 'X'
      i_flg_send_immediately = 'X'
    TABLES
      i_tab_lines            = ti_lines
    EXCEPTIONS
      not_qualified          = 1
      failed                 = 2
      OTHERS                 = 3.

raymond_giuseppi
Active Contributor
0 Kudos

Where are you stuck

  • Extracting data of recent PO
  • Sending a mail with attachment

karthikreddy8174
Explorer
0 Kudos

*&---------------------------------------------------------------------*

*& 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.

Sandra_Rossi
Active Contributor
0 Kudos

karthikreddy8174 Excuse-me but why do you paste this piece of code? Do you have any question?

xiswanto
Active Participant

You have the code (perhaps you copy the sample code from another program?), then simply changes the data source so that your mail body / attachment data source originated from the table you wanted instead of the current one, Unless you are expecting us to write the code for you?