首页 > 其他分享 >SAP AUTOMAIL-自动发邮件功能

SAP AUTOMAIL-自动发邮件功能

时间:2024-08-26 13:21:53浏览次数:12  
标签:发邮件 DATA lv yjzw lt ls AUTOMAIL SAP TYPE

总结

针对发送邮件内容封装公用函数,针对不同业务场景,比如邮件统计排名晾晒类,各类业务催办类知会类邮件等,实现AUTO MAIL自动触发邮件。

1. 邮件发送内容:正文,附件,超链接等等

1.1  正文可以是一般内容或表格明细清单,涉及到很多格式的设置,用HTML格式设置。

1.2  附件可以是DOC,  PDF ,EXCEL,JPG/PNG图片等等格式

1.3  邮件中可设置超链接地址,比如用户催办邮件,用户点超链接,可以直接调整到待办单据页面。

2.  邮件发送监控

发送邮件tcode: scot   可以监控邮件发送状态及内容

如果系统中所有邮件发送不出去 跟BASIS排查系统问题;若单据功能发送不出,排查程序的问题

封装发送邮件的公用函数

1.SE37创建公用函数FUNCTION :ZFIFM_0164

2. Import 参数。

入参说明: 

IM_MAIL_CONTENTTYPESTRING                     邮件正文
IM_SUBJECTTYPESO_OBJ_DES                     邮件主题
IM_MAILTYPEBCSY_SMTPA                     主送邮件地址
IM_CCMAILTYPEBCSY_SMTPA                     抄送邮件地址
IM_CCMAIL_BLINDTYPEBCSY_SMTPA                     密抄送邮件地址
IM_SENDERTYPESYST_UNAME'ICP-NOTICE'邮件发送人
IM_OTFTYPETT_ITCOO                     附件PDF格式内表数据
IM_CONTENT_HEXTYPESOLIX_TAB                     附件EXCEL文件
IM_CONTENT_DOCTYPESOLIX_TAB                     附件WORD文件
IM_CONTENT_PNGTYPESOLIX_TAB                     附件图片文件
IT_EXPERTSTYPEZTTFI_GENERAL_RANGE                     Table type for general range table
IM_IMG_TOP_NAMETYPESTRING                     顶部图片
IM_IMG_BOTTOM_NAMETYPESTRING                     底部图片
IM_ATTACHMENT_SUBJECTTYPESO_OBJ_DES                     附件名称
IM_XSTRINGTYPEXSTRING                                                                                                    
IM_EXCEL_SIZETYPESO_OBJ_LEN                     EXCEL文档内容大小
IT_CONTENT_HEXTYPEZTEXCEL_FJ                     邮件附件表类型 
IM_XLSXTYPECHAR1                     附件格式XLSX

 EXCEPTION定义:

FUNCTION ZFIFM_0164.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(IM_MAIL_CONTENT) TYPE  STRING OPTIONAL
*"     VALUE(IM_SUBJECT) TYPE  SO_OBJ_DES OPTIONAL
*"     VALUE(IM_MAIL) TYPE  BCSY_SMTPA OPTIONAL
*"     VALUE(IM_CCMAIL) TYPE  BCSY_SMTPA OPTIONAL
*"     VALUE(IM_CCMAIL_BLIND) TYPE  BCSY_SMTPA OPTIONAL
*"     VALUE(IM_SENDER) TYPE  SYST_UNAME DEFAULT 'ICP-NOTICE'
*"     VALUE(IM_OTF) TYPE  TT_ITCOO OPTIONAL
*"     VALUE(IM_CONTENT_HEX) TYPE  SOLIX_TAB OPTIONAL
*"     VALUE(IM_CONTENT_DOC) TYPE  SOLIX_TAB OPTIONAL
*"     VALUE(IM_CONTENT_PNG) TYPE  SOLIX_TAB OPTIONAL
*"     REFERENCE(IT_EXPERTS) TYPE  ZTTFI_GENERAL_RANGE OPTIONAL
*"     VALUE(IM_IMG_TOP_NAME) TYPE  STRING OPTIONAL
*"     VALUE(IM_IMG_BOTTOM_NAME) TYPE  STRING OPTIONAL
*"     VALUE(IM_ATTACHMENT_SUBJECT) TYPE  SO_OBJ_DES OPTIONAL
*"     VALUE(IM_XSTRING) TYPE  XSTRING OPTIONAL
*"     VALUE(IM_EXCEL_SIZE) TYPE  SO_OBJ_LEN OPTIONAL
*"     VALUE(IT_CONTENT_HEX) TYPE  ZTEXCEL_FJ OPTIONAL
*"     VALUE(IM_XLSX) TYPE  CHAR1 OPTIONAL
*"  RAISING
*"      CX_SEND_REQ_BCS
*"----------------------------------------------------------------------
  DATA : LT_MAIL_BODY       TYPE SOLI_TAB,
         LO_CX_SEND_REQ_BCS TYPE REF TO CX_SEND_REQ_BCS,
         LO_EMAIL_BODY      TYPE REF TO CL_DOCUMENT_BCS,
         LO_RECEIVER        TYPE REF TO CL_CAM_ADDRESS_BCS,
         LO_EMAIL           TYPE REF TO CL_BCS,
         LO_SENDER          TYPE REF TO CL_SAPUSER_BCS,
         L_SEND_RESULT      TYPE OS_BOOLEAN,
         COS_MAIL           TYPE C LENGTH 10 VALUE '@vanke.com',
         COS_MAIL_HZ        TYPE C LENGTH 10 VALUE '@'.

**  设置签名相关变量
  DATA: L_LEN          TYPE SO_OBJ_LEN,
        LT_SOLIX       TYPE SOLIX_TAB,
        LV_IS_FOLDER   TYPE BOOLE_D,
        LV_CONTENT     TYPE XSTRING,
        LV_LOIO        TYPE SKWF_IO,
        LO_MR_API      TYPE REF TO IF_MR_API,
        LO_CONVERT     TYPE REF TO CL_BCS_CONVERT,
        LO_MIME_HELPER TYPE REF TO CL_GBT_MULTIRELATED_SERVICE.

**  邮件正文转换
  CALL FUNCTION 'CONVERT_STRING_TO_TAB'
    EXPORTING
      I_STRING         = IM_MAIL_CONTENT
      I_TABLINE_LENGTH = 255
    TABLES
      ET_TABLE         = LT_MAIL_BODY. "

**  设置集团 LOGO 签名
  IF LO_MR_API IS INITIAL.
    LO_MR_API = CL_MIME_REPOSITORY_API=>IF_MR_API~GET_API( ).

  ENDIF.

  CALL METHOD LO_MR_API->GET
    EXPORTING
      I_URL              = '/SAP/PUBLIC/VankeLogo4Mail.png'
    IMPORTING
      E_IS_FOLDER        = LV_IS_FOLDER
      E_CONTENT          = LV_CONTENT
      E_LOIO             = LV_LOIO
    EXCEPTIONS
      PARAMETER_MISSING  = 1
      ERROR_OCCURED      = 2
      NOT_FOUND          = 3
      PERMISSION_FAILURE = 4
      OTHERS             = 5.

  L_LEN = XSTRLEN( LV_CONTENT ).

  CREATE OBJECT LO_CONVERT.

  CALL METHOD LO_CONVERT->XSTRING_TO_SOLIX
    EXPORTING
      IV_XSTRING = LV_CONTENT
    RECEIVING
      ET_SOLIX   = LT_SOLIX.

  CREATE OBJECT LO_MIME_HELPER.

  CALL METHOD LO_MIME_HELPER->ADD_BINARY_PART
    EXPORTING
      CONTENT      = LT_SOLIX
      FILENAME     = 'vanke.jpg'
      EXTENSION    = 'JPG'
      DESCRIPTION  = 'descriptiongif'
      CONTENT_TYPE = 'image/jpg'
      LENGTH       = L_LEN
      CONTENT_ID   = 'vanke.jpg'.
  CALL METHOD LO_MIME_HELPER->SET_MAIN_HTML
    EXPORTING
      CONTENT     = LT_MAIL_BODY
      FILENAME    = 'vanke' "'xx'
      DESCRIPTION = 'yy'.


  IF IM_IMG_TOP_NAME IS NOT INITIAL.


    CALL METHOD LO_MR_API->GET
      EXPORTING
*       i_url              = '/SAP/PUBLIC/ZPO/ZAI_HED_EMIAL.PNG' "ZAI_BOTTOM_EMIAL
        I_URL              = '/SAP/PUBLIC/ZPO/' && IM_IMG_TOP_NAME "ZAI_BOTTOM_EMIAL
      IMPORTING
        E_IS_FOLDER        = LV_IS_FOLDER
        E_CONTENT          = LV_CONTENT
        E_LOIO             = LV_LOIO
      EXCEPTIONS
        PARAMETER_MISSING  = 1
        ERROR_OCCURED      = 2
        NOT_FOUND          = 3
        PERMISSION_FAILURE = 4
        OTHERS             = 5.

    L_LEN = XSTRLEN( LV_CONTENT ).

    CREATE OBJECT LO_CONVERT.

    CALL METHOD LO_CONVERT->XSTRING_TO_SOLIX
      EXPORTING
        IV_XSTRING = LV_CONTENT
      RECEIVING
        ET_SOLIX   = LT_SOLIX.

    CALL METHOD LO_MIME_HELPER->ADD_BINARY_PART
      EXPORTING
        CONTENT      = LT_SOLIX
*       filename     = 'ZAI_HED_EMIAL.PNG'
        FILENAME     = |{ IM_IMG_TOP_NAME }|
        EXTENSION    = 'PNG'
        DESCRIPTION  = 'descriptiongif'
        CONTENT_TYPE = 'image/png'
        LENGTH       = L_LEN
*       content_id   = 'ZAI_HED_EMIAL.PNG'.
        CONTENT_ID   = |{ IM_IMG_TOP_NAME }|.

  ENDIF.

  IF IM_IMG_BOTTOM_NAME IS NOT INITIAL.

    CLEAR :LV_IS_FOLDER,LV_CONTENT,LV_LOIO,L_LEN,LO_CONVERT,LT_SOLIX[].
    CALL METHOD LO_MR_API->GET
      EXPORTING
*       i_url              = '/SAP/PUBLIC/ZPO/ZAI_BOTTOM_EMIAL.PNG' "ZAI_BOTTOM_EMIAL
        I_URL              = '/SAP/PUBLIC/ZPO/' && IM_IMG_BOTTOM_NAME "ZAI_BOTTOM_EMIAL
      IMPORTING
        E_IS_FOLDER        = LV_IS_FOLDER
        E_CONTENT          = LV_CONTENT
        E_LOIO             = LV_LOIO
      EXCEPTIONS
        PARAMETER_MISSING  = 1
        ERROR_OCCURED      = 2
        NOT_FOUND          = 3
        PERMISSION_FAILURE = 4
        OTHERS             = 5.

    L_LEN = XSTRLEN( LV_CONTENT ).

    CREATE OBJECT LO_CONVERT.

    CALL METHOD LO_CONVERT->XSTRING_TO_SOLIX
      EXPORTING
        IV_XSTRING = LV_CONTENT
      RECEIVING
        ET_SOLIX   = LT_SOLIX.

*    CREATE OBJECT lo_mime_helper.

    CALL METHOD LO_MIME_HELPER->ADD_BINARY_PART
      EXPORTING
        CONTENT      = LT_SOLIX
*       filename     = 'ZAI_BOTTOM_EMIAL.PNG'
        FILENAME     = |{ IM_IMG_BOTTOM_NAME }|
        EXTENSION    = 'PNG'
        DESCRIPTION  = 'descriptiongif2'
        CONTENT_TYPE = 'image/png'
        LENGTH       = L_LEN
        CONTENT_ID   = |{ IM_IMG_BOTTOM_NAME }|.

  ENDIF.


  TRY.
      CALL METHOD CL_DOCUMENT_BCS=>CREATE_FROM_MULTIRELATED
        EXPORTING
          I_SUBJECT          = IM_SUBJECT
          I_MULTIREL_SERVICE = LO_MIME_HELPER
        RECEIVING
          RESULT             = LO_EMAIL_BODY.
    CATCH CX_DOCUMENT_BCS .
      MESSAGE E672(SO) WITH 'bcs error while creating bcs_doc'.
      EXIT.
    CATCH CX_BCOM_MIME .
      MESSAGE E672(SO) WITH 'mime error while creating bcs_doc'.
      EXIT.
    CATCH CX_GBT_MIME.

  ENDTRY.
*START-OF-MODIFICATION-ON 24.07.2017 15:28:09 ------------------------------*
*Description:发送XLS附件功能
  DATA:LT_CONTENTS  TYPE TABLE OF SOLIX.
  DATA:LT_CONTENTS_DOC  TYPE TABLE OF SOLIX.
  DATA:LT_CONTENTS_EXCEL  TYPE TABLE OF SOLIX.
  DATA:LV_PDF_SIZE  TYPE SO_OBJ_LEN.
  DATA:LV_DESCR     TYPE SO_OBJ_DES.
  DATA:LV_PDF       TYPE XSTRING.
  DATA:LV_SIZE      TYPE SO_OBJ_LEN.
  DATA:L_PDF_LEN    TYPE I,
       LT_PDF_LINES TYPE TABLE OF TLINE.
