我的網誌清單

20141001

ABAP-寄MAIL function

 

1. SO_NEW_DOCUMENT_SEND_API1

這個func最常用來寄mail,所以記錄一下以免忘

clip_image002[4]

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

*& Report ZSENDMAIL

*&

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

*&

*&

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

REPORT ZSENDMAIL.

DATA: OBJCONT LIKE SOLISTI1 OCCURS 5 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: ENTRIES LIKE SY-TABIX.

DATA: NAME(15).

*主旨

DOC_CHNG-OBJ_DESCR = '污狼某!'.

*MAIL BODY

OBJCONT = '呷奔啦 !!!'.

APPEND OBJCONT.

OBJCONT = '緊來去 !'.

APPEND OBJCONT.

*計算大小寫回MAIL HEADER

DESCRIBE TABLE OBJCONT LINES ENTRIES.

READ TABLE OBJCONT INDEX ENTRIES.

DOC_CHNG-DOC_SIZE = ( ENTRIES - 1 ) * 255 + STRLEN( OBJCONT ).

*收件者

CLEAR RECLIST.

RECLIST-RECEIVER = 'aaa@gmail.com'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

* Send the document

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_TYPE = 'RAW'

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

OBJECT_CONTENT = OBJCONT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

*狀態回傳

CASE SY-SUBRC.

WHEN 0.

LOOP AT RECLIST.

IF RECLIST-RECEIVER = SPACE.

NAME = RECLIST-REC_ID.

ELSE.

NAME = RECLIST-RECEIVER.

ENDIF.

IF RECLIST-RETRN_CODE = 0.

WRITE: / NAME, ': succesfully sent'.

ELSE.

WRITE: / NAME, ': error occured'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'Too many receivers specified !'.

WHEN 2.

WRITE: / 'No receiver got the document !'.

WHEN 4.

WRITE: / 'Missing send authority !'.

WHEN OTHERS.

WRITE: / 'Unexpected error occurred !'.

ENDCASE.

*& Report ZSENDMAIL

2.使用se37

clip_image004[4]

COMMIT_WORK一定要給值,要不會寄不出去

RECEIVERS內的收件者,其REC_TYPE要給U,要不也會有問題

OBJECT_CONTENT是放mail本文用的

clip_image006[4]

要如左圖才是正常的

沒有留言:

張貼留言