Technical Articles
RFC/Program to Send data to MAIL as HTML table format
Hi Experts,
We has Standard RFC in SAP to send an Mail for the created or requested DATA. but the same data when we open into our mail box it will be into Disturbed / Jumbled way.
we can write our won HTML Tag / Table format into our SAP ABAP .
The Data which we want to send as a mail , that we can add it into html open and close tag with with TD and TR tag for the row and column to arrange our data into Table format into a mail body.
NOTE: Full RFC Find the below attachment code.
So Kindly Find the below steps and code.
concatenate ‘QPH Process for notification:’ i_notification ‘has been created.’ into subject separated by space.
doc_data-priority = 1.
doc_data-obj_descr = subject.
***************************************************************************************
wa_contents-line = ‘<html> <body style=”background-color:#FFFFFF;”> <basefont face=”arial, verdana, courier” size=”2″ >’.
append wa_contents to it_contents.
wa_contents-line = ‘<table style=”MARGIN: 10px” bordercolor=”#050211″ width = “100%” border=”1px”> ‘.
append wa_contents to it_contents.
concatenate ‘<tr><td width=”30%”>Vendor No/Name:</td><td>’ lv_final-sellifnr ‘ / ‘ lv_final-name1 into wa_contents.
append wa_contents to it_contents.
concatenate ‘<tr><td width=”30%”>Inspection Lot Number:</td><td>’ lv_final-prueflos into wa_contents.
append wa_contents to it_contents.
concatenate ‘<tr><td width=”30%”>QPH/Notification Number:</td><td>’ lv_final-notno into wa_contents.
append wa_contents to it_contents.
concatenate ‘<tr><td width=”30%”>Plant</td><td>’ lv_final-werk ‘</td></tr>’ into wa_contents.
append wa_contents to it_contents.
concatenate ‘<tr><td width=”30%”>Raised Date</td><td>’ lv_final-ddate ‘ / ‘ lv_final-ddate+6(2) ‘.’
lv_final-ddate+4(2) ‘.’ lv_final-ddate(4) ‘</td></tr>’ into wa_contents.
append wa_contents to it_contents.
concatenate ‘<tr><td width=”30%”>Part No/Name:</td><td>’ lv_final-selmatnr ‘ / ‘ lv_final-ktextmat into wa_contents.
append wa_contents to it_contents.
concatenate ‘<tr><td width=”30%”>Rejection code/Description:</td><td>’ lv_final-rcode ‘ / ‘ lv_final-rtext into wa_contents.
append wa_contents to it_contents.
wa_contents-line = ‘</table> ‘.
append wa_contents to it_contents.
wa_contents-line = ‘</body></html>’.
append wa_contents to it_contents.
function z*******_sendmail.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_INSPECTION) TYPE QPLOS OPTIONAL
*" VALUE(I_NOTIFICATION) TYPE ZQM_NOTNO OPTIONAL
*" VALUE(I_VENDOR) TYPE ELIFN OPTIONAL
*" TABLES
*" ET_RETURN TYPE BAPIRET2_T OPTIONAL
*"----------------------------------------------------------------------
data : doc_data type sodocchgi1,
it_pack type standard table of sopcklsti1,
wa_pack type sopcklsti1,
it_contents type standard table of solisti1,
wa_contents type solisti1,
it_recv type standard table of somlreci1 with header line,
wa_recv type somlreci1,
tab_lines type i.
data: subject(70).
data: lt_final type table of zqm_supt.
data: lv_final type zqm_supt ,
lv_vendor type adrnr ,
lv_mailid type ad_smtpadr .
data : obj_key type swotobjid-objkey,
cls_name type bapibds01-classname.
data : lt_gos type table of bdn_con,
wa_gos type bdn_con.
data : gc_307 type i value '307',
gc_308 type i value '308',
gv_msg_no type i.
clear : lv_final, lv_vendor, lv_mailid , it_contents[] .
if i_notification is not initial.
select single * from zqm_supt
into lv_final
where notno = i_notification
and block = ''.
select single adrnr from lfa1
into lv_vendor
where lifnr = lv_final-sellifnr.
select single smtp_addr from adr6
into lv_mailid
where addrnumber = lv_vendor.
endif.
wa_recv-rec_type = 'U'.
wa_recv-receiver = lv_mailid.
append wa_recv to it_recv.
concatenate 'QPH Process for notification:' i_notification 'has been created.' into subject separated by space.
doc_data-priority = 1.
doc_data-obj_descr = subject.
***************************************************************************************
wa_contents-line = '<html> <body style="background-color:#FFFFFF;"> <basefont face="arial, verdana, courier" size="2" >'.
append wa_contents to it_contents.
wa_contents-line = '<table style="MARGIN: 10px" bordercolor="#050211" width = "100%" border="1px"> '.
append wa_contents to it_contents.
concatenate '<tr><td width="30%">Vendor No/Name:</td><td>' lv_final-sellifnr ' / ' lv_final-name1 into wa_contents.
append wa_contents to it_contents.
concatenate '<tr><td width="30%">Inspection Lot Number:</td><td>' lv_final-prueflos into wa_contents.
append wa_contents to it_contents.
concatenate '<tr><td width="30%">QPH/Notification Number:</td><td>' lv_final-notno into wa_contents.
append wa_contents to it_contents.
concatenate '<tr><td width="30%">Plant</td><td>' lv_final-werk '</td></tr>' into wa_contents.
append wa_contents to it_contents.
concatenate '<tr><td width="30%">Raised Date</td><td>' lv_final-ddate ' / ' lv_final-ddate+6(2) '.'
lv_final-ddate+4(2) '.' lv_final-ddate(4) '</td></tr>' into wa_contents.
append wa_contents to it_contents.
concatenate '<tr><td width="30%">Part No/Name:</td><td>' lv_final-selmatnr ' / ' lv_final-ktextmat into wa_contents.
append wa_contents to it_contents.
concatenate '<tr><td width="30%">Rejection code/Description:</td><td>' lv_final-rcode ' / ' lv_final-rtext into wa_contents.
append wa_contents to it_contents.
wa_contents-line = '</table> '.
append wa_contents to it_contents.
wa_contents-line = '</body></html>'.
append wa_contents to it_contents.
describe table it_contents lines tab_lines.
******* packlist
wa_pack-head_start = 1.
wa_pack-head_num = 0.
wa_pack-body_start = 1.
wa_pack-body_num = tab_lines.
wa_pack-doc_type = 'HTML'.
append wa_pack to it_pack.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = doc_data
put_in_outbox = 'X'
commit_work = 'X'
tables
packing_list = it_pack
* OBJECT_HEADER =
* CONTENTS_BIN =
contents_txt = it_contents
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
receivers = it_recv
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 'dgsgfds' TYPE 'I'.
move gc_308 to gv_msg_no.
perform collect_msg tables et_return[]
using space
gv_msg_no.
else .
move gc_307 to gv_msg_no.
perform collect_msg tables et_return[]
using space
gv_msg_no.
endif.
endfunction.
*----------------------------------------------------------------------*
***INCLUDE LZQM_QPH_SENDMAILF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form COLLECT_MSG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ET_DMS_RETURN[] text
* -->P_SPACE text
* -->P_GV_MSG_NO text
*----------------------------------------------------------------------*
form collect_msg tables p_et_return type bapiret2_t
using p_space
p_gv_msg_no.
data: gs_message type bapiret2.
*---Constant
constants:gc_msgclass type sy-msgid value 'ZPPS_MC',
gc_msgtype_error type sy-msgty value 'E',
gc_msgtype_sucess type sy-msgty value 'S'.
*--Global Variables
data : gv_msg_value type string,
gv_msg_no type sy-msgno.
clear: gs_message.
if p_gv_msg_no = '308' .
gs_message-id = gc_msgclass .
gs_message-type = gc_msgtype_error.
gs_message-number = p_gv_msg_no.
elseif p_gv_msg_no = '307'.
gs_message-id = gc_msgclass .
gs_message-type = gc_msgtype_sucess.
gs_message-number = p_gv_msg_no.
endif.
call function 'BALW_BAPIRETURN_GET2'
exporting
type = gs_message-type
cl = gs_message-id
number = gs_message-number
* par1 = gs_message-message_v1
importing
return = gs_message.
append gs_message to p_et_return.
clear: gs_message.
endform. " COLLECT_MSG
Conclusion : We can use HTML any tags to arrange our DATA into user’s expected , and also user friendly and meaning full result with clear and more understanding. sending a mail is an simple process but if DATA which we have send from SAP Mail should be meaning full and clear format , using an this example we can arrange our mail sending data into proper and clear format to understand the END use’s
Regards,
Vaibhav Revankar.
SAP ABAP + UI5 + Odata .
So… this is a program that makes HTML – hardly rocket science. But you’ve given no indication of how to attach this to an email. And there’s no attachment. I’m afraid I find it very hard what it is you’re trying to say here, nor what use it might be. Perhaps you can have someone locally go through it with you to make it clearer.
Oh, and if you’re going to post code – do use the {;} button. It makes things much easier to read.
Hi Matthew,
please check now Code editor for the more details.
NOTE: it_contents having HTML tags and Data, need to Pass into "'SO_NEW_DOCUMENT_ATT_SEND_API1'" with sender email id.
Well, I’m glad you know about the {;} button now. See how much better your blog looks already. Now… why not apply to the other code in your blog.
But you shouldn’t be using SO_ function modules. The CL_BCS framework is far easier to use, more flexible and powerful, and less prone to errors.
And use ABAP Objects rather than FORMs, which are obsolete…