**附件PDF
  IF NOT IM_OTF[] IS INITIAL.
    CALL FUNCTION 'CONVERT_OTF'
      EXPORTING
        FORMAT                = 'PDF'
        MAX_LINEWIDTH         = 132
      IMPORTING
        BIN_FILESIZE          = L_PDF_LEN
        BIN_FILE              = LV_PDF        " BINARY FILE
      TABLES
        OTF                   = IM_OTF
        LINES                 = LT_PDF_LINES
      EXCEPTIONS
        ERR_MAX_LINEWIDTH     = 1
        ERR_FORMAT            = 2
        ERR_CONV_NOT_POSSIBLE = 3
        ERR_BAD_OTF           = 4
        OTHERS                = 5.
    IF SY-SUBRC = 0.
    ENDIF.

    LV_SIZE = XSTRLEN( LV_PDF ).
    LT_CONTENTS = CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX( IP_XSTRING =  LV_PDF ).
    CONCATENATE IM_SUBJECT '.PDF' INTO LV_DESCR.
    TRY.
        CALL METHOD LO_EMAIL_BODY->ADD_ATTACHMENT(
            I_ATTACHMENT_TYPE    = 'PDF'
            I_ATT_CONTENT_HEX    = LT_CONTENTS
            I_ATTACHMENT_SIZE    = LV_SIZE
            I_ATTACHMENT_SUBJECT = LV_DESCR ).

      CATCH CX_DOCUMENT_BCS.

    ENDTRY.
  ENDIF.

  IF NOT IM_CONTENT_HEX[] IS INITIAL.
**附件XLS
*    APPEND LINES OF im_content_doc TO lt_contents_doc.
*    IF im_attachment_subject IS INITIAL.
*      CONCATENATE im_subject '.XLS' INTO lv_descr.
*    ELSE.
*      lv_descr = im_attachment_subject.
*    ENDIF.
*    TRY.
*        CALL METHOD lo_email_body->add_attachment(
*            i_attachment_type    = 'XLS'
*            i_att_content_hex    = lt_contents_doc
**           i_attachment_size    = lv_size
*            i_attachment_subject = lv_descr ).
*      CATCH cx_document_bcs.
*
*    ENDTRY.
    APPEND LINES OF IM_CONTENT_HEX TO LT_CONTENTS_EXCEL.
    IF IM_ATTACHMENT_SUBJECT IS INITIAL.
      IF IM_XLSX IS NOT INITIAL.
       CONCATENATE IM_SUBJECT '.XLSX' INTO LV_DESCR.
      ELSE.
       CONCATENATE IM_SUBJECT '.XLS' INTO LV_DESCR.
      ENDIF.
    ELSE.
      LV_DESCR = IM_ATTACHMENT_SUBJECT.
    ENDIF.
    IF IM_EXCEL_SIZE IS NOT INITIAL.
      LV_SIZE = IM_EXCEL_SIZE.
    ENDIF.
    TRY.
        CALL METHOD LO_EMAIL_BODY->ADD_ATTACHMENT(
            I_ATTACHMENT_TYPE    = 'BIN'
            I_ATT_CONTENT_HEX    = LT_CONTENTS_EXCEL
            I_ATTACHMENT_SIZE    = LV_SIZE
            I_ATTACHMENT_SUBJECT = LV_DESCR ).
      CATCH CX_DOCUMENT_BCS.

    ENDTRY.
  ENDIF.

  " 新增发送多个附件功能,按表传进来循环处理  
  LOOP AT  IT_CONTENT_HEX INTO DATA(LS_CONTENT_HEX).
    TRY.
        CALL METHOD LO_EMAIL_BODY->ADD_ATTACHMENT(
            I_ATTACHMENT_TYPE    = 'BIN'
            I_ATT_CONTENT_HEX    = LS_CONTENT_HEX-EXCEL
            I_ATTACHMENT_SIZE    = LS_CONTENT_HEX-SIZE
            I_ATTACHMENT_SUBJECT = LS_CONTENT_HEX-DESCR ).
      CATCH CX_DOCUMENT_BCS.

    ENDTRY.
  ENDLOOP.

  IF NOT IM_XSTRING IS INITIAL.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        BUFFER          = IM_XSTRING
        APPEND_TO_TABLE = ABAP_TRUE
      IMPORTING
        OUTPUT_LENGTH   = L_PDF_LEN
      TABLES
        BINARY_TAB      = LT_CONTENTS_DOC.
    IF IM_ATTACHMENT_SUBJECT IS INITIAL.
      CONCATENATE IM_SUBJECT '.XLSX' INTO LV_DESCR.
    ELSE.
      LV_DESCR = IM_ATTACHMENT_SUBJECT.
    ENDIF.
    TRY.
        CALL METHOD LO_EMAIL_BODY->ADD_ATTACHMENT(
            I_ATTACHMENT_TYPE    = 'BIN'
            I_ATT_CONTENT_HEX    = LT_CONTENTS_DOC
            I_ATTACHMENT_SIZE    = LV_SIZE
            I_ATTACHMENT_SUBJECT = LV_DESCR ).
      CATCH CX_DOCUMENT_BCS.

    ENDTRY.
  ENDIF.

  IF NOT IM_CONTENT_DOC[] IS INITIAL.
**附件DOC
    APPEND LINES OF IM_CONTENT_DOC TO LT_CONTENTS.
    CONCATENATE IM_SUBJECT '.DOC' INTO LV_DESCR.
    TRY.
        CALL METHOD LO_EMAIL_BODY->ADD_ATTACHMENT(
            I_ATTACHMENT_TYPE    = 'DOC'
            I_ATT_CONTENT_HEX    = LT_CONTENTS
*           i_attachment_size    = lv_size
            I_ATTACHMENT_SUBJECT = LV_DESCR ).
      CATCH CX_DOCUMENT_BCS.
    ENDTRY.
  ENDIF.

  IF NOT IM_CONTENT_PNG[] IS INITIAL.
**附件为图片
    APPEND LINES OF IM_CONTENT_PNG TO LT_CONTENTS.
    CONCATENATE IM_SUBJECT '.PNG' INTO LV_DESCR.
    TRY.
        CALL METHOD LO_EMAIL_BODY->ADD_ATTACHMENT(
            I_ATTACHMENT_TYPE    = 'PNG'
            I_ATT_CONTENT_HEX    = LT_CONTENTS
*           i_attachment_size    = lv_size
            I_ATTACHMENT_SUBJECT = LV_DESCR ).
      CATCH CX_DOCUMENT_BCS.
    ENDTRY.
  ENDIF.
*END-OF-MODIFICATION---24.07.2017 15:28:09 ---------------------------------*

  LO_EMAIL = CL_BCS=>CREATE_PERSISTENT( ).
  LO_EMAIL->SET_DOCUMENT( LO_EMAIL_BODY ).

** 主送邮件地址设置
  LOOP AT IM_MAIL INTO DATA(LS_MAIL).
**    检查是否有包含集团邮箱后缀 @XXXXX.com,没有则追加
    IF LS_MAIL NS COS_MAIL_HZ.
      LS_MAIL = LS_MAIL && COS_MAIL.
    ENDIF.

    TRY.
        LO_RECEIVER = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( LS_MAIL ).
        LO_EMAIL->ADD_RECIPIENT( I_RECIPIENT = LO_RECEIVER ).
      CATCH CX_ADDRESS_BCS.

    ENDTRY.

  ENDLOOP.

** 业务专家邮件地址设置
  LOOP AT IT_EXPERTS ASSIGNING FIELD-SYMBOL(<FS_EXP>).
**    检查是否有包含 集团邮箱后缀 @XXXXX.com,没有则追加
    IF <FS_EXP>-LOW NS COS_MAIL_HZ.
      LS_MAIL = <FS_EXP>-LOW && COS_MAIL.
    ENDIF.

    TRY.
        LO_RECEIVER = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( LS_MAIL ).
        LO_EMAIL->ADD_RECIPIENT( I_RECIPIENT = LO_RECEIVER ).
      CATCH CX_ADDRESS_BCS.

    ENDTRY.

  ENDLOOP.

** CC邮件地址设置
  LOOP AT IM_CCMAIL INTO DATA(LS_CCMAIL).
**    检查是否有包含集团邮箱后缀 @XXXXX.com,没有则追加
    IF LS_CCMAIL NS COS_MAIL_HZ.
      LS_CCMAIL = LS_CCMAIL && COS_MAIL.
    ENDIF.

    TRY.
        LO_RECEIVER = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( LS_CCMAIL ).
        LO_EMAIL->ADD_RECIPIENT( I_RECIPIENT = LO_RECEIVER I_COPY = ABAP_TRUE ).
      CATCH CX_ADDRESS_BCS.
    ENDTRY.

  ENDLOOP.


** 密抄邮件地址设置
  LOOP AT IM_CCMAIL_BLIND INTO  LS_CCMAIL.
**    检查是否有包含集团邮箱后缀 @XXXXX.com,没有则追加
    IF LS_CCMAIL NS COS_MAIL.
      LS_CCMAIL = LS_CCMAIL && COS_MAIL.
    ENDIF.

    TRY.
        LO_RECEIVER = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( LS_CCMAIL ).
        LO_EMAIL->ADD_RECIPIENT( I_RECIPIENT = LO_RECEIVER I_COPY = ABAP_TRUE I_BLIND_COPY = ABAP_TRUE ).
      CATCH CX_ADDRESS_BCS.
    ENDTRY.

  ENDLOOP.

  "Set Sender and send mail
  TRY.
      LO_SENDER = CL_SAPUSER_BCS=>CREATE( IM_SENDER ).
    CATCH CX_ADDRESS_BCS.

  ENDTRY.

  LO_EMAIL->SET_SENDER( LO_SENDER ).
  LO_EMAIL->SET_STATUS_ATTRIBUTES( I_REQUESTED_STATUS = 'E' I_STATUS_MAIL = 'E' ).""不返回执邮件
**  立即发送
  TRY.
      CALL METHOD LO_EMAIL->SET_SEND_IMMEDIATELY
        EXPORTING
          I_SEND_IMMEDIATELY = 'X'.
    CATCH CX_SEND_REQ_BCS .
*RAISE cx_send_req_bcs.
  ENDTRY.

  TRY.
      CALL METHOD LO_EMAIL->SEND
        RECEIVING
          RESULT = L_SEND_RESULT.

      COMMIT WORK.

    CATCH CX_SEND_REQ_BCS INTO LO_CX_SEND_REQ_BCS.

  ENDTRY.


ENDFUNCTION.

邮件中图片的说明:

1. 邮件中显示的图片在SE80 MIME资源库PUBLIC路径下上传

 2. 用户email中有时会出现图片打不开的问题,有时需要手工点击邮件加载图片才能出来,

 需要检查outlook设置了图片拦截之类。

调用封装函数

  DATA lt_mail    TYPE  bcsy_smtpa.
  DATA ls_mail    LIKE  LINE OF lt_mail.
 "邮件
  DATA: lv_subject TYPE  so_obj_des, "主题
        lt_mail    TYPE  bcsy_smtpa, "收件人
        lt_mail_cc TYPE  bcsy_smtpa, "抄送人
        ls_mail    LIKE  LINE OF lt_mail.

  "附件
  DATA : lt_excel      TYPE  ztexcel_fj,
         lv_excel_name TYPE string, "EXCEL 附件名
         lv_xstring1   TYPE xstring, "附件一
         lv_xstring2   TYPE xstring, "附件二
         lv_xstring3   TYPE xstring. "附件三.

  DATA:lv_row_1 TYPE zexcel_cell_row.
  DATA:lv_row_2 TYPE zexcel_cell_row.
  "读取EXCEL
  DATA: lo_excel_reader1 TYPE REF TO zif_excel_reader,
        lo_excel_reader2 TYPE REF TO zif_excel_reader,
        lo_excel_reader3 TYPE REF TO zif_excel_reader.
*  DATA LO__EXCEL_WORKSHEET TYPE REF TO ZCL_EXCEL_WORKSHEET .
  "style类
  DATA:lo_style TYPE REF TO zcl_excel_style.
  DATA:lv_style_guid TYPE zexcel_cell_style."style的guid
  "border类-边框
  DATA:lo_border TYPE REF TO zcl_excel_style_border.

  DATA:lv_sender TYPE syst_uname.
  lv_sender = 'V-XXXX'."发送人

  DATA: lv_content TYPE string .
 
  ls_mail = sy-uname && '@126.COM'.
  COLLECT ls_mail INTO pt_mail_cc.

    "转换为二进制
    "附件1
