REPORT Y_CLY_SEND_MAIL.
TABLES: RLGRAP.
DATA: G_SEND_FLG LIKE SONV-FLAG.
DATA: G_EMAIL_ID LIKE SOFOLENTI1-OBJECT_ID.
DATA: GT_RECE TYPE TABLE OF SOMLRECI1 WITH HEADER LINE.
DATA: GT_MAIL_TEXT TYPE TABLE OF SOLISTI1 WITH HEADER LINE.
DATA: GT_FIELD_TAB TYPE TABLE OF SOLIX WITH HEADER LINE.
DATA: GT_PACK_TAB TYPE TABLE OF SOPCKLSTI1 WITH HEADER LINE.
DATA: GT_OBJ_HEAD TYPE TABLE OF SOLISTI1 WITH HEADER LINE.
DATA: GS_DOCMENT TYPE SODOCCHGI1.
DATA: GV_HEAD_SID TYPE I.
DATA: GV_BODY_SID TYPE I.
DATA: GV_BODY_SIDA TYPE I.
DATA: GV_TITLE TYPE STRING VALUE 'title:C'.
DATA: GT_FILE_PATH TYPE TABLE OF STRING WITH HEADER LINE.
DATA: LT_T001 TYPE TABLE OF T001 WITH HEADER LINE.
PARAMETERS: P_FILE TYPE RLGRAP-FILENAME DEFAULT 'C:\Users\cly_a\Desktop\fj3.xlsx'.
SELECT-OPTIONS: S_FILE FOR RLGRAP-FILENAME DEFAULT 'C:\Users\cly_a\Desktop\fj3.xlsx'.
PARAMETERS: L1(84) DEFAULT 'ABC'.
PARAMETERS: L2(84) DEFAULT 'END'.
INITIALIZATION.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_FILE-LOW.
PERFORM FRM_ZF4_FILE.
START-OF-SELECTION.
PERFORM FRM_00_INIT_DATA.
PERFORM FRM_SEND_MAIL.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form FRM_00_INIT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_00_INIT_DATA .
CLEAR: GV_HEAD_SID.
CLEAR: GV_BODY_SIDA.
CLEAR: GT_FILE_PATH[].
CLEAR: LT_T001[].
IF P_FILE IS NOT INITIAL.
GT_FILE_PATH = P_FILE.
APPEND GT_FILE_PATH.
ENDIF.
LOOP AT S_FILE.
GT_FILE_PATH = S_FILE-LOW.
APPEND GT_FILE_PATH.
ENDLOOP.
SORT GT_FILE_PATH.
DELETE ADJACENT DUPLICATES FROM GT_FILE_PATH COMPARING ALL FIELDS.
SELECT * INTO TABLE LT_T001 FROM T001 UP TO 10 ROWS.
ENDFORM. " FRM_00_INIT_DATA
*&---------------------------------------------------------------------*
*& Form FRM_SEND_MAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FRM_SEND_MAIL.
CLEAR: GS_DOCMENT.
CLEAR: G_SEND_FLG.
CLEAR: G_EMAIL_ID.
CLEAR: GT_PACK_TAB[].
CLEAR: GT_OBJ_HEAD[].
CLEAR: GT_MAIL_TEXT[].
CLEAR: GT_FIELD_TAB[].
CLEAR: GT_RECE[].
PERFORM FRM_SEND_MAIL_S1_RECEIVER TABLES GT_RECE.
PERFORM FRM_SEND_MAIL_S2_TITLE_BODY TABLES GT_PACK_TAB GT_MAIL_TEXT USING GS_DOCMENT GV_TITLE.
PERFORM FRM_SEND_MAIL_S3_FILE_ITAB.
BREAK-POINT.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' DESTINATION 'DEABK'
EXPORTING
DOCUMENT_DATA = GS_DOCMENT
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
IMPORTING
G_SEND_FLG_TO_ALL = G_SEND_FLG
NEW_OBJECT_ID = G_EMAIL_ID
TABLES
PACKING_LIST = GT_PACK_TAB " 邮件详细列表清单
OBJECT_HEADER = GT_OBJ_HEAD " 邮件附件列表【参数作用不详】
CONTENTS_TXT = GT_MAIL_TEXT " 邮件内容
CONTENTS_HEX = GT_FIELD_TAB " 内容(all)【本地附件、内表】
RECEIVERS = GT_RECE " 收件人列表
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_G_SEND_FLG = 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.
ENDIF.
WRITE:/ G_EMAIL_ID.
WRITE:/ G_SEND_FLG.
WRITE:/ SY-SUBRC.
ENDFORM. "FRM_SEND_MAIL
*&---------------------------------------------------------------------*
*& Form FRM_SEND_MAIL_S1_RECEIVER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_RECE text
*----------------------------------------------------------------------*
FORM FRM_SEND_MAIL_S1_RECEIVER TABLES PT_RECE STRUCTURE SOMLRECI1.
PT_RECE-REC_TYPE = 'U'.
PT_RECE-COM_TYPE = 'INT'.
PT_RECE-EXPRESS = 'X'.
""""""""""""""""""""""""""""""""""""""""""""""""""
PT_RECE-COPY = ''. " 正常收件人
PT_RECE-RECEIVER = 'yunlong.cao@pcitc.com'.
APPEND PT_RECE.
PT_RECE-COPY = 'X'. " 抄送
PT_RECE-RECEIVER = '262560478@QQ.COM'.
APPEND PT_RECE.
CLEAR: PT_RECE.
ENDFORM. "FRM_SEND_RECEIVER
*&---------------------------------------------------------------------*
*& Form FRM_SEND_TITLE_BODY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->GT_PACK_TAB text
* -->PT_MAIL_TEXT text
* -->GS_DOCMENT text
* -->PV_TITLE text
*----------------------------------------------------------------------*
FORM FRM_SEND_MAIL_S2_TITLE_BODY TABLES PT_PACK_TAB STRUCTURE SOPCKLSTI1
PT_MAIL_TEXT STRUCTURE SOLISTI1
USING GS_DOCMENT TYPE SODOCCHGI1
PV_TITLE.
PT_MAIL_TEXT-LINE = L1.
APPEND PT_MAIL_TEXT.
PT_MAIL_TEXT-LINE = L2.
APPEND PT_MAIL_TEXT.
**** Mail Attribute
GS_DOCMENT-OBJ_NAME = 'MESSAGE'.
GS_DOCMENT-OBJ_DESCR = '邮件主题' . " 邮件主题
GS_DOCMENT-OBJ_DESCR = PV_TITLE. " 标题
GS_DOCMENT-OBJ_LANGU = SY-LANGU.
GS_DOCMENT
ABAP-发邮件SO_NEW_DOCUMENT_ATT_SEND_API1(本地附件,内表,SmartForms)
于 2019-08-29 15:35:32 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)