fetch the data from table and send an email in ABAP
Send an email in abap.
REPORT ZAJAY_EF_ZSTU.
tables:zstu.
data: maildata LIKE sodocchgi1,
mailtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
mailrec LIKE somlrec90 OCCURS 0 WITH HEADER LINE,
it_zstu type table of zstu WITH HEADER LINE,
wa_zstu type zstu.
START-OF-SELECTION.
clear:maildata,mailtxt,mailrec.
REFRESH:mailtxt,mailrec.
select-OPTIONS : s_id for zstu-zstu_id.
SELECT * from zstu into TABLE it_zstu where zstu_id in s_id.
sort it_zstu by zstu_id.
maildata-obj_descr = | Employee details |.
mailtxt = '<!DOCTYPE html>'.
append mailtxt.
mailtxt = '<html lang="en">'.
append mailtxt.
mailtxt = '<head>'.
append mailtxt.
mailtxt = '<title>Email Functionality</title>'.
append mailtxt.
* mailtxt = ' <style>'.
* append mailtxt.
*
* mailtxt = 'table, th, td { border: 1px solid black;border-collapse: collapse} h2{ color:blue} '.
* APPEND mailtxt.
* mailtxt = '</style>'.
* append mailtxt.
mailtxt = '<style>table, th, td {border:1px solid black; border-collapse:collapse}</style>'.
APPEND mailtxt.
mailtxt = '</head>'.
append mailtxt.
mailtxt = '<body>'.
append mailtxt.
mailtxt = '<h2> Details of ABC College Students. </h2>'.
append mailtxt.
mailtxt = '<table>'." style:"border-style: solid">'.
append mailtxt.
mailtxt = '<tr>'.
append mailtxt.
mailtxt = '<th style = "border:1px solid black; border-collapse:collapse;">Student ID</th>'.
append mailtxt.
mailtxt = '<th style = "border:1px solid black; border-collapse:collapse;">Student Name</th>'.
append mailtxt.
mailtxt = '<th style = "border:1px solid black; border-collapse:collapse;">Student Dept</th>'.
append mailtxt.
mailtxt = '<th style = "border:1px solid black; border-collapse:collapse;">student Fee</th>'.
append mailtxt.
mailtxt = '</tr>'.
append mailtxt.
LOOP AT it_zstu into wa_zstu.
mailtxt = '<tr>'.
append mailtxt.
mailtxt-line = | <td style = "border:1px solid black; border-collapse:collapse;">{ wa_zstu-zstu_id }</td> |.
append mailtxt.
mailtxt-line = | <td style = "border:1px solid black; border-collapse:collapse;">{ wa_zstu-zstu_Name }</td> | .
append mailtxt.
mailtxt-line = | <td style = "border:1px solid black; border-collapse:collapse;">{ wa_zstu-zstu_Dep }</td> | .
append mailtxt.
mailtxt-line = | <td style = "border:1px solid black; border-collapse:collapse;">{ wa_zstu-zstu_fee }</td> | .
append mailtxt.
mailtxt = '</tr>'.
append mailtxt.
ENDLOOP.
mailtxt = '</table>'.
append mailtxt.
mailtxt = '</body>'.
append mailtxt.
mailtxt = '</html>'.
append mailtxt.
mailrec-receiver = 'abc@gmail.com'.
mailrec-rec_type = 'U'.
APPEND mailrec.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = maildata
DOCUMENT_TYPE = 'HTM'
* PUT_IN_OUTBOX = ' '
* COMMIT_WORK = ' '
* IP_ENCRYPT =
* IP_SIGN =
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
tables
OBJECT_HEADER = mailtxt
OBJECT_CONTENT = mailtxt
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
receivers = mailrec
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8
.
IF sy-subrc <> 0.
MESSAGE 'Mail not sent' TYPE 'E'.
ELSE.
WRITE:'Mail sent successfully'.
ENDIF.
COMMIT WORK.
Input
Output
* check in sost t code.
* select email and click on display.
Comments
Post a Comment