"写到EXCEL 按页签名获取页签
    DATA(lo_worksheet_1_1) = lo_excel1->get_worksheet_by_name( ip_sheet_name = '月度XX统计' ). "附件1 页签1
    DATA(lo_worksheet_1_2) = lo_excel1->get_worksheet_by_name( ip_sheet_name = 'XXX明细表' )."附件1 页签2

      "填充EXCEL 附件1 页签2
      lv_row_1 = lv_row_1 + 1 .
      lo_worksheet_1_2->set_cell( ip_column = 'A'  ip_row = lv_row_1 ip_style = lv_style_guid ip_value = ls_data_mx-bukrs   ). "公司
      lo_worksheet_1_2->set_cell( ip_column = 'B'  ip_row = lv_row_1 ip_style = lv_style_guid ip_value = ls_data_mx-butxt   ). "公司名称
      lo_worksheet_1_2->set_cell( ip_column = 'C'  ip_row = lv_row_1 ip_style = lv_style_guid ip_value = ls_data_mx-sqdnr   ). "申请单号
      lo_worksheet_1_2->set_cell( ip_column = 'D'  ip_row = lv_row_1 ip_style = lv_style_guid ip_value = ls_data_mx-fkdnr   ). "付款单号
      lo_worksheet_1_2->set_cell( ip_column = 'E'  ip_row = lv_row_1 ip_style = lv_style_guid ip_value = ls_data_mx-zfllx   ). "类型分类
      lo_worksheet_1_2->set_cell( ip_column = 'F'  ip_row = lv_row_1 ip_style = lv_style_guid ip_value = ls_data_mx-zfllx_t ). "类型分类描述
      lo_worksheet_1_2->set_cell( ip_column = 'G'  ip_row = lv_row_1 ip_style = lv_style_guid ip_value = ls_data_mx-cttnr   ). "合同编码
      lo_worksheet_1_2->set_cell( ip_column = 'H'  ip_row = lv_row_1 ip_style = lv_style_guid ip_value = ls_data_mx-ctgdnr  ). "合同归档编号
      lo_worksheet_1_2->set_cell( ip_column = 'I'  ip_row = lv_row_1 ip_style = lv_style_guid ip_value = ls_data_mx-cgjhx   ). "合同名称

    lv_excel_name = '附件1-' && p_month+0(4) && '年' && p_month+4(2) && '月XX情况统计报告-' && ls_bukrs-nupnm && '.xlsx'.
    PERFORM frm_excel_to_binary USING lt_excel lo_excel1 lv_excel_name .

    "正文
    lv_content =   '<html>'
                   && '<head>'
                   && '<meta http-equiv="Content-Type" content="text/html;charset=gb2312">'
                   && '</head>'
                   && '<body>'
                   && '<font face="楷体";size="3"; style="text-indent:2em ; line-height:180%" >'
                   && '<small>各位领导好,<br/>'
                   && '&nbsp&nbsp&nbsp&nbsp每个月将下发XX月度分析报告。'
                   && p_month+0(4) &&'年'&& p_month+4(2) &&'月XX分析报告如下:<br/>'.

    "拼接正文lv_content 

  CALL FUNCTION 'ZFIFM_0164'
      EXPORTING
        im_mail_content = lv_content
        im_subject      = lv_subject
        im_sender       = lv_sender
        im_mail         = lt_mail
        im_ccmail       = lt_mail_cc
*       im_xstring      = lv_xstring.
        it_content_hex  = lt_excel[]
*       IM_EXCEL_SIZE   = LV_SIZE.
    IF  sy-subrc = 0 .
    ENDIF.




*&---------------------------------------------------------------------*
*&      Form  FRM_EXCEL_TO_BINARY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_excel_to_binary USING pt_excel TYPE ztexcel_fj
                               po_excel TYPE REF TO zcl_excel
                               pv_excel_name .

  "转换为二进制
  DATA: lv_file         TYPE xstring,
        lv_bytecount    TYPE i,
        lv_xstring      TYPE  xstring,
        lo_excel_writer TYPE REF TO zif_excel_writer,
        lt_file_tab     TYPE solix_tab.
  CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.

  DATA lv_excelname TYPE string .

  lv_file = lo_excel_writer->write_file( po_excel ).

  lv_xstring = lv_file.

  " Convert to binary
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer        = lv_file
    IMPORTING
      output_length = lv_bytecount
    TABLES
      binary_tab    = lt_file_tab.

*    LT_EXCEL[] = LT_FILE_TAB[].
  DATA  lv_size TYPE so_obj_len.
  lv_size = lv_bytecount.

  APPEND INITIAL LINE TO pt_excel[] ASSIGNING FIELD-SYMBOL(<lfs_excel>) .
  <lfs_excel>-excel[] = lt_file_tab[] .
  <lfs_excel>-size = lv_size .
  <lfs_excel>-descr = pv_excel_name .

ENDFORM.

应用2

1.SE37创建FUNCTION :Z_COM_AUTO_MAIL

2. Import 参数。

3.Export 参数

4.table参数

5.table参数中ZTMAILADD邮件地址表参数,SE11创建表类型ZTMAILADD

SE11创建结构ZSMAILADD

SE11创建数据元素

SE11创建域

6. 源码如下: 

FUNCTION Z_COM_AUTO_MAIL.
*"----------------------------------------------------------------------
*"*"區域介面:
*"  IMPORTING
*"     REFERENCE(I_SUBJECT) TYPE  SO_OBJ_DES OPTIONAL
*"     REFERENCE(I_MAILTO) TYPE  CHAR255 OPTIONAL
*"     REFERENCE(I_MAILCC) TYPE  CHAR255 OPTIONAL
*"  EXPORTING
*"     VALUE(E_RETURN) TYPE  CHAR255
*"  TABLES
*"      T_MAILADD TYPE  ZTMAILADD OPTIONAL
*"      T_CONTENT TYPE  SOLI_TAB
*"      T_ATTACHMENT TYPE  SOLI_TAB OPTIONAL
*"----------------------------------------------------------------------
 
  DATA:LO_DOCUMENT      TYPE REF TO CL_DOCUMENT_BCS, "用来放发送的内容的类
       LIT_CONTENTS     TYPE SOLI_TAB,
       L_CC             TYPE ADR6-SMTP_ADDR,
       L_TO             TYPE ADR6-SMTP_ADDR,
       L_BCS_TO         TYPE REF TO IF_RECIPIENT_BCS,
       L_BCS_CC         TYPE REF TO IF_RECIPIENT_BCS,
       LO_SENDER        TYPE REF TO CL_SAPUSER_BCS,
       L_RESULT         TYPE OS_BOOLEAN,
*      cl_bcs发送邮件主要用到的功能类, 包括创建发送请求, 添加发送内容,添加发送地址, 到最终的发送指令发出.
       W_DOCUMENT       TYPE REF TO CL_BCS,
       L_FILE_SIZE_CHAR TYPE SO_OBJ_LEN,
       L_FILEN          TYPE STRING,
       LIT_MAILHEX      TYPE SOLIX_TAB,
       L_FILE_SIZE      TYPE I,
       L_RC             TYPE I,
       L_STRING         TYPE STRING,
       L_SUBJECT        TYPE SO_OBJ_DES,
*      cx_bcs异常类, 捕捉发送邮件过程中出现的异常.
       LO_FAIL          TYPE REF TO CX_BCS.
* 邮件正文
  LOOP AT T_CONTENT INTO L_STRING.
    APPEND L_STRING  TO LIT_CONTENTS.
  ENDLOOP.
  TRY.
*     CREATE THE DOCUMENT WITH CONTENTS
      CREATE OBJECT LO_DOCUMENT.
      LO_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
          I_TYPE       = 'HTM'
          I_SUBJECT    = I_SUBJECT  "邮件标题
          I_LENGTH     = L_FILE_SIZE_CHAR
          I_LANGUAGE   = SY-LANGU
          I_IMPORTANCE = '1'
          I_TEXT       = LIT_CONTENTS
          ).
 
* 附件类型为BIN接收任何类型的附件,包括视频、音频文件等。
* 读取附件
      IF T_ATTACHMENT IS NOT INITIAL.
        LOOP AT T_ATTACHMENT INTO DATA(P_FILE).
          L_FILEN = P_FILE.
          CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
            EXPORTING
              FILENAME                = L_FILEN
              FILETYPE                = 'BIN'  "
*             has_field_separator     = SPACE
*             header_length           = 0
*             read_by_line            = ''
*             dat_mode                = SPACE
*             codepage                = SPACE
*             ignore_cerr             = ABAP_TRUE
*             replacement             = '#'
*             virus_scan_profile      =
            IMPORTING
              FILELENGTH              = L_FILE_SIZE
*             header                  =
            CHANGING
              DATA_TAB                = LIT_MAILHEX
*             isscanperformed         = SPACE
            EXCEPTIONS
              FILE_OPEN_ERROR         = 1
              FILE_READ_ERROR         = 2
              NO_BATCH                = 3
              GUI_REFUSE_FILETRANSFER = 4
              INVALID_TYPE            = 5
              NO_AUTHORITY            = 6
              UNKNOWN_ERROR           = 7
              BAD_DATA_FORMAT         = 8
              HEADER_NOT_ALLOWED      = 9
              SEPARATOR_NOT_ALLOWED   = 10
              HEADER_TOO_LONG         = 11
              UNKNOWN_DP_ERROR        = 12
              ACCESS_DENIED           = 13
              DP_OUT_OF_MEMORY        = 14
              DISK_FULL               = 15
              DP_TIMEOUT              = 16
              NOT_SUPPORTED_BY_GUI    = 17
              ERROR_NO_GUI            = 18
              OTHERS                  = 19.
          IF SY-SUBRC <> 0.
            CASE SY-SUBRC.
              WHEN   '1' .
                E_RETURN = 'FILE_OPEN_ERROR         ' .
              WHEN   '2' .
                E_RETURN = 'FILE_READ_ERROR         ' .
              WHEN   '3' .
                E_RETURN = 'NO_BATCH                ' .
              WHEN   '4' .
                E_RETURN = 'GUI_REFUSE_FILETRANSFER ' .
              WHEN   '5' .
                E_RETURN = 'INVALID_TYPE            ' .
              WHEN   '6' .
                E_RETURN = 'NO_AUTHORITY            ' .
              WHEN   '7' .
                E_RETURN = 'UNKNOWN_ERROR           ' .
              WHEN   '8' .
                E_RETURN = 'BAD_DATA_FORMAT         ' .
              WHEN   '9' .
                E_RETURN = 'HEADER_NOT_ALLOWED      ' .
              WHEN   '10'.
                E_RETURN = 'SEPARATOR_NOT_ALLOWED   ' .
              WHEN   '11'.
                E_RETURN = 'HEADER_TOO_LONG         ' .
              WHEN   '12'.
                E_RETURN = 'UNKNOWN_DP_ERROR        ' .
              WHEN   '13'.
                E_RETURN = 'ACCESS_DENIED           ' .
              WHEN   '14'.
                E_RETURN = 'DP_OUT_OF_MEMORY        ' .
              WHEN   '15'.
                E_RETURN = 'DISK_FULL               ' .
              WHEN   '16'.
                E_RETURN = 'DP_TIMEOUT              ' .
              WHEN   '17'.
                E_RETURN = 'NOT_SUPPORTED_BY_GUI    ' .
              WHEN   '18'.
                E_RETURN = 'ERROR_NO_GUI            ' .
              WHEN OTHERS.
                E_RETURN = 'OTHERS mistake' .
            ENDCASE.
* Implement suitable error handling here
            RETURN.
          ENDIF.
* 附件长度,这个很重要,一定要有
          L_FILE_SIZE_CHAR = L_FILE_SIZE_CHAR.
*     获取附件名字及附件文件类型
          DATA(L_FILE) = P_FILE .
          DO .
            SPLIT L_FILE AT '\' INTO DATA(LV_TMP) L_FILE .
            SEARCH L_FILE FOR '\' .
            IF SY-SUBRC <> 0.
              EXIT .
            ENDIF.
          ENDDO.
          L_SUBJECT = L_FILE .
*     添加附件,可以添加多个附件
          CALL METHOD LO_DOCUMENT->ADD_ATTACHMENT
            EXPORTING
              I_ATTACHMENT_TYPE    = 'BIN'
              I_ATTACHMENT_SUBJECT = L_SUBJECT         "附件名称
              I_ATTACHMENT_SIZE    = L_FILE_SIZE_CHAR  "附件大小
              I_ATT_CONTENT_HEX    = LIT_MAILHEX.      "附件内容
        ENDLOOP.
      ENDIF.
*     CREATING PERSISTENT OBJECT WILL ALLOW YOU TO SET THE DOCUMENT IN THE MAIL
      W_DOCUMENT = CL_BCS=>CREATE_PERSISTENT( ).
*     发件人
*     前提是这个邮箱地址能发邮件,并且不需要密码
      LO_SENDER = CL_SAPUSER_BCS=>CREATE( SY-UNAME ).
      W_DOCUMENT->SET_SENDER( LO_SENDER ).
 
*     收件人
      IF I_MAILTO IS NOT INITIAL.
        L_TO = I_MAILTO.
        L_BCS_TO = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( L_TO ).
*     Add recipient to send request
        CALL METHOD W_DOCUMENT->ADD_RECIPIENT
          EXPORTING
            I_RECIPIENT = L_BCS_TO.
      ENDIF.
*    抄送人
      IF I_MAILCC IS NOT INITIAL.
        L_CC = I_MAILCC.  "
        L_BCS_CC = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( L_CC ).
        CALL METHOD W_DOCUMENT->ADD_RECIPIENT
          EXPORTING
            I_RECIPIENT = L_BCS_CC
            I_COPY      = 'X'.
        " i_express   = 'X'.
      ENDIF.
      "邮件地址表有值。
      IF T_MAILADD IS NOT INITIAL.
        LOOP AT T_MAILADD INTO DATA(LS_MAILADD).
          IF LS_MAILADD-MAILTYPE = 'T'.
            L_TO = LS_MAILADD-MAILADDR.
            L_BCS_TO = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( L_TO ).
