这几天接到这样一个ABAP需求:SAP邮件自动发送给各个部门领导,邮件的正文为了美观需要采用指定的HTML格式,同时需要附上Excel附件。
之前都是简单的采用函数“SO_NEW_DOCUMENT_ATT_SEND_API1”来进行发送的,那么这里该如何处理呢?
这里需要考虑两个问题:
- 正文采用HTML格式;
- 带有Excel附件;
这里我简单做了一个DEMO,基本可以满足需求,但是比较繁琐,当然有更好的方式可以在留言中提出来,由于涉及用户隐私,所以不希望本文被转载。
首先看一下最终简单的效果图:
【具体实现】
1、HTML正文格式
***整理邮件内容
data : lv_updat type string,
lv_uptim type string.
lv_updat = sy-datum+0(4) && '/' && sy-datum+4(2) && '/' && sy-datum+6(2).
lv_uptim = sy-uzeit+0(2) && ':' && sy-uzeit+2(2) && ':' && sy-uzeit+4(2).
*** 主题
read table gt_tab_excel_list index 1.
select single mtart from mara into lv_mtart
where matnr = gt_tab_excel_list-matnr.
if lv_mtart = 'FERT'.
lv_subject = text-012.
elseif lv_mtart = 'HALB'.
lv_subject = text-013.
else.
lv_subject = text-014.
endif.
"CVJ物料类型安全库存更新
lv_subject = 'CVJ' && lv_subject && text-015.
*** 邮件标题
lv_title = lv_subject.
*** 正文
text =
'The following information is automatically sent by SAP system.'.
concatenate
'<html>'
'<head>'
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'
'<title>' lv_title '</title>'
'<style type="text/css">'
'table{ font-size: 12px; font-family: "Microsoft yahei",Arial; text-align: center; }'
'th{ background-color: skyblue; }'
'tr{ height: 30px; }'
* '.font{ font-style: italic; color: deeppink; font-size: 12px; }'
* '.color{ color:blue; }'
'table,table tr th,table tr td { border:1px solid black;border-collapse:collapse; } '
'</style>'
'</head>'
'<body>'
'<div>' text '</div> '
'<br />'
'<div>' lv_subject '</div> '
'<table width="550" border="0" cellpadding="0" cellspacing="0">'
'<tr>'
'<th>物料类型</th>'
'<th>更新件数</th>'
'<th>更新日期</th>'
'<th>更新时间</th>'
'<th>更新人</th>'
'</tr>' into ls_html separated by space.
lv_num = pv_num.
concatenate ls_html
'<tr>'
'<td>'lv_mtart'</td>'
'<td>'lv_num'</td>'
'<td>'lv_updat'</td>'
'<td>'lv_uptim'</td>'
'<td>'sy-uname'</td>'
'</tr>'
into ls_html separated by space.
concatenate ls_html
'</table>'
'<br />'
'<div> ※ 具体更新内容参考附件EXCEL,可通过 ERP T-code:ZMJMPPR0301 查询明细. </div> '
'</body>'
'</html>' into ls_html separated by space.
perform convert_string_to_tab tables lt_text
using ls_html.
这里需要注意的是,将html构成的mail信息截断为255字符,由Text构成。