send a mail via sap

***********************************************************************
* Program Name: ztest_mail
* Title : Send email via sap
* Author :
* Create Date :
* Description : Send email via sap
***********************************************************************
report ztest_mail.

************************************************************************
* DATA
************************************************************************
data:
gt_mail type zsmm0012_mail occurs 0 with header line,
objpack like sopcklsti1 occurs 2 with header line,
objhead like solisti1 occurs 1 with header line,
objbin like solisti1 occurs 10 with header line,
objtxt like solisti1 occurs 10 with header line,
reclist like somlreci1 occurs 5 with header line,
doc_chng like sodocchgi1,
tab_lines like sy-tabix,
otf like itcoo occurs 100 with header line,
cancel,
pdf like tline occurs 100 with header line,
doctab like docs occurs 1 with header line,
numbytes type i,
arc_idx like toa_dara,
pdfspoolid like tsp01-rqident,
jobname like tbtcjob-jobname,
jobcount like tbtcjob-jobcount.
************************************************************************
* SELECTION-SCREEN *
************************************************************************
parameters:
spoolno like tsp01-rqident,
download as checkbox default ' ',
p_file like rlgrap-filename default 'C:tempfile.pdf'.

************************************************************************
* START-OF-SELECTION
************************************************************************
start-of-selection.


clear: doc_chng,objtxt,objtxt[],reclist,reclist[],
objpack,objpack[].
doc_chng-obj_name = 'SENDFILE'.
doc_chng-obj_descr = 'Send External Mail'.
objtxt+0(40) = 'Price Change Error List'.
append objtxt.
clear objtxt.
objtxt+0(10) = 'Po Number'.
objtxt+11(5) = 'Item'.
objtxt+17(9) = 'Pur.Group'.
objtxt+27(18) = 'Pur.Group.Desc'.
objtxt+46(8) = 'MRP Ctrl'.
objtxt+56(18) = 'MRP Ctrl Desc'.
objtxt+75(60) = 'Error Message'.
append objtxt.
clear objtxt.
* Creation of the document to be sent
* File Name
gt_mail-ebeln = '10001'.
gt_mail-ebelp = 10.
gt_mail-ekgrp = '99'.
gt_mail-eknam = 'test 99'.
gt_mail-dispo = 'zzz'.
gt_mail-dsnam = 'test zzz'.
gt_mail-errea = 'Error error'.
append gt_mail.

gt_mail-ebeln = '100010000'.
gt_mail-ebelp = 10.
gt_mail-ekgrp = '9'.
gt_mail-eknam = 'test 9'.
gt_mail-dispo = 'zzz'.
gt_mail-dsnam = 'test zzz'.
gt_mail-errea = 'Error error'.
append gt_mail.


gt_mail-ebeln = '10001000'.
gt_mail-ebelp = 10.
gt_mail-ekgrp = '99'.
gt_mail-eknam = 'test 99'.
gt_mail-dispo = 'zzz'.
gt_mail-dsnam = 'test zzz'.
gt_mail-errea = 'Error error'.
append gt_mail.

gt_mail-ebeln = '100010'.
gt_mail-ebelp = 10.
gt_mail-ekgrp = '999'.
gt_mail-eknam = 'test 999'.
gt_mail-dispo = 'zzz'.
gt_mail-dsnam = 'test zzz'.
gt_mail-errea = 'Error error'.
append gt_mail.
loop at gt_mail.

objtxt+0(10) = gt_mail-ebeln.
objtxt+11(5) = gt_mail-ebelp.
objtxt+17(9) = gt_mail-ekgrp.
objtxt+27(18) = gt_mail-eknam.
objtxt+46(8) = gt_mail-dispo.
objtxt+56(18) = gt_mail-dsnam.
objtxt+75(60) = gt_mail-errea.
append objtxt.
clear objtxt.
endloop.


* call function 'GUI_DOWNLOAD'
* exporting
** BIN_FILESIZE =
* filename = 'C:ERROR_LOG.TXT'
** FILETYPE = 'ASC'
** APPEND = ' '
** WRITE_FIELD_SEPARATOR = ' '
** HEADER = '00'
** TRUNC_TRAILING_BLANKS = ' '
** WRITE_LF = 'X'
** COL_SELECT = ' '
** COL_SELECT_MASK = ' '
** DAT_MODE = ' '
** CONFIRM_OVERWRITE = ' '
** NO_AUTH_CHECK = ' '
** CODEPAGE = ' '
** IGNORE_CERR = ABAP_TRUE
** REPLACEMENT = '#'
** WRITE_BOM = ' '
** TRUNC_TRAILING_BLANKS_EOL = 'X'
** WK1_N_FORMAT = ' '
** WK1_N_SIZE = ' '
** WK1_T_FORMAT = ' '
** WK1_T_SIZE = ' '
** WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
** SHOW_TRANSFER_STATUS = ABAP_TRUE
** IMPORTING
** FILELENGTH =
* tables
* data_tab = gt_mail
** FIELDNAMES =
** EXCEPTIONS
** FILE_WRITE_ERROR = 1
** NO_BATCH = 2
** GUI_REFUSE_FILETRANSFER = 3
** INVALID_TYPE = 4
** NO_AUTHORITY = 5
** UNKNOWN_ERROR = 6
** HEADER_NOT_ALLOWED = 7
** SEPARATOR_NOT_ALLOWED = 8
** FILESIZE_NOT_ALLOWED = 9
** HEADER_TOO_LONG = 10
** DP_ERROR_CREATE = 11
** DP_ERROR_SEND = 12
** DP_ERROR_WRITE = 13
** UNKNOWN_DP_ERROR = 14
** ACCESS_DENIED = 15
** DP_OUT_OF_MEMORY = 16
** DISK_FULL = 17
** DP_TIMEOUT = 18
** FILE_NOT_FOUND = 19
** DATAPROVIDER_EXCEPTION = 20
** CONTROL_FLUSH_ERROR = 21
** OTHERS = 22
* .
* if sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* endif.
*

describe table objtxt lines tab_lines.
read table objtxt index tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
* Completing the recipient list
* reclist-receiver = 'khsu@abeam.com'.
* reclist-rec_type = 'U'.
* append reclist.
reclist-receiver = 'AB_KAOWEN'.
reclist-rec_type = 'B'.
append reclist.

** Creation of the entry for the compressed document
* clear objpack-transf_bin.
* objpack-head_start = 1.
* objpack-head_num = 0.
* objpack-body_start = 1.
* objpack-body_num = tab_lines.
* objpack-doc_type = 'RAW'.
* append objpack.

* Creation of the entry for the compressed attachment
*OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
OBJPACK-OBJ_NAME = 'ERROR_LOG.TXT'.
OBJPACK-OBJ_DESCR = 'ERROR LOG'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.

* Sending the document
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = doc_chng
put_in_outbox = 'X'
tables
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
receivers = reclist
exceptions
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
others = 99.

case sy-subrc.
when 0.
write: / 'Result of the send process:'.
loop at reclist.
write: / reclist-receiver(48), ':'.
if reclist-retrn_code = 0.
write 'The document was sent'.
else.
write 'The document could not be sent'.
endif.
endloop.
when 1.
write: / 'No authorization for sending to the specified number',
'of recipients'.
when 2.
write: / 'Document could not be sent to any recipient'.
when 4.
write: / 'No send authorization'.
when others.
write: / 'Error occurred while sending'.
endcase.

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/190059/viewspace-1012767/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/190059/viewspace-1012767/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值