*     Add recipient to send request
            CALL METHOD W_DOCUMENT->ADD_RECIPIENT
              EXPORTING
                I_RECIPIENT = L_BCS_TO.
          ELSEIF LS_MAILADD-MAILTYPE = 'C'.
            L_CC = LS_MAILADD-MAILADDR.  "
            L_BCS_CC = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( L_CC ).
 
            CALL METHOD W_DOCUMENT->ADD_RECIPIENT
              EXPORTING
                I_RECIPIENT = L_BCS_CC
                I_COPY      = 'X'.
            " i_express   = 'X'.
          ENDIF.
        ENDLOOP.
      ENDIF.
*     SEND THE MAIL
      W_DOCUMENT->SET_SEND_IMMEDIATELY( 'X' ).  "设置立即发送
      W_DOCUMENT->SEND_REQUEST->SET_LINK_TO_OUTBOX( 'X' ). "与outbox关联
      CALL METHOD W_DOCUMENT->SET_DOCUMENT( LO_DOCUMENT ).
      CALL METHOD W_DOCUMENT->SEND(
        EXPORTING
          I_WITH_ERROR_SCREEN = 'X'
        RECEIVING
          RESULT              = L_RESULT ).
    CATCH CX_BCS INTO LO_FAIL.
  ENDTRY.
* YOU CAN VERIFY THE STATUS IN THE LIST, YOU CAN ALSO SUBMIT THIS AS A BACKGROUND JOB.
  IF L_RESULT = 'X'.
    COMMIT WORK AND WAIT.
  ELSE.
    ROLLBACK WORK.
    E_RETURN = '发送失败' .
  ENDIF.
ENDFUNCTION.

邮件附件表可添加多个附件及多个不同的邮件种类,ABAP获取附件的方法可查看另一篇博文:ABAP选择本地文件,获取文件地址

以上,function已经创建完成,可以使用了。返回消息为空就代表发送成功了。下面我们创建将测试程序。

se38创建测试程序(代码中的邮件地址改为自己的哟,目前为本人邮箱)。

*&---------------------------------------------------------------------*
*& Report ZLQT_COM_AUTO_MAIL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLQT_COM_AUTO_MAIL.
 
DATA I_SUBJECT    TYPE SO_OBJ_DES .              "邮件主题
DATA I_MAILTO     TYPE CHAR255    .              "收件人
DATA I_MAILCC     TYPE CHAR255    .              "抄送
DATA E_RETURN     TYPE CHAR255    .              "返回消息
DATA T_MAILADD    TYPE TABLE OF ZSMAILADD WITH HEADER LINE   .   "邮件地址表
DATA T_CONTENT    TYPE TABLE OF SOLI      WITH HEADER LINE   .   "邮件正文内容
DATA T_ATTACHMENT TYPE TABLE OF SOLI      WITH HEADER LINE   .   "邮件附件地址
I_SUBJECT = '邮件主题' .
*T_MAILADD-MAILTYPE = 'T' .
*T_MAILADD-MAILADDR = '[email protected]' .
*APPEND T_MAILADD .
*
*T_MAILADD-MAILTYPE = 'C' .
*T_MAILADD-MAILADDR = '[email protected]' .
*APPEND T_MAILADD .
I_MAILTO  = '[email protected]'.
I_MAILCC  = '[email protected]' .
T_CONTENT-LINE = SY-UNAME && SY-DATUM  .
APPEND T_CONTENT .
T_ATTACHMENT-LINE = 'C:\Users\szmis11\Desktop\WeChat 圖片_202]]]]]01109190311.jpg' .
APPEND T_ATTACHMENT.
T_ATTACHMENT-LINE = 'C:\Users\szmis11\Desktop\automail.docx' .
APPEND T_ATTACHMENT.
CALL FUNCTION 'Z_COM_AUTO_MAIL'
 EXPORTING
   I_SUBJECT          = I_SUBJECT
   I_MAILTO           = I_MAILTO
   I_MAILCC           = I_MAILCC
 IMPORTING
   E_RETURN           = E_RETURN
  TABLES
    T_MAILADD          = T_MAILADD
    T_CONTENT          = T_CONTENT
    T_ATTACHMENT       = T_ATTACHMENT
          .
WRITE : E_RETURN .

以上为-自动发邮件FUNCTION,AUTOMAIL功能全部内容,若代码存在问题,欢迎评论指正。

应用3

邮件内容形式比如:

排名统计类晾晒邮件:

FUNCTION zplfm_zznotice_email.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(IV_ZZGUID) TYPE  ZTPL0050-ZZGUID
*"  EXPORTING
*"     VALUE(EV_SENT) TYPE  CHAR1
*"----------------------------------------------------------------------
  DATA:BEGIN OF ls_uname,
         ver_inner     TYPE ztpp0001-ver_inner,
         bbnum         TYPE      i,
         timestamp_upd TYPE     ztpp0001-timestamp_upd,
         uname         TYPE      ztpp0001-uname,
         posid         TYPE      ztpp0002-posid,
         post1         TYPE      ztpp0002-post1,
       END OF ls_uname.
  DATA lt_uname LIKE TABLE OF ls_uname.
  DATA lt_ldnumt TYPE zspl0010_t.
  DATA ls_ldnumt TYPE zspl0010.
  DATA lt_pernr TYPE zcl_wd_pl_c017_r05=>tt_pernr.
  DATA ls_pernr TYPE zcl_wd_pl_c017_r05=>ty_pernr.
  DATA lt_csr TYPE zcl_wd_pl_c017_r05=>tt_csr.
  DATA lv_appnam TYPE string.
  DATA:im_para TYPE  tihttpnvp,
       is_para TYPE  ihttpnvp.
  DATA:ls_url TYPE string,
       ls_par TYPE string.
  DATA lt_urls TYPE ztmail02.
  DATA lt_wfs_person TYPE zpst_employee.
  DATA ls_wfs_person TYPE zpss_employee.
  DATA lv_key TYPE string.
  DATA lv_lines TYPE sy-tabix.
  DATA lv_hname1 TYPE ze_hname.
  DATA lt_mjcy  TYPE ziwci_wd_pl_c004_newbz=>elements_nd_mjcy.
  DATA ls_mjcy  TYPE ziwci_wd_pl_c004_newbz=>element_nd_mjcy.
  DATA lo_pl_c004_newbz TYPE REF TO zcl_wd_pl_c004_newbz.

  CREATE OBJECT lo_pl_c004_newbz.

  "取证照下的楼栋
  SELECT ztpl0051~zzguid,
         ztpl0051~linkid,
         ztpl0050~zzlx,
         ztpl0050~loaddat,"add by c-zhabl01 at 20220720 for yisz:增加上传人的显示
         ztpl0050~loadusr,"add by c-zhabl01 at 20220720 for yisz:增加上传人的显示
         ztpl0050~loadusr_v,"add by c-zhabl01 at 20220720 for yisz:增加上传人的显示
         ztpl0051~ldnum,
         ztpl0051~pspid,      "add by yisz
         prps~post1 AS ldnam   "add by yisz 2022/10/20
    FROM ztpl0051
    INNER JOIN ztpl0050 ON ztpl0050~zzguid = ztpl0051~zzguid
    INNER JOIN prps ON prps~posid = ztpl0051~ldnum
    WHERE ztpl0050~zzguid = @iv_zzguid
    AND prps~stufe = 3
    INTO TABLE @DATA(lt_ldnum).
  IF sy-subrc EQ 0.

    DATA(lv_ldnum) = lt_ldnum[ 1 ]-ldnum.
    DATA(lv_zzlx) = lt_ldnum[ 1 ]-zzlx.
    DATA(lv_loaddat) = lt_ldnum[ 1 ]-loaddat.  "add by c-zhabl01 at 20220720 for yisz:增加上传人的显示
    DATA(lv_loadusr) = lt_ldnum[ 1 ]-loadusr.   "add by c-zhabl01 at 20220720 for yisz:增加上传人的显示

    "楼栋所属项目
    SELECT SINGLE psphi
      FROM prps
      WHERE posid = @lv_ldnum
      INTO @DATA(lv_psphi).
    IF sy-subrc EQ 0.
      SELECT SINGLE posid,fbukrs,post1
        FROM prps
        WHERE psphi = @lv_psphi
          AND stufe = '1'
        INTO ( @DATA(lv_posid_xm),@DATA(lv_fbukrs),@DATA(lv_post1)  ).
      IF sy-subrc EQ 0.

        "取楼栋的最新阶段,只有当最新阶段小于当前证照对应的阶段时,才发邮件提醒
        DATA(lv_step_id_n) = zcl_pl_asset_tag_service=>get_step_id_by_zzlx( CONV string( lv_zzlx ) ).

        SELECT ztpp0002~posid,
               ztpp0002~step_id,
               ztpp0001~bbnum,
               ztpp0002~ver_inner
          FROM ztpp0002
          INNER JOIN ztpp0001 ON ztpp0001~ver_inner = ztpp0002~ver_inner
          FOR ALL ENTRIES IN @lt_ldnum
          WHERE ztpp0001~bbstat IN ( 'AP','IN' )
            AND ztpp0002~posid = @lt_ldnum-ldnum
          INTO TABLE @DATA(lt_step_id).
        IF sy-subrc EQ 0.
          SORT lt_step_id BY posid bbnum DESCENDING.
          DELETE ADJACENT DUPLICATES FROM lt_step_id COMPARING posid.
        ENDIF.

        CLEAR lt_ldnumt[].
        LOOP AT lt_ldnum INTO DATA(ls_ldnum).
          DATA(lv_tabix) = sy-tabix.

          READ TABLE lt_step_id INTO DATA(ls_step_id) WITH KEY posid = ls_ldnum-ldnum.
          IF sy-subrc NE 0.
            CLEAR ls_step_id.
          ENDIF.

          IF ls_step_id IS INITIAL OR ls_step_id-step_id GE lv_step_id_n OR ls_ldnum-ldnum IS INITIAL.
            DELETE lt_ldnum INDEX lv_tabix.
          ENDIF.

          CLEAR ls_ldnumt.
          ls_ldnumt-ldnum = ls_ldnum-ldnum.
          ls_ldnumt-ldnam = ls_ldnum-ldnam.
          APPEND ls_ldnumt TO lt_ldnumt.
        ENDLOOP.

        CHECK lt_ldnum IS NOT INITIAL.
        "项目的最新版本
        SELECT ztpp0001~ver_inner,
               ztpp0001~bbnum,
               ztpp0001~timestamp_upd,
               ztpp0001~uname,
               ztpp0002~posid,
               ztpp0002~post1
          FROM ztpp0002
          INNER JOIN ztpp0001 ON ztpp0001~ver_inner = ztpp0002~ver_inner
          WHERE ztpp0002~posid = @lv_posid_xm
          INTO TABLE @DATA(lt_uname_c).
        IF sy-subrc EQ 0.

          LOOP AT lt_uname_c INTO DATA(ls_uname_c).
            ls_uname_c-bbnum = zcl_pl_asset_tag_service=>read_0_to_z( iv_source = |{ ls_uname_c-bbnum }| iv_separator = 'V' iv_direction = 'A' iv_deep_reading = 'X' ).
            IF ls_uname_c-bbnum IS INITIAL.
              ls_uname_c-bbnum = 0.
            ENDIF.

            CLEAR ls_uname.
            MOVE-CORRESPONDING ls_uname_c TO ls_uname.
            APPEND ls_uname TO lt_uname.
          ENDLOOP.
          SORT lt_uname BY bbnum DESCENDING timestamp_upd DESCENDING.

          REFRESH lt_mjcy.
          CLEAR ls_uname.
          READ TABLE lt_uname INTO ls_uname INDEX 1.
          IF sy-subrc EQ 0.
            lo_pl_c004_newbz->get_mjcy(
                  EXPORTING
                    iv_ver_inner      = ls_uname-ver_inner   "项目最新版本
                    iv_zzlx = lv_zzlx          "发邮件的后台job的程序只留下工规证 云效:424267
                 IMPORTING
                    et_mjcy           =  lt_mjcy
             ).
            "delete lt_mjcy where ldfw ns ls_xm-posid.
          ENDIF.

          CHECK lt_mjcy IS NOT INITIAL.     "没有差异,不发邮件提醒

          "获取超链接地址
          DATA lt_param TYPE tihttpnvp.
          DATA ls_param TYPE ihttpnvp.
          ls_param-name = 'POSID'.
          ls_param-value = ls_uname-posid.
          APPEND ls_param TO lt_param.

          ls_param-name = 'SYSFR'.
          ls_param-value = 'MJJHMAIL'.
          APPEND ls_param TO lt_param.

          ls_param-name = 'LDNUM'.
          ls_param-value = lt_mjcy[ 1 ]-ldfw.
          APPEND ls_param TO lt_param.


          DATA(lv_title) = |{ ls_uname-post1 }{ ls_uname-bbnum }项目详情|.

          DATA(lv_url) = ||.

          CALL FUNCTION 'ZPORTALFM_001'
            EXPORTING
              im_appnam = 'ZWD_PL_C004_NEWBZ_DIS'
              im_para   = lt_param
              im_title  = lv_title
            IMPORTING
              ev_url    = lv_url.

          "取收件人
          "ADD BY YISZ 2022/10/19 增加项目人员配置的收件人/抄送人,邮件的收件人,优先取配置表的
          SELECT *
            INTO TABLE @DATA(lt_ztpl0058n)
            FROM ztpl0058n
            WHERE fqnum = @lv_posid_xm.
          IF sy-subrc EQ 0.
            LOOP AT lt_ztpl0058n ASSIGNING FIELD-SYMBOL(<lfs_0058n>).
              TRANSLATE <lfs_0058n>-mail TO UPPER CASE.
            ENDLOOP.

            SORT lt_ztpl0058n BY rercc pernr mail.
            DELETE ADJACENT DUPLICATES FROM lt_ztpl0058n COMPARING rercc pernr mail."modify by c-zhabl01 at 20221122 :避免收件人重复
          ENDIF.

          DATA(lv_receiver_name) = ||.

          LOOP AT lt_ztpl0058n INTO DATA(ls_ztpl0058n) WHERE rercc = 'R'.
            CLEAR ls_pernr.
            ls_pernr-email = ls_ztpl0058n-mail.
            ls_pernr-pernr = ls_ztpl0058n-pernr.
            APPEND ls_pernr TO lt_pernr.

            lv_receiver_name = |{ lv_receiver_name }/{ ls_ztpl0058n-ename }|.
          ENDLOOP.

          "MARK BY YISZ 2022/10/25 BEGIN
