事务代码smartforms创建一个表单ZTEST001
将表单转换成PDF并添加到邮件的附件中发送给用户
"打印参数 DATA:LV_FMNAME TYPE RS38L_FNAM, LS_CTRLOP TYPE SSFCTRLOP, LS_COMPOP TYPE SSFCOMPOP, LS_RETURN TYPE SSFCRESCL, LS_INFO TYPE SSFCRESCL, LS_OPTIONS TYPE SSFCRESOP. "附件参数 DATA:LT_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE, LT_TLINE TYPE TLINE OCCURS 0 WITH HEADER LINE, LT_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE. "邮件参数 DATA:LV_SIZE TYPE I, "邮件附件大小 LV_LINES_TXT TYPE I, "邮件文本行数 LV_LINES_BIN TYPE I, "邮件附件行数 LV_BENFILE TYPE XSTRING, LV_OBJECT TYPE CHAR50, "邮件主题 LV_PDFNAME TYPE CHAR50, GT_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE, "邮件内容 正文+附件 GT_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE, "正文内容 GT_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE, "附件内容 GT_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE, "收件人 LS_DOC_CHNG TYPE SODOCCHGI1. "邮件属性 "打印控制 LS_CTRLOP-NO_OPEN = 'X'. LS_CTRLOP-NO_CLOSE = 'X'. LS_CTRLOP-GETOTF = 'X'. LS_CTRLOP-LANGU = '1'. LS_CTRLOP-NO_DIALOG = 'X'. LS_COMPOP-TDNOPREV = 'X'. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING FORMNAME = 'ZTEST001' IMPORTING FM_NAME = LV_FMNAME EXCEPTIONS NO_FORM = 1 NO_FUNCTION_MODULE = 2 OTHERS = 3. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL FUNCTION 'SSF_OPEN' EXPORTING OUTPUT_OPTIONS = LS_COMPOP CONTROL_PARAMETERS = LS_CTRLOP USER_SETTINGS = 'X' IMPORTING JOB_OUTPUT_OPTIONS = LS_OPTIONS EXCEPTIONS FORMATTING_ERROR = 1 INTERNAL_ERROR = 2 SEND_ERROR = 3 USER_CANCELED = 4 OTHERS = 5. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL FUNCTION LV_FMNAME EXPORTING OUTPUT_OPTIONS = LS_COMPOP CONTROL_PARAMETERS = LS_CTRLOP USER_SETTINGS = ' ' IMPORTING JOB_OUTPUT_INFO = LS_RETURN EXCEPTIONS FORMATTING_ERROR = 1 INTERNAL_ERROR = 2 SEND_ERROR = 3 USER_CANCELED = 4 OTHERS = 5. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ELSE. ENDIF. CALL FUNCTION 'SSF_CLOSE' IMPORTING JOB_OUTPUT_INFO = LS_INFO EXCEPTIONS FORMATTING_ERROR = 1 INTERNAL_ERROR = 2 SEND_ERROR = 3 OTHERS = 4. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ELSE. APPEND LINES OF LS_INFO-OTFDATA TO LT_OTF. ENDIF. CALL FUNCTION 'CONVERT_OTF' EXPORTING FORMAT = 'PDF' PDF_USERNAME = 'TIANCZ' IMPORTING BIN_FILESIZE = LV_SIZE BIN_FILE = LV_BENFILE TABLES OTF = LT_OTF LINES = LT_TLINE EXCEPTIONS ERR_MAX_LINEWIDTH = 1 ERR_FORMAT = 2 ERR_CONV_NOT_POSSIBLE = 3 ERR_BAD_OTF = 4 OTHERS = 5. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. IF LV_BENFILE IS NOT INITIAL. CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING BUFFER = LV_BENFILE IMPORTING OUTPUT_LENGTH = LV_SIZE TABLES BINARY_TAB = LT_RECORD. ENDIF. REFRESH:GT_RECLIST,GT_OBJTXT,GT_OBJBIN,GT_OBJPACK. CLEAR: LS_DOC_CHNG. "将转换后的文件添加到邮件附件 APPEND LINES OF LT_RECORD TO GT_OBJBIN. "添加邮件正文 GT_OBJTXT = ''. APPEND GT_OBJTXT. GT_OBJTXT = '邮件测试,包含一个PDF附件'. APPEND GT_OBJTXT. "邮件正文行数 LV_LINES_TXT = LINES( GT_OBJTXT ). LV_OBJECT = '邮件测试'. LV_PDFNAME = 'SM转换的PDF文件.pdf'. LS_DOC_CHNG-OBJ_LANGU = SY-LANGU. LS_DOC_CHNG-OBJ_NAME = 'Email'. LS_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10. LS_DOC_CHNG-OBJ_DESCR = LV_OBJECT. "邮件主题 LS_DOC_CHNG-SENSITIVTY = 'F'. LS_DOC_CHNG-DOC_SIZE = LV_LINES_TXT * 255 + LV_SIZE. LS_DOC_CHNG-PRIORITY = '1'. CLEAR GT_OBJPACK-TRANSF_BIN. GT_OBJPACK-HEAD_START = 1. GT_OBJPACK-HEAD_NUM = 0. GT_OBJPACK-BODY_START = 1. GT_OBJPACK-BODY_NUM = LV_LINES_TXT. GT_OBJPACK-DOC_TYPE = 'RAW'. APPEND GT_OBJPACK. CLEAR:LV_LINES_BIN. GT_OBJPACK-TRANSF_BIN = 'X'. GT_OBJPACK-HEAD_START = 1. GT_OBJPACK-HEAD_NUM = 1. GT_OBJPACK-BODY_START = 1. LV_LINES_BIN = LINES( LT_RECORD ). GT_OBJPACK-DOC_SIZE = LV_SIZE . GT_OBJPACK-BODY_NUM = LV_LINES_BIN. GT_OBJPACK-DOC_TYPE = 'PDF'. GT_OBJPACK-OBJ_NAME = 'PO'. GT_OBJPACK-OBJ_DESCR = LV_PDFNAME. APPEND GT_OBJPACK. GT_RECLIST-RECEIVER = 'XXXXX@163.com'."收件人邮箱 GT_RECLIST-REC_TYPE = 'U'. APPEND GT_RECLIST. CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING DOCUMENT_DATA = LS_DOC_CHNG " 邮件属性 PUT_IN_OUTBOX = '' COMMIT_WORK = 'X' TABLES PACKING_LIST = GT_OBJPACK " 邮件内容 CONTENTS_BIN = GT_OBJBIN " 附件内容(二进制) CONTENTS_TXT = GT_OBJTXT " 邮件内容(直接填入) RECEIVERS = GT_RECLIST " 收件箱地址 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 '发送成功!' TYPE 'S'. WAIT UP TO 1 SECONDS. SUBMIT RSCONN01 WITH MODE = 'INT' WITH OUTPUT = '' AND RETURN. ELSE. MESSAGE '发送失败!' TYPE 'S'. ENDIF.