最终成果:
*&---------------------------------------------------------------------**& Report ZLC_FIND_EXIT*&---------------------------------------------------------------------**&根据T-CODE / 程序名查询出口、BADI增强*&---------------------------------------------------------------------*REPORT ZEDIT_G."打印参数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'EXPORTINGFORMNAME = 'ZTEST001' "创建的SMARTFORMS表单名称IMPORTINGFM_NAME = LV_FMNAMEEXCEPTIONSNO_FORM = 1NO_FUNCTION_MODULE = 2OTHERS = 3.IF SY-SUBRC <> 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.CALL FUNCTION 'SSF_OPEN' "打开打印页面EXPORTINGOUTPUT_OPTIONS = LS_COMPOPCONTROL_PARAMETERS = LS_CTRLOPUSER_SETTINGS = 'X'IMPORTINGJOB_OUTPUT_OPTIONS = LS_OPTIONSEXCEPTIONSFORMATTING_ERROR = 1INTERNAL_ERROR = 2SEND_ERROR = 3USER_CANCELED = 4OTHERS = 5.IF SY-SUBRC <> 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.CALL FUNCTION LV_FMNAME 调用打印表单接口函数EXPORTINGOUTPUT_OPTIONS = LS_COMPOPCONTROL_PARAMETERS = LS_CTRLOPUSER_SETTINGS = ' 'IMPORTINGJOB_OUTPUT_INFO = LS_RETURNEXCEPTIONSFORMATTING_ERROR = 1INTERNAL_ERROR = 2SEND_ERROR = 3USER_CANCELED = 4OTHERS = 5.IF SY-SUBRC <> 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ELSE.ENDIF.CALL FUNCTION 'SSF_CLOSE' "关闭打印表单IMPORTINGJOB_OUTPUT_INFO = LS_INFOEXCEPTIONSFORMATTING_ERROR = 1INTERNAL_ERROR = 2SEND_ERROR = 3OTHERS = 4.IF SY-SUBRC <> 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ELSE.APPEND LINES OF LS_INFO-OTFDATA TO LT_OTF.ENDIF.CALL FUNCTION 'CONVERT_OTF' "转换PDF格式EXPORTINGFORMAT = 'PDF'PDF_USERNAME = 'TIANCZ'IMPORTINGBIN_FILESIZE = LV_SIZEBIN_FILE = LV_BENFILETABLESOTF = LT_OTFLINES = LT_TLINEEXCEPTIONSERR_MAX_LINEWIDTH = 1ERR_FORMAT = 2ERR_CONV_NOT_POSSIBLE = 3ERR_BAD_OTF = 4OTHERS = 5.IF SY-SUBRC <> 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.IF LV_BENFILE IS NOT INITIAL.CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' "转换PDF添加邮件附件EXPORTINGBUFFER = LV_BENFILEIMPORTINGOUTPUT_LENGTH = LV_SIZETABLESBINARY_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'EXPORTINGDOCUMENT_DATA = LS_DOC_CHNG " 邮件属性PUT_IN_OUTBOX = ''COMMIT_WORK = 'X'TABLESPACKING_LIST = GT_OBJPACK " 邮件内容CONTENTS_BIN = GT_OBJBIN " 附件内容(二进制)CONTENTS_TXT = GT_OBJTXT " 邮件内容(直接填入)RECEIVERS = GT_RECLIST " 收件箱地址EXCEPTIONSTOO_MANY_RECEIVERS = 1DOCUMENT_NOT_SENT = 2DOCUMENT_TYPE_NOT_EXIST = 3OPERATION_NO_AUTHORIZATION = 4PARAMETER_ERROR = 5X_ERROR = 6ENQUEUE_ERROR = 7OTHERS = 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.
T-CODE:SOST--查看邮件发送情况:
可参考学习笔记:https://www.cnblogs.com/StephenAmell/p/17414767.html