*          LOOP AT lt_uname INTO ls_uname.
*            DATA(ls_fiout) = VALUE zsfm0035_fi( ).
*            CALL FUNCTION 'ZPLFM_0035'
*              EXPORTING
*                uname = ls_uname-uname
*                otype = 'U'
*              IMPORTING
*                fiout = ls_fiout.
*
*            IF ls_fiout-yx_hcode EQ lv_fbukrs.
*              EXIT.
*            ENDIF.
*          ENDLOOP.
          "MARK BY YISZ 2022/10/25 END


*          根据证照关联的楼栋,找到对应的项目,根据ZTPP0001里面的最后更新人(更新人判断:根据项目的所属一线公司,取ZTPP0001的版本倒序查找,判断更新人的组织是否一致,若不一致,则继续查找上一版本的最后更新人,直至组织一致为止)、
          "ADD BY YISZ 2022/10/25 BEGIN
          "解决问题:ZTPP0001-uname有的存的不是域账号而是姓名,导致找不到邮箱地址
          IF lt_pernr IS INITIAL.
            DELETE lt_uname WHERE uname = 'SYSADM' OR uname = 'S_PI_SERVICE' OR uname CS 'ERP'.
            LOOP AT lt_uname INTO ls_uname.
              DATA(ls_fiout) = VALUE zsfm0035_fi( ).
              IF cl_abap_matcher=>matches( pattern = '[a-z|A-Z]*-?[a-z|A-Z]*[0-9?]*' text = ls_uname-uname ).
                "域账号
                CALL FUNCTION 'ZPLFM_0035'
                  EXPORTING
                    uname = ls_uname-uname
                    otype = 'U'
                  IMPORTING
                    fiout = ls_fiout.
                IF ls_fiout-yx_hcode IS NOT INITIAL.
                  IF ls_fiout-yx_hcode EQ lv_fbukrs.  "找到一个属于当前项目所属公司的用户,退出,作为收件人
                    EXIT.
                  ENDIF.
                ENDIF.
              ELSE.
                "通过姓名查询出人员域账号;姓名重名时,通过项目所属的一线公司过滤
                CLEAR:  lv_key,lt_wfs_person[],lv_lines.
                lv_key = ls_uname-uname.

                CALL FUNCTION 'ZPLFM_0025A'
                  EXPORTING
                    iv_key        = lv_key
                  IMPORTING
                    it_wfs_person = lt_wfs_person[].

                CLEAR ls_wfs_person.
                DELETE lt_wfs_person WHERE ename NE lv_key.
                DESCRIBE TABLE lt_wfs_person LINES lv_lines.
                IF lv_lines > 1.

                  "非一线公司的人员,yx_hcode为空
                  LOOP AT lt_wfs_person INTO ls_wfs_person.
                    IF ls_wfs_person-yx_hcode IS NOT INITIAL.
                      DELETE lt_wfs_person WHERE yx_hcode NS lv_fbukrs.
                    ELSEIF ls_wfs_person-bm_stext IS NOT INITIAL.
                      CLEAR lv_hname1.
                      SELECT SINGLE hname INTO lv_hname1 FROM ztfi0005 WHERE hcode = lv_fbukrs AND ntype = 'C'.
                      DELETE lt_wfs_person WHERE bm_stext NS lv_hname1+0(2).
                    ENDIF.
                  ENDLOOP.
                ENDIF.
                "通过一线公司过滤还存在多个重名时,同一个合作方用户的历史无效账号去掉
                DELETE lt_wfs_person WHERE uname CS 'H-' OR uname CS 'V-'.
                READ TABLE lt_wfs_person INTO ls_wfs_person INDEX 1.
                IF sy-subrc = 0.
*                  modify by c-zhabl01 at 20221116 :取不到收件人名称问题修复---begin
                  "优先取配置表的
*                  clear ls_ztpl0058n.
*                  read table lt_ztpl0058n into ls_ztpl0058n with key mail = ls_fiout-mail.
*                  if sy-subrc = 0.
*                    clear ls_fiout.
*                    exit.
*                  else.
*                    ls_fiout-mail = ls_wfs_person-mail.
                  IF ls_wfs_person-yx_hcode EQ lv_fbukrs.
                    ls_fiout-mail = ls_wfs_person-mail.
                    ls_fiout-ename = ls_wfs_person-ename.
                    EXIT.
                  ENDIF.
*                  endif.
*                  modify by c-zhabl01 at 20221116 :取不到收件人名称问题修复---end

                ENDIF.
              ENDIF.
            ENDLOOP.

            IF ls_fiout-mail IS NOT INITIAL.
              lt_pernr = VALUE #( ( email = |{ ls_fiout-mail }| uname = |{ ls_fiout-uname }| ) ).
            ELSE.
              IF ls_fiout-uname IS NOT INITIAL.
                lt_pernr = VALUE #( ( email = |{ ls_fiout-uname }@VANKE.COM|  uname = |{ ls_fiout-uname }| ) ).
              ENDIF.
            ENDIF.

            IF ls_fiout-ename IS NOT INITIAL.
              lv_receiver_name = |{ lv_receiver_name }/{ ls_fiout-ename }|.
            ENDIF.
*            clear ls_fiout.
          ENDIF.
          "ADD BY YISZ 2022/10/25 END

          CHECK lt_pernr IS NOT INITIAL.   "找到收件人了,发送邮件

          IF lv_receiver_name IS NOT INITIAL AND lv_receiver_name+(1) EQ '/'.
            lv_receiver_name = lv_receiver_name+1.
          ENDIF.

          IF sy-sysid EQ 'ED1'.
            lt_csr = VALUE #( BASE lt_csr ( email = |[email protected]| ) ).
          ENDIF.

          IF sy-sysid+0(2) EQ 'EP'.
            lt_csr = VALUE #( BASE lt_csr ( email = |[email protected]| ) ).
            lt_csr = VALUE #( BASE lt_csr ( email = |[email protected]| ) ).
            lt_csr = VALUE #( BASE lt_csr ( email = |[email protected]| ) ).
            lt_csr = VALUE #( BASE lt_csr ( email = |[email protected]| ) ).
          ENDIF.
          lt_csr = VALUE #( BASE lt_csr ( email = |[email protected]| ) ).
*          lt_csr = VALUE #( BASE lt_csr ( email = |[email protected]| ) ).

          DATA(lv_subject) = CONV so_obj_des( |项目阶段面积校核提醒| ).
          DATA(lt_main_text) = VALUE bcsy_text( ).

          DATA(lv_ld) = ||.
          LOOP AT lt_ldnum INTO ls_ldnum.
            lv_ld = |{ lv_ld }/{ ls_ldnum-ldnum }【{ ls_ldnum-ldnam }】|.
          ENDLOOP.

          IF lv_ld IS NOT INITIAL.
            lv_ld = lv_ld+1.
          ENDIF.

          DATA(lv_ddtext) = VALUE dd07v-ddtext( ).
          CALL FUNCTION 'DOMAIN_VALUE_GET'
            EXPORTING
              i_domname  = 'ZD_ZZLX'
              i_domvalue = CONV dd07v-domvalue_l( lv_zzlx )
            IMPORTING
              e_ddtext   = lv_ddtext
            EXCEPTIONS
              not_exist  = 1
              OTHERS     = 2.
          IF sy-subrc <> 0.
* Implement suitable error handling here
          ENDIF.

*--- add by c-zhabl01 at 20220720 for yisz:增加上传人的显示---begin
          DATA(ls_fiout_load) = VALUE zsfm0035_fi( ).
          CALL FUNCTION 'ZPLFM_0035'
            EXPORTING
              pernr = lv_loadusr
              otype = 'P'
            IMPORTING
              fiout = ls_fiout_load.
