以PDF附件形式发送smartform…

程序要点:1、显示smartform时,获取对应的OTF数据,然后转换为PDF对象

2、使用function module  SO_NEW_DOCUMENT_ATT_SEND_API1 发送邮件,设置 PUT_IN_OUTBOX              'X' 可以在工作台outbox查看邮件的发送状态及内容

3、调用程序 RSCONN01 立即发送;上述function module 执行之后,并不能立即发送出去,需要执行 RSCONN01 才能立即发送。此程序一般在basis配置SAP邮件时设置成后台作业,参考事务码SCOT

以下是程序源码及SAP outbox截图:

  *&---------------------------------------------------------------------*
*& Report  YZ_TEST13
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  YZ_TEST13.


DATA I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE.
DATA WA_BUFFER TYPE STRING"To convert from 132 to 255

DATAI_RECORD TYPE TABLE OF SOLISTI1 WITH HEADER LINE,
      WA_DOC TYPE SODOCCHGI1,
      I_RECLIST TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

Objects to send mail.
    I_OBJPACK TYPE TABLE OF SOPCKLSTI1 WITH HEADER LINE,
    I_OBJTXT TYPE  TABLE OF SOLISTI1 WITH HEADER LINE,
    I_OBJBIN TYPE TABLE OF SOLISTI1 WITH HEADER LINE,

Work Area declarations
    WA_OBJHEAD TYPE SOLI_TAB,

Variables declarations
    V_LEN_IN TYPE SOOD-OBJLEN,
    V_LINES_TXT TYPE I,
    V_LINES_BIN TYPE I.

DATA OUTPUT_OPTIONS TYPE SSFCOMPOP .

DATA CONTROL_PARAMETERS TYPE SSFCTRLOP.

DATA JOB_OUTPUT_INFO TYPE SSFCRESCL.

DATA LV_FNAME(30).


PARAMETERS P_MAILTO(30DEFAULT 'zyz_erp@163.com'.

*Smartforms
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    FORMNAME                 '/SAPDII/FINC_LIST'
  VARIANT                  '
  DIRECT_CALL              '
  IMPORTING
    FM_NAME                  LV_FNAME
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.

CONTROL_PARAMETERS-GETOTF 'X'.

CALL FUNCTION LV_FNAME
  EXPORTING
  ARCHIVE_INDEX              =
  ARCHIVE_INDEX_TAB          =
  ARCHIVE_PARAMETERS         =
   CONTROL_PARAMETERS         CONTROL_PARAMETERS
  MAIL_APPL_OBJ              =
  MAIL_RECIPIENT             =
  MAIL_SENDER                =
   OUTPUT_OPTIONS             OUTPUT_OPTIONS
  USER_SETTINGS              'X'
  LINEITEMS                  =
  IMPORTING
   DOCUMENT_OUTPUT_INFO       =
    JOB_OUTPUT_INFO            JOB_OUTPUT_INFO
  JOB_OUTPUT_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 'CONVERT_OTF'
  EXPORTING
    FORMAT                      'PDF'
    MAX_LINEWIDTH               132
  ARCHIVE_INDEX               '
  COPYNUMBER                  0
  ASCII_BIDI_VIS2LOG          '
  PDF_DELETE_OTFTAB           '
   IMPORTING
     BIN_FILESIZE                V_LEN_IN
  BIN_FILE                    =
  TABLES
    OTF                         JOB_OUTPUT_INFO-OTFDATA
    LINES                       I_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.

Attachment
LOOP AT I_TLINE.
  TRANSLATE I_TLINE USING '~'.
  CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.
ENDLOOP.
TRANSLATE WA_BUFFER USING '~'.
DO.
  I_RECORD WA_BUFFER.
  APPEND I_RECORD.
  SHIFT WA_BUFFER LEFT BY 255 PLACES.
  IF WA_BUFFER IS INITIAL.
    EXIT.
  ENDIF.
ENDDO.
I_OBJBIN[] I_RECORD[].

*Mail Body
I_OBJTXT-LINE '邮件正文文文文文文文文文文'.
APPEND I_OBJTXT.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.
WA_DOC-OBJ_NAME 'smartform'.
WA_DOC-EXPIRY_DAT SY-DATUM 10.
WA_DOC-OBJ_DESCR '邮件标题题题题题题题题题'.
WA_DOC-SENSITIVTY 'F'.
WA_DOC-DOC_SIZE V_LINES_TXT 255.

Main Text
CLEAR I_OBJPACK-TRANSF_BIN.
I_OBJPACK-HEAD_START 1.
I_OBJPACK-HEAD_NUM 5.
I_OBJPACK-BODY_START 1.
I_OBJPACK-BODY_NUM V_LINES_TXT.
I_OBJPACK-DOC_TYPE 'RAW'.
APPEND I_OBJPACK.

Attachment (pdf-Attachment)
I_OBJPACK-TRANSF_BIN 'X'.
I_OBJPACK-HEAD_START 1.
I_OBJPACK-HEAD_NUM 0.
I_OBJPACK-BODY_START 1.
DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.
I_OBJPACK-DOC_SIZE V_LINES_BIN 255 .
I_OBJPACK-BODY_NUM V_LINES_BIN.
I_OBJPACK-DOC_TYPE 'PDF'.
I_OBJPACK-OBJ_NAME 'smart'.
APPEND I_OBJPACK.

CLEAR I_RECLIST.
I_RECLIST-REC_TYPE 'U'.
I_RECLIST-RECEIVER P_MAILTO.
APPEND I_RECLIST.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    DOCUMENT_DATA              WA_DOC
    PUT_IN_OUTBOX              'X'
    COMMIT_WORK                'X'
  TABLES
    PACKING_LIST               I_OBJPACK
    OBJECT_HEADER              WA_OBJHEAD
    CONTENTS_BIN               I_OBJBIN
    CONTENTS_TXT               I_OBJTXT
    RECEIVERS                  I_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.
*start SAPconnect process immediately
  SUBMIT RSCONN01 WITH MODE EQ 'INT' AND RETURN.

  COMMIT WORK.
ENDIF.

SAP outbox:

[转载]以PDF附件形式发送smartform到邮箱(二)

posted @ 2014-06-17 14:52  胡来  阅读(570)  评论(0编辑  收藏  举报