*---add by c-zhabl01 at 20220720 for yisz:增加上传人的显示---end

          DATA(lv_yjzw) = ||.

          "证照面积差异明细显示在邮件正文 2022/8/15 yisz add begin
          lv_yjzw =  |{ lv_yjzw }<body lang=ZH-CN link="#0563C1" vlink="#954F72" style='text-justify-trim:punctuation'><div class=WordSection1>|.
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal style='margin-right:3.75pt;line-height:150%'>{ lv_receiver_name },您好!</p>|.


          "正文第一段
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal style='mso-margin-top-alt:0cm;margin-right:3.75pt;margin-bottom:0cm;margin-left:12.15pt;margin-bottom:.0001pt;text-indent:12.0pt;line-height:150%'>|.
          lv_yjzw =  |{ lv_yjzw }依据<b>《销售型物业数据管理办法》</b>,为确保成本财务核算及资源统计的准确,需参照法定证照,及时维护<span lang=EN-US>ICP</span>系统面积指标。<span lang=EN-US><o:p></o:p></span></p>|.

          "第二段
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal style='margin-left:12.15pt;text-indent:8.85pt;line-height:150%'>|.
          lv_yjzw =  |{ lv_yjzw }系统通过自动比对发现,项目<b>【{ lv_posid_xm } { lv_post1 }】</b>如下楼栋存在面积差异,请点击<span lang=EN-US><a href="|.


          lv_yjzw =  |{ lv_yjzw }{ lv_url }|.

          lv_yjzw =  |{ lv_yjzw }" target="_blank"><strong><span lang=EN-US style='font-size:10.5pt;line-height:150%;font-family:宋体;color:blue'><span lang=EN-US>项目主数据管理</span></span></strong></a>|.
          lv_yjzw =  |{ lv_yjzw }去校核及更新面积|.
          lv_yjzw =  |{ lv_yjzw }</span><span style='font-size:10.5pt;line-height:150%'>。</span>|.
          lv_yjzw =  |{ lv_yjzw }<span lang=EN-US style='font-size:10.5pt;line-height:150%;font-family:"Songti SC",serif'><o:p></o:p></span></p>|.

          "第三段
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal style='margin-left:12.15pt;text-indent:8.85pt;line-height:150%'><span style='color:black'>系统操作指引请参考:</span>|.
          lv_yjzw =  |{ lv_yjzw }<span lang=EN-US><a href="https://yun.vanke.com/l/b1ka45" target="_blank"><span style='font-family:"Songti SC",serif'>https://yun.vanke.com/l/b1ka45</span></a>|.
          lv_yjzw =  |{ lv_yjzw }</span><span style='color:black'>。</span> <span lang=EN-US><o:p></o:p></span></p>|.

          "列表
          lv_yjzw =  |{ lv_yjzw }<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=961 style='width:721.0pt;margin-left:21.3pt;border-collapse:collapse'>|.
          lv_yjzw =  |{ lv_yjzw }<tr style='height:30.0pt'><td width=117 style='width:88.0pt;border:solid windowtext 1.0pt;background:#F2F2F2;padding:0cm 5.4pt 0cm 5.4pt;height:30.0pt'>|.
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><b><span style='font-size:10.5pt;color:black'>证照类型<span lang=EN-US><o:p></o:p></span></span></b></p></td>|.
          lv_yjzw =  |{ lv_yjzw }<td width=117 style='width:88.0pt;border:solid windowtext 1.0pt;border-left:none;background:#F2F2F2;padding:0cm 5.4pt 0cm 5.4pt;height:30.0pt'>| .
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><b><span style='font-size:10.5pt;color:black'>证照编号<span lang=EN-US><o:p></o:p></span></span></b></p>| .
          lv_yjzw =  |{ lv_yjzw }<td width=117 style='width:88.0pt;border:solid windowtext 1.0pt;border-left:none;background:#F2F2F2;padding:0cm 5.4pt 0cm 5.4pt;height:30.0pt'>| .
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><b><span style='font-size:10.5pt;color:black'>证照面积</span></b>| .
          lv_yjzw =  |{ lv_yjzw }<b><span lang=EN-US style='font-size:10.5pt;font-family:"Times New Roman",serif;color:black'>&nbsp;(C)</span></b>| .
          lv_yjzw =  |{ lv_yjzw }<b><span lang=EN-US style='font-size:10.5pt;color:black'><o:p></o:p></span></b></p></td>| .
          lv_yjzw =  |{ lv_yjzw }<td width=117 style='width:88.0pt;border:solid windowtext 1.0pt;border-left:none;background:#F2F2F2;padding:0cm 5.4pt 0cm 5.4pt;height:30.0pt'>| .
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><b><span style='font-size:10.5pt;color:black'>楼栋总面积</span></b>| .
          lv_yjzw =  |{ lv_yjzw }<b><span lang=EN-US style='font-size:10.5pt;font-family:"Times New Roman",serif;color:black'>(D)</span></b>| .
          lv_yjzw =  |{ lv_yjzw }<b><span lang=EN-US style='font-size:10.5pt;color:black'><o:p></o:p></span></b></p></td>| .
          lv_yjzw =  |{ lv_yjzw }<td width=117 style='width:88.0pt;border:solid windowtext 1.0pt;border-left:none;background:#F2F2F2;padding:0cm 5.4pt 0cm 5.4pt;height:30.0pt'>| .
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><b><span style='font-size:10.5pt;color:black'>面积差异</span></b>| .
          lv_yjzw =  |{ lv_yjzw }<b><span lang=EN-US style='font-size:10.5pt;font-family:"Times New Roman",serif;color:black'>(C-D)</span></b>| .
          lv_yjzw =  |{ lv_yjzw }<b><span lang=EN-US style='font-size:10.5pt;color:black'><o:p></o:p></span></b></p></td>| .
          lv_yjzw =  |{ lv_yjzw }<td width=245 style='width:184.0pt;border:solid windowtext 1.0pt;border-left:none;background:#F2F2F2;padding:0cm 5.4pt 0cm 5.4pt;height:30.0pt'>| .
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><b><span style='font-size:10.5pt;color:black'>核对标准<span lang=EN-US><o:p></o:p></span></span></b></p></td>| .
          lv_yjzw =  |{ lv_yjzw }<td width=129 style='width:97.0pt;border:solid windowtext 1.0pt;border-left:none;background:#F2F2F2;padding:0cm 5.4pt 0cm 5.4pt;height:30.0pt'>| .
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><b><span style='font-size:10.5pt;color:black'>待校核楼栋<span lang=EN-US><o:p></o:p></span></span></b></p></td>| .
          lv_yjzw =  |{ lv_yjzw }</tr>| .


          "证照类型/项目阶段
          DATA lt_dd07v TYPE TABLE OF dd07v.
          SELECT domname domvalue_l ddtext
            FROM dd07v
            INTO CORRESPONDING FIELDS OF TABLE lt_dd07v
            WHERE ( domname = 'ZD_ZZLX'
            OR domname = 'ZD_STEP_ID' )
              AND ddlanguage = sy-langu.

          LOOP AT lt_mjcy INTO ls_mjcy.

            lv_yjzw =  |{ lv_yjzw }<tr style='height:43.2pt'>| .

            "证照类型
            READ TABLE lt_dd07v INTO DATA(ls_dd07v) WITH KEY domname = 'ZD_ZZLX' domvalue_l = ls_mjcy-zzlx_n.

            lv_yjzw =  |{ lv_yjzw }<td width=117 style='width:88.0pt;border:solid windowtext 1.0pt;border-top:none;padding:0cm 5.4pt 0cm 5.4pt;height:43.2pt'>| .
            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><span style='font-size:10.5pt;color:black'>| .
            lv_yjzw =  |{ lv_yjzw }{ ls_dd07v-ddtext }<span lang=EN-US><o:p></o:p></span></span></p></td>| .

            "证照编号
            lv_yjzw =  |{ lv_yjzw }<td width=117 style='width:88.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;height:43.2pt'>| .
            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'>|.
            lv_yjzw =  |{ lv_yjzw }<span style='font-size:10.5pt;color:black'>{ ls_mjcy-zzno }</span><span lang=EN-US style='font-size:10.5pt;font-family:"Times New Roman",serif;color:black'><o:p></o:p></span></p></td>| .

            "证照面积
            DATA(lv_mj) = |{ ls_mjcy-mj_zz }|.
            zcl_pl_asset_tag_service=>remove_ending_0_of_decimal( CHANGING cv_data = lv_mj ).
            DATA(lv_mj_c) = CONV char100( lv_mj ).
            zcl_pl_asset_tag_service=>display_in_thousands( CHANGING cv_str = lv_mj_c ).
            lv_mj = lv_mj_c.
            lv_yjzw =  |{ lv_yjzw }<td width=117 style='width:88.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;height:43.2pt'>| .
            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'>|.
            lv_yjzw =  |{ lv_yjzw }<span lang=EN-US style='font-size:10.5pt;font-family:"Times New Roman",serif;color:black'>{ lv_mj }<o:p></o:p></span></p></td>|.


            "icp面积
*
            lv_mj = |{ ls_mjcy-mj_icp }|.
            zcl_pl_asset_tag_service=>remove_ending_0_of_decimal( CHANGING cv_data = lv_mj ).
            lv_mj_c = CONV char100( lv_mj ).
            zcl_pl_asset_tag_service=>display_in_thousands( CHANGING cv_str = lv_mj_c ).
            lv_mj = lv_mj_c.
            lv_yjzw =  |{ lv_yjzw }<td width=117 style='width:88.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;height:43.2pt'>|.
            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><span lang=EN-US style='font-size:10.5pt;font-family:"Times New Roman",serif;color:black'>{ lv_mj }<o:p></o:p></span></p></td>| .


            "差异面积
*            .
            lv_mj = |{ ls_mjcy-mjcy }|.
            zcl_pl_asset_tag_service=>remove_ending_0_of_decimal( CHANGING cv_data = lv_mj ).
            lv_mj_c = CONV char100( lv_mj ).
            zcl_pl_asset_tag_service=>display_in_thousands( CHANGING cv_str = lv_mj_c ).
            lv_mj = lv_mj_c.
            lv_yjzw =  |{ lv_yjzw }<td width=117 style='width:88.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;height:43.2pt'>|.
            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><span lang=EN-US style='font-size:10.5pt;font-family:"Times New Roman",serif;color:red'>{ lv_mj }<o:p></o:p></span></p></td>| .

            "核对标准
            lv_yjzw =  |{ lv_yjzw }<td width=245 style='width:184.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;height:43.2pt'>| .
            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'><span style='font-size:10.5pt;color:black'>{ ls_mjcy-hdbz }</span></p></td>| .

            "待校核楼栋
            lv_yjzw =  |{ lv_yjzw }<td width=129 style='width:97.0pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;height:43.2pt'>| .
            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal align=center style='text-align:center'>{ ls_mjcy-ldfw }</p></td>| .
            lv_yjzw =  |{ lv_yjzw }</tr>|.
          ENDLOOP.

          lv_yjzw =  |{ lv_yjzw }</table>|.

          " MODIFY BY DENGW01  云效434295   start
          SELECT oparea, opperson
            FROM ztplmopconfig
            INTO TABLE @DATA(lt_ztplmopconfig).


          "联系人
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>|.
          lv_yjzw =  |{ lv_yjzw }<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=609 style='width:456.8pt;margin-left:8.4pt;border-collapse:collapse'>| .
          lv_yjzw =  |{ lv_yjzw }<tr style='height:14.4pt'>| .
          lv_yjzw =  |{ lv_yjzw }<td width=609 colspan=4 style='width:456.8pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>若面积校核不是您负责,请帮忙将此邮件转发给责任人,并抄送以下系统运维同事:<span lang=EN-US><o:p></o:p></span></p></td></tr>| .

          LOOP AT lt_ztplmopconfig INTO DATA(ls_ztplmopconfig).
            lv_yjzw =  |{ lv_yjzw }<tr style='height:14.4pt'><td width=277 nowrap style='width:208.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><b><span lang=EN-US>{ ls_ztplmopconfig-oparea }<o:p></o:p></span></b></p></td>| .
            lv_yjzw =  |{ lv_yjzw }<td width=402 nowrap style='width:326.5pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>{ ls_ztplmopconfig-opperson }<span lang=EN-US><o:p></o:p></span></p></td>| .
            lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td>| .
            lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td></tr>| .

*            lv_yjzw =  |{ lv_yjzw }<tr style='height:14.4pt'><td width=277 nowrap style='width:208.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><b>南方区域:<span lang=EN-US><o:p></o:p></span></b></p></td>| .
*            lv_yjzw =  |{ lv_yjzw }<td width=302 nowrap style='width:226.5pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>袁绍滨(<span lang=EN-US>c-yuansb</span>)<span lang=EN-US><o:p></o:p></span></p></td>| .
*            lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td>| .
*            lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td></tr>| .
*
*            lv_yjzw =  |{ lv_yjzw }<tr style='height:14.4pt'><td width=277 nowrap style='width:208.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><b>北京<span lang=EN-US>/</span>华中<span lang=EN-US>/</span>西北<span lang=EN-US>/</span>西南区域:<span lang=EN-US><o:p></o:p></span></b></p></td>| .
*            lv_yjzw =  |{ lv_yjzw }<td width=302 nowrap style='width:226.5pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>黎<span lang=EN-US>&nbsp; </span>梅(<span lang=EN-US>c-lim18</span>)<span lang=EN-US><o:p></o:p></span></p></td>| .
*            lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td></tr>| .
*
*            lv_yjzw =  |{ lv_yjzw }<tr style='height:28.8pt'><td width=277 nowrap valign=top style='width:208.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.8pt'>| .
*            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><b>除<span lang=EN-US>7BG</span>外其他公司:<span lang=EN-US><o:p></o:p></span></b></p></td>| .
*            lv_yjzw =  |{ lv_yjzw }<td width=302 valign=top style='width:226.5pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.8pt'>| .
*            lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>黎梅(<span lang=EN-US>c-lim18</span>)<span lang=EN-US><br></span>赵庆(<span lang=EN-US>c-zhaoq05</span>)<span lang=EN-US><o:p></o:p></span></p>| .
*            lv_yjzw =  |{ lv_yjzw }</td><td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.8pt'></td>| .
*            lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.8pt'></td></tr>|.

          ENDLOOP.
          lv_yjzw =  |{ lv_yjzw }</table>|.
          lv_yjzw =  |{ lv_yjzw }<p style='mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:15.0pt;margin-bottom:.0001pt'><span lang=EN-US><o:p>&nbsp;</o:p></span></p>| .
          lv_yjzw =  |{ lv_yjzw }<p style='mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:15.0pt;margin-bottom:.0001pt'>祝好!<span lang=EN-US><o:p></o:p></span></p>| .
          lv_yjzw =  |{ lv_yjzw }<p style='mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:15.0pt;margin-bottom:.0001pt'>崔筱盼<span lang=EN-US><o:p></o:p></span></p>| .
          lv_yjzw =  |{ lv_yjzw }<p style='mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:15.0pt;margin-bottom:.0001pt'>集团总部 事业中心<span lang=EN-US><o:p></o:p>| .
          lv_yjzw =  |{ lv_yjzw }</span></p><p class=MsoNormal><span lang=EN-US | .
          lv_yjzw =  |{ lv_yjzw }style='font-size:10.5pt;font-family:等线'><o:p>&nbsp;</o:p></span></p></div></body>| .

          " MODIFY BY DENGW01  云效434295   end

*          "联系人
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>|.
*          lv_yjzw =  |{ lv_yjzw }<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=609 style='width:456.8pt;margin-left:8.4pt;border-collapse:collapse'>| .
*          lv_yjzw =  |{ lv_yjzw }<tr style='height:14.4pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=609 colspan=4 style='width:456.8pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>若面积校核不是您负责,请帮忙将此邮件转发给责任人,并抄送以下系统运维同事:<span lang=EN-US><o:p></o:p></span></p></td></tr>| .
*          lv_yjzw =  |{ lv_yjzw }<tr style='height:14.4pt'><td width=277 nowrap style='width:208.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><b>东北<span lang=EN-US>/</span>上海区域:<span lang=EN-US><o:p></o:p></span></b></p></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=302 nowrap style='width:226.5pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>黄新辉(<span lang=EN-US>c-huangxh03</span>)<span lang=EN-US><o:p></o:p></span></p></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td></tr>| .
*          lv_yjzw =  |{ lv_yjzw }<tr style='height:14.4pt'><td width=277 nowrap style='width:208.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><b>南方区域:<span lang=EN-US><o:p></o:p></span></b></p></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=302 nowrap style='width:226.5pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>袁绍滨(<span lang=EN-US>c-yuansb</span>)<span lang=EN-US><o:p></o:p></span></p></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td></tr>| .
*          lv_yjzw =  |{ lv_yjzw }<tr style='height:14.4pt'><td width=277 nowrap style='width:208.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><b>北京<span lang=EN-US>/</span>华中<span lang=EN-US>/</span>西北<span lang=EN-US>/</span>西南区域:<span lang=EN-US><o:p></o:p></span></b></p></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=302 nowrap style='width:226.5pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>黎<span lang=EN-US>&nbsp; </span>梅(<span lang=EN-US>c-lim18</span>)<span lang=EN-US><o:p></o:p></span></p></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.4pt'></td></tr>| .
*          lv_yjzw =  |{ lv_yjzw }<tr style='height:28.8pt'><td width=277 nowrap valign=top style='width:208.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.8pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal><b>除<span lang=EN-US>7BG</span>外其他公司:<span lang=EN-US><o:p></o:p></span></b></p></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=302 valign=top style='width:226.5pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.8pt'>| .
*          lv_yjzw =  |{ lv_yjzw }<p class=MsoNormal>黎梅(<span lang=EN-US>c-lim18</span>)<span lang=EN-US><br></span>赵庆(<span lang=EN-US>c-zhaoq05</span>)<span lang=EN-US><o:p></o:p></span></p>| .
*          lv_yjzw =  |{ lv_yjzw }</td><td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.8pt'></td>| .
*          lv_yjzw =  |{ lv_yjzw }<td width=15 nowrap style='width:11.1pt;padding:0cm 5.4pt 0cm 5.4pt;height:28.8pt'></td></tr></table>| .
*          lv_yjzw =  |{ lv_yjzw }<p style='mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:15.0pt;margin-bottom:.0001pt'><span lang=EN-US><o:p>&nbsp;</o:p></span></p>| .
*          lv_yjzw =  |{ lv_yjzw }<p style='mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:15.0pt;margin-bottom:.0001pt'>祝好!<span lang=EN-US><o:p></o:p></span></p>| .
*          lv_yjzw =  |{ lv_yjzw }<p style='mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:15.0pt;margin-bottom:.0001pt'>崔筱盼<span lang=EN-US><o:p></o:p></span></p>| .
*          lv_yjzw =  |{ lv_yjzw }<p style='mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:15.0pt;margin-bottom:.0001pt'>集团总部 事业中心<span lang=EN-US><o:p></o:p>| .
*          lv_yjzw =  |{ lv_yjzw }</span></p><p class=MsoNormal><span lang=EN-US | .
*          lv_yjzw =  |{ lv_yjzw }style='font-size:10.5pt;font-family:等线'><o:p>&nbsp;</o:p></span></p></div></body>| .


*
*
*            append |<th style='width:150px;background-color:#FFFFFF;font-size:12pt;text-align: center;font-family:"楷体",sans-serif'>{ ls_mjcy-zzno }</th>| to lt_main_text.
*
*
*
*            append |<th style='width:150px;background-color:#FFFFFF;font-size:12pt;text-align: center;font-family:"楷体",sans-serif'>{ lv_mj }</th>| to lt_main_text.
*
*
*            append |<th style='width:150px;background-color:#FFFFFF;font-size:12pt;text-align: center;font-family:"楷体",sans-serif'>{ lv_mj } </th>| to lt_main_text.

*            lv_trunc = trunc( ls_mjcy-mjcy ).
*            lv_frac2 = frac( ls_mjcy-mjcy ) * 10000.
**              data(lv_frac2) = conv i( substring_after( val = |{ ls_mjcy-mj_icp - lv_trunc }| sub = '.' ) ).
*            if lv_frac2 ne 0.
*              lv_frac2_s = |{ trunc( lv_frac2 ) }|.
*              do 4 times.
*                lv_offset = 4 - sy-index.
*                if lv_frac2_s+lv_offset(1) eq 0.
*                  lv_frac2_s = lv_frac2_s+0(lv_offset).
*                else.
*                  exit.
*                endif.
*              enddo.
*
*              if lv_frac2_s is not initial and lv_frac2_s+0(1) = '-'.
*                lv_frac2_s = lv_frac2_s+1.
*              endif.
*              lv_mj = |{ lv_trunc }.{ lv_frac2_s }|.
*            else.
*              lv_mj = |{ lv_trunc }|.
*            endif.
*            append |<th style='width:150px;background-color:#FFFFFF;color:red;font-size:12pt;text-align: center;font-family:"楷体",sans-serif'>{ lv_mj }</th>| to lt_main_text.
*            append |<th style='width:200px;background-color:#FFFFFF;font-size:12pt;text-align: center;font-family:"楷体",sans-serif'>{ ls_mjcy-hdbz }</th>| to lt_main_text.
**                MODIFY by c-zhabl01 at 20220906:处理ldfw超长被截断问题---begin
*            append |<th style='width:200px;background-color:#FFFFFF;font-size:12pt;text-align: center;font-family:"楷体",sans-serif'>| to lt_main_text.
*            while ls_mjcy-ldfw is not initial.
*              data(lv_len) = cond i( when strlen( ls_mjcy-ldfw ) gt 255 then 255 else strlen( ls_mjcy-ldfw ) ).
*              append |{ ls_mjcy-ldfw+0(lv_len) }| to lt_main_text.
*              ls_mjcy-ldfw = ls_mjcy-ldfw+lv_len.
*            endwhile.
*            append |</th>| to lt_main_text.
**                MODIFY by c-zhabl01 at 20220906:处理ldfw超长被截断问题---end
*            append |</tr>| to lt_main_text.
*          endloop.
*          append |</table>| to lt_main_text.
*          append |</p>| to lt_main_text.
*          append |</body>| to lt_main_text.
**          endif.
*
*
*          append |<body style="width:2000px;">| to lt_main_text.
**          append |<br></br>| to lt_main_text.
*          append |<p style='font-size:12.0pt;font-family:"楷体";margin:0;margin-left:20px'>&nbsp;&nbsp;处理过程中若有问题,烦请您联系以下同事协助处理:</p>| to lt_main_text.
*          append |<p style='font-size:12.0pt;font-family:"楷体";margin:0;margin-left:20px'>&nbsp;&nbsp;上海/东北区域:黄新辉 c-huangxh03 </p>| to lt_main_text.
*          append |<p style='font-size:12.0pt;font-family:"楷体";margin:0;margin-left:20px'>&nbsp;&nbsp;南方区域:袁绍滨c-yuansb </p>| to lt_main_text.
*          append |<p style='font-size:12.0pt;font-family:"楷体";margin:0;margin-left:20px'>&nbsp;&nbsp;北京/西南/西北/华中区域:黎梅c-lim18 </p>| to lt_main_text.
*          append |<p style='font-size:12.0pt;font-family:"楷体";margin:0;margin-left:20px'>&nbsp;&nbsp;除7BG外其他:黎梅c-lim18 /赵庆c-zhaoq05 </p>| to lt_main_text.
*          append |<p style='font-size:12.0pt;font-family:"楷体";margin:0;margin-left:20px'>&nbsp;&nbsp;若面积校核不是您负责,请帮忙转发邮件给面积校核的责任人,并告知我们责任人的域账号,我们进行邮件发送人的更新,谢谢! </p>| to lt_main_text.
*
*
*          "ADD BY YISZ 2022/10/19 BEGIN
*          refresh im_para.
*          lv_appnam = 'ZWD_PL_C019N'.
*          append value #( name = 'PSPID' value = lv_posid_xm ) to im_para.
*          "生成URL地址
*          call function 'ZPORTALFM_003'
*            exporting
*              im_appnam        = lv_appnam
*              im_para          = im_para
*              im_switch_portal = 'X'
*            importing
*              ev_url           = ls_url.
*
*          append |<p style='font-size:12.0pt;font-family:"楷体";color:black;margin:0;margin-left:20px'>&nbsp;&nbsp;您也可以点击此处超链接| to lt_main_text.
*          ls_url = |<a style='color:red' href="| && ls_url && |" target="_blank" >进行项目{ lv_posid_xm }【{ lv_post1 }】的面积校核人员维护</a></p>|.
*
*          clear lt_urls.
*          call function 'CONVERT_STRING_TO_TAB'
*            exporting
*              i_string         = ls_url
*              i_tabline_length = 255
*            tables
*              et_table         = lt_urls.
*          append  lines of lt_urls to lt_main_text.
*          "ADD BY YISZ 2022/10/19 END
*
*          "签名
*          append |<br></br>| to lt_main_text.
*          append |<p style='font-size:12.0pt;font-family:"楷体";color:black;margin:0;margin-left:20px'>祝好!</p>| to lt_main_text.
*          append |<p style='font-size:12.0pt;font-family:"楷体";color:black;margin:0;margin-left:20px'>崔筱盼</p>| to lt_main_text.
*          append |<p style='font-size:12.0pt;font-family:"楷体";color:black;margin:0;margin-left:20px'>集团总部 事业中心</p>| to lt_main_text.
*          append |</body>| to lt_main_text.
          "证照面积差异明细显示在邮件正文 2022/8/15 yisz add end

          CLEAR lt_main_text.
          CLEAR lt_urls.
          CALL FUNCTION 'CONVERT_STRING_TO_TAB'
            EXPORTING
              i_string         = lv_yjzw
              i_tabline_length = 255
            TABLES
              et_table         = lt_urls.
          APPEND  LINES OF lt_urls TO lt_main_text.

*            ====发送邮件======
          DATA:l_subject          TYPE so_obj_des,
               lr_email_body      TYPE REF TO cl_document_bcs,
               lr_email           TYPE REF TO cl_bcs,
               lo_cx_send_req_bcs TYPE REF TO cx_send_req_bcs,
               l_mail_address     TYPE adr6-smtp_addr,
               lr_receiver        TYPE REF TO cl_cam_address_bcs,
*       l_sender           type ref to cl_sapuser_bcs,
               l_sender           TYPE REF TO if_sender_bcs,
               l_send_result      TYPE os_boolean,
               lo_mr_api          TYPE REF TO if_mr_api,
               lo_convert         TYPE REF TO cl_bcs_convert,
               lo_mime_helper     TYPE REF TO cl_gbt_multirelated_service.

          l_subject = lv_subject.  "邮件标题
          TRY.
              CREATE OBJECT lo_mime_helper.

*              delete by c-zhabl01 at 20220802 for wangx:操作手册改为超链接---begin
*                "添加附件-操作手册
*                data(lv_bina_data) = value xstring( ).
*                data(lv_content_type) = value w3conttype( ).
*
*                zcl_cd_rps=>wda_get_mime_object(
*                    exporting
*                      iv_wdc_name  = 'ZWD_PL_C017'    " Web Dynpro Application ID
*                      iv_mime_id   = 'ZWD_PL_C017_MIME_1'    " MIME object ID
*                    importing
*                      ev_bina_data = lv_bina_data    " binary data
*                      ev_mime_type = lv_content_type    " binary data
*                  ).
*
*                if lv_bina_data is not initial.
*
*                  data(lt_solix) = value solix_tab( ).
*
*                  create object lo_convert.
*                  call method lo_convert->xstring_to_solix
*                    exporting
*                      iv_xstring = lv_bina_data
*                    receiving
*                      et_solix   = lt_solix.
*                  data(lv_len) = conv so_obj_len( xstrlen( lv_bina_data ) ).
*
*                  call method lo_mime_helper->add_binary_part
*                    exporting
*                      content      = lt_solix
*                      filename     = '证照面积核对功能操作手册.doc'
*                      extension    = 'doc'
*                      description  = '证照面积核对功能操作手册'
*                      content_type = lv_content_type
*                      length       = lv_len
*                      content_id   = '证照面积核对功能操作手册.doc'.
**            *    p_document->add_attachment( i_attachment_type = 'png'
**                                i_attachment_subject = 'CB'
**                                i_att_content_hex = lt_solix ).
*
*                endif.
*              delete by c-zhabl01 at 20220802 for wangx:操作手册改为超链接---end

              CALL METHOD lo_mime_helper->set_main_html
                EXPORTING
                  content = lt_main_text[].
            CATCH cx_root.
          ENDTRY.

          TRY.
              CALL METHOD cl_document_bcs=>create_from_multirelated
                EXPORTING
                  i_subject          = l_subject
                  i_multirel_service = lo_mime_helper
                RECEIVING
                  result             = lr_email_body.
            CATCH cx_root.
          ENDTRY.

          lr_email = cl_bcs=>create_persistent( ).
          lr_email->set_document( lr_email_body ).

*// 收件人
          LOOP AT lt_pernr INTO ls_pernr.      "add by c-zhabl01 at 20220222 for lilt:增加多个收件人
            TRANSLATE ls_pernr-email TO UPPER CASE.
            MODIFY lt_pernr FROM ls_pernr INDEX sy-tabix.
            l_mail_address = ls_pernr-email.
            TRY.
                lr_receiver = cl_cam_address_bcs=>create_internet_address( l_mail_address  ).
                lr_email->add_recipient( i_recipient = lr_receiver ).
              CATCH cx_root.
            ENDTRY.
          ENDLOOP.

          DATA lv_cs TYPE n LENGTH 3.
*// 抄送人
*          IF sy-sysid+0(2) = 'ED'.
*            CLEAR ls_ztpl0058n.
*            ls_ztpl0058n-rercc =  'C'.
*            ls_ztpl0058n-mail = '[email protected]'.
*            INSERT ls_ztpl0058n INTO lt_ztpl0058n INDEX 1.
*          ENDIF.

          LOOP AT lt_ztpl0058n INTO ls_ztpl0058n WHERE rercc = 'C'.
            READ TABLE lt_pernr WITH KEY email = ls_ztpl0058n-mail TRANSPORTING NO FIELDS.
            IF sy-subrc NE 0.
              l_mail_address = ls_ztpl0058n-mail.
              TRY.
                  lv_cs = lv_cs + 1.
                  lr_receiver = cl_cam_address_bcs=>create_internet_address( i_address_string = l_mail_address ).
*                lr_receiver->set_so_key( conv char10( lv_cs  ) ).
                  lr_email->add_recipient( i_recipient = lr_receiver i_copy = 'X' ).
                CATCH cx_root.
              ENDTRY.
            ENDIF.
          ENDLOOP.

          LOOP AT lt_csr INTO DATA(ls_csr).
            TRANSLATE ls_csr-email TO UPPER CASE.
            READ TABLE lt_ztpl0058n WITH KEY mail = ls_csr-email TRANSPORTING NO FIELDS.
            IF sy-subrc NE 0.

              l_mail_address = ls_csr-email.
              TRY.
                  lv_cs = lv_cs + 1.
                  lr_receiver = cl_cam_address_bcs=>create_internet_address( l_mail_address ).     "邮件地址转换
*                  lr_receiver->set_so_key( conv char10(  lv_cs  ) ).
*                  lr_email->add_recipient( exporting i_recipient = lr_receiver i_blind_copy = 'X' ).     "添加邮件地址到发送请求---密件抄送
                  lr_email->add_recipient( EXPORTING i_recipient = lr_receiver i_copy = 'X' ).     "添加邮件地址到发送请求
                CATCH cx_root.
              ENDTRY.
            ENDIF.
          ENDLOOP.

*// 邮件发送人
          "Set Sender and send mail
          DATA lv_sender TYPE syst_uname.
          TRY.
              IF sy-sysid+0(2) EQ 'EP' .
*        lv_sender = |{ 'ICP-NOTICE' }|.
                lv_sender = |{ 'V-CUIXP' }|.
              ELSE.
                lv_sender = |{ 'ICP' }|.
              ENDIF.

*                lv_sender = |{ 'V-CUIXP' }|.
              l_sender ?= cl_sapuser_bcs=>create( lv_sender ).
            CATCH cx_address_bcs.
              "l_mail_address = '[email protected]'.
              IF sy-sysid+0(2) EQ 'EP' .
                l_mail_address = '[email protected]'.
              ELSE.
                l_mail_address = '[email protected]'.
              ENDIF.

              l_sender ?= cl_cam_address_bcs=>create_internet_address(
                                                                      i_address_string = l_mail_address
                                                                      i_address_name   = l_mail_address ).
          ENDTRY .

          lr_email->set_sender( l_sender ).
          lr_email->set_status_attributes( i_requested_status = 'E' i_status_mail = 'E' ).""不返回执邮件


*// 立即发送 Send email directly
          TRY.
              CALL METHOD lr_email->set_send_immediately
                EXPORTING
                  i_send_immediately = 'X'.
            CATCH cx_root .
          ENDTRY.

          TRY.
              CALL METHOD lr_email->send
                RECEIVING
                  result = l_send_result.

              ev_sent = abap_true.
              COMMIT WORK.

              "记录提醒记录
              SELECT *
                FROM ztpp1066
                FOR ALL ENTRIES IN @lt_ldnum
                WHERE zzlx = @lt_ldnum-zzlx
                  AND ldnum = @lt_ldnum-ldnum
                INTO TABLE @DATA(lt_ztpp1066).
              IF sy-subrc EQ 0.
                SORT lt_ztpp1066 BY zzlx ldnum.
              ENDIF.

              DATA lt_ztpp1066_new TYPE STANDARD TABLE OF ztpp1066.

              DATA(lv_receiver) = ||.
              LOOP AT lt_pernr INTO ls_pernr.
                IF ls_pernr-uname IS NOT INITIAL.
                  lv_receiver = |{ lv_receiver },{ ls_pernr-uname }|.
                ELSE.
                  lv_receiver = |{ lv_receiver },{ substring_before( sub = '@' val = ls_pernr-email ) }|.
                ENDIF.
              ENDLOOP.

              IF lv_receiver IS NOT INITIAL.
                lv_receiver = lv_receiver+1.
              ENDIF.

              LOOP AT lt_ldnum INTO ls_ldnum.

                READ TABLE lt_ztpp1066 INTO DATA(ls_ztpp1066) WITH KEY zzlx = ls_ldnum-zzlx ldnum = ls_ldnum-ldnum BINARY SEARCH.
                IF sy-subrc EQ 0.
                  zcl_pl_asset_tag_service=>set_usrdt( EXPORTING iv_mode = 'U' CHANGING cs_usrdt = ls_ztpp1066-usrdt ).
                ELSE.
                  zcl_pl_asset_tag_service=>set_usrdt( EXPORTING iv_mode = 'I' CHANGING cs_usrdt = ls_ztpp1066-usrdt ).
                ENDIF.

                ls_ztpp1066-zzlx = ls_ldnum-zzlx.
                ls_ztpp1066-ldnum = ls_ldnum-ldnum.

*                ls_ztpp1066-receiver = ls_fiout-uname."add by c-zhabl01 at 20220707 for wangx:增加收件人记录
                ls_ztpp1066-receiver = lv_receiver."modify by c-zhabl01 at 20221102 :收件人可能是多个,用,隔开

                APPEND ls_ztpp1066 TO lt_ztpp1066_new.
              ENDLOOP.

              MODIFY ztpp1066 FROM TABLE lt_ztpp1066_new.
              IF sy-subrc EQ 0.
                COMMIT WORK.

*--- ADD BY C-ZHABL01 AT 20220915:增加阶段自动升版---begin
                SELECT psphi,
                       posid AS ldnum
                  FROM prps
                  FOR ALL ENTRIES IN @lt_ztpp1066_new
                  WHERE posid = @lt_ztpp1066_new-ldnum
                  INTO TABLE @DATA(lt_psphi).
                IF sy-subrc EQ 0.
                  SELECT posid,
                         psphi
                    FROM prps
                    FOR ALL ENTRIES IN @lt_psphi
                    WHERE psphi = @lt_psphi-psphi
                      AND stufe = '1'
                    INTO TABLE @DATA(lt_xm).
                  IF sy-subrc EQ 0.
                    SELECT *
                      FROM ztpp1071
                      FOR ALL ENTRIES IN @lt_xm
                      WHERE posid = @lt_xm-posid
                        AND status IN ( 'N','E' )
                      INTO TABLE @DATA(lt_ztpp1071_old).
                    IF sy-subrc EQ 0.
                      SORT lt_ztpp1071_old BY posid.
                    ENDIF.

                    DATA lt_ztpp1071_new TYPE STANDARD TABLE OF ztpp1071.

                    SORT lt_psphi BY ldnum.
                    SORT lt_xm BY psphi.
                    LOOP AT lt_xm INTO DATA(ls_xm).

                      APPEND INITIAL LINE TO lt_ztpp1071_new ASSIGNING FIELD-SYMBOL(<lfs_1071_new>).
                      <lfs_1071_new>-posid = ls_xm-posid.
                      <lfs_1071_new>-fbdat = sy-datum.
                      <lfs_1071_new>-status = 'N'.
                      zcl_pl_asset_tag_service=>set_usrdt( EXPORTING iv_mode = 'I' CHANGING cs_usrdt = <lfs_1071_new>-stamp ).

                      READ TABLE lt_ztpp1071_old WITH KEY posid = ls_xm-posid TRANSPORTING NO FIELDS BINARY SEARCH.
                      IF sy-subrc EQ 0.
                        LOOP AT lt_ztpp1071_old INTO DATA(ls_1071) FROM sy-tabix.
                          IF ls_1071-posid NE ls_xm-posid.
                            EXIT.
                          ENDIF.

                          IF ls_1071-fbdat EQ <lfs_1071_new>-fbdat.
                            CONTINUE.
                          ENDIF.

                          ls_1071-status = 'I'.

                          zcl_pl_asset_tag_service=>set_usrdt( EXPORTING iv_mode = 'U' CHANGING cs_usrdt = ls_1071-stamp ).

                          APPEND ls_1071 TO lt_ztpp1071_new.
                        ENDLOOP.
                      ENDIF.
                    ENDLOOP.

                    MODIFY ztpp1071 FROM TABLE lt_ztpp1071_new.
                    IF sy-subrc EQ 0.
                      COMMIT WORK.
                    ELSE.
                      ROLLBACK WORK.
                    ENDIF.
                  ENDIF.
                ENDIF.
*---ADD BY C-ZHABL01 AT 20220915:增加阶段自动升版---end
              ELSE.
                ROLLBACK WORK.
              ENDIF.
            CATCH cx_root.
          ENDTRY.
          "         ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFUNCTION.

标签:发邮件,DATA,lv,yjzw,lt,ls,AUTOMAIL,SAP,TYPE
From: https://blog.csdn.net/woniu_maggie/article/details/141555252

相关文章

  • SAP修改底表方法
    SE16N激活DEBUG调试底表1、通过SE16N,输入表名称,输入参数过滤;2、在命令框输入/H,执行,激活DEBUG,执行查询,进入DEBUG页面;3、输入变量:GD-SAPEDIT、GD-EDIT,修改值为X,然后执行(F8);4、进入底表修改数据,然后保存,完成修改。......
  • SAP S4HANA 2023 FPS01 FAA虚拟机发布了
    SAPS4HANA2023FPS01FAA虚拟机发布了。系统不再需要修改虚拟机日期了,提供最高长达三年的许可,业务财务做账都是真实的时间!该虚拟机版本优点:新版的一键启动脚本,3分钟就能启动完成。内存加载80GB就可以启动所有服务。不需要修改虚拟机日期,完美支持业务操作和财务做账,月结年......
  • SAP赋能消费品行业:创新与效率的双重驱动
     在快速消费品行业,市场变化如同潮水般汹涌,消费者需求日益个性化,竞争愈发激烈。SAP系统以其先进的企业资源规划技术,为消费品行业提供了强大的数字化解决方案,助力企业在创新与效率的双重驱动下,实现业务的持续增长和市场竞争力的提升。         消费品行业面临的......
  • SAP月结流程【S4 HANA版本】【配图文】
    1)打开新的财务账期及物料账期:S_ALR_87003642或OB52打开财务账期,MMPV打开物料账期,MMRV查看物料账期。账期一般在每月1号凌晨打开,否则对于7×24小时生产的企业可能无法正常进行物料的收发。2)维护当月汇率:S_BCE_68000174或OB08维护系统默认汇率,一般维护上月末(月初)的中间汇率,开......
  • SAP Parallel Accounting(平行分类账业务)配置及操作手册【适用于多国家会计准则】
    1.配置准备1.1理解平行账概念平行账,也称为多分类账,是SAP系统中的一项功能,它允许企业按照不同的会计准则来维护各自的财务数据。这种设置特别适用于那些需要符合多种会计准则的跨国公司。通过平行账,企业可以在不同的分类账中记录相同的交易,但按照各自的会计政策进行处理。......
  • CSAPP:Lab1 -DataLab
    环境准备最好准备一个纯净的Linux系统,可以通过vmware创建虚拟机,或者使用docker 构建一个centos或者 ubuntu系统。主机我是windows系统,本机上安装vscode,通过vscode安装remotessh插件,连接Linux虚拟机,vscode上直接可以打开远程虚拟机中工作区,进行软件开发,比较方便。主要还是c......
  • SAP EWM PMR
    目录1简介2业务流程3业务操作4主数据设置4.1ERP主数据4.2EWM主数据5后台配置5.1主数据5.2GI流程5.3仓库内部移动流程5.4 仓库任务设置5.5集成5.6EWM链接1简介EWMPMR分2部分功能,第一是MES-DrivenStaging,第二是AdvancedProductionIn......
  • SAP B1 三大基本表单标准功能介绍-业务伙伴主数据(三)
    背景在SAPB1中,科目表、业务伙伴主数据、物料主数据被称为三大基本表单,其中的标准功能是实施项目的基础。本系列文章将逐一介绍三大基本表单各个字段的含义、须填内容、功能等内容。附上SAPB110.0的帮助文档:SAPBusinessOne10.0|SAPHelpPortal本文介绍的是:业务......
  • 【项目实战】商务智能BI工具(MicroStrategy、Cognos、SAP Business Objects/BO)
    一、商务智能BI商务智能,BusinessIntelligence,简称BI。商务智能工具,是帮助企业分析数据、生成报告、创建仪表盘和可视化数据的重要软件。MicroStrategy、Cognos和BusinessObjects(通常称为BO)都是业界知名的BI解决方案二、MicroStrategyMicroStrategy是一家专注于数据分......
  • SAP转移过帐
    转移过帐和实物库存转储在任何企业中,货物移动不仅限于收货、发货的形式。出于组织原因(如分散库存)或其它因素(如质量保证),可能需要内部转移过帐和实物库存转储。对于转移过帐,最重要的是更改物料的库存ID编号或库存类别。转移过帐无需涉及实际(实物)的货物移动。而对于库存转储,总......