ABAP发送邮件-带附件

相关T-CODE:SBWP   SCOT  SOST  SO01~SO07


DATA GV_METHOD1      LIKE SY-UCOMM.
DATA GS_USER         LIKE SOUDNAMEI1.
DATA GS_USER_DATA    LIKE SOUDATAI1.
DATA GV_OWNER        LIKE SOUD-USRNAM.
DATA GT_RECEIPIENTS  LIKE SOOS1 OCCURS WITH HEADER LINE.
DATA GS_DOCUMENT     LIKE SOOD4 .
DATA GS_HEADER2      LIKE SOOD2.
DATA GS_FOLMAM       LIKE SOFM2.
DATA GT_OBJCNT       LIKE SOLI OCCURS WITH HEADER LINE.
DATA GT_OBJHEAD      LIKE SOLI OCCURS WITH HEADER LINE.
DATA GT_OBJPARA      LIKE SELC OCCURS WITH HEADER LINE.
DATA GT_OBJPARB      LIKE SOOP1 OCCURS WITH HEADER LINE.
DATA GT_ATTACHMENTS  LIKE SOOD5 OCCURS WITH HEADER LINE.
DATA GT_REFERENCES   LIKE SOXRL OCCURS WITH HEADER LINE.
DATA GS_RECIVER      LIKE SOOS6 .
DATA GV_AUTHORITY    LIKE SOFA-USRACC.
DATA GS_REF_DOCUMENT LIKE SOOD4.
DATA GS_NEW_PARENT   LIKE SOODK.
DATABEGIN OF GT_FILES OCCURS 10 ,
        
TEXT(4096TYPE C,
      
END OF GT_FILES.

DATA : GV_FOLD_NUMBER(12TYPE C,
       GV_FOLD_YR
(2)      TYPE C,
       GV_FOLD_TYPE
(3)    TYPE C.

DATAGS_FOLDER_ID LIKE SOODK,
       GS_ORDER_ID 
LIKE SOODK.

DATAGV_MAIL_TITLE(50).

DATAGT_RECEIVERS LIKE SOOS1 OCCURS WITH HEADER LINE.


INITIALIZATION.


START-OF-SELECTION.

  GV_MAIL_TITLE 
'这是邮件标题'.


** 发件人信息 edit
  
PERFORM SO_USER_READ.

**邮件信息、属性定义
  
PERFORM DOCUMENT_REPOSITORY.

**附件生成
  
PERFORM CREAT_ATTACHMENTS.

**send mail
  
PERFORM SEND.


*&---------------------------------------------------------------------*
*&      Form  SO_USER_READ
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SO_USER_READ .

  GS_USER
-SAPNAME SY-UNAME.
  
CALL FUNCTION 'SO_USER_READ_API1'
    
EXPORTING
      USER            
GS_USER
    
IMPORTING
      USER_DATA       
GS_USER_DATA
    
EXCEPTIONS
      USER_NOT_EXIST  =
 1
      PARAMETER_ERROR 
2
      X_ERROR         
3
      
OTHERS          4.
  
IF SY-SUBRC <> 0.
    
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  
ENDIF.

  GV_FOLD_TYPE   
GS_USER_DATA-OUTBOXFOL+0(3).
  GV_FOLD_YR     
GS_USER_DATA-OUTBOXFOL+3(2).
  GV_FOLD_NUMBER 
GS_USER_DATA-OUTBOXFOL+5(12).


  
CLEARGT_FILES[]GT_FILES.
  
REFRESH GT_OBJCNT,
  GT_OBJHEAD
,
  GT_OBJPARA
,
  GT_OBJPARB
,
  GT_RECEIPIENTS
,
  GT_ATTACHMENTS
,
  GT_REFERENCES
,
  GT_FILES
.
  
CLEAR  :    GS_DOCUMENT,
  GS_HEADER2
,
  GT_OBJCNT
,
  GT_OBJHEAD
,
  GT_OBJPARA
,
  GT_OBJPARB
,
  GT_RECEIPIENTS
,
  GT_ATTACHMENTS
,
  GT_REFERENCES
,
  GT_FILES
.


ENDFORM.                    " SO_USER_READ
*&---------------------------------------------------------------------*
*&      Form  DOCUMENT_REPOSITORY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DOCUMENT_REPOSITORY .
  GV_METHOD1 
'SAVE'.
  GS_DOCUMENT
-FOLTP   GV_FOLD_TYPE.
  GS_DOCUMENT
-FOLYR   GV_FOLD_YR.
  GS_DOCUMENT
-FOLNO   GV_FOLD_NUMBER.
  GS_DOCUMENT
-OBJTP   GS_USER_DATA-OBJECT_TYP.
*g_document-OBJYR   = '27'.
*g_document-OBJNO   = '000000002365'.
*g_document-OBJNAM = 'MESSAGE'.
  GS_DOCUMENT
-OBJDES   'mail of sap by program'.
  GS_DOCUMENT
-FOLRG   'O'.
*g_document-okcode   = 'CHNG'.
  GS_DOCUMENT
-OBJLEN '0'.
*  g_document-file_ext = 'TXT'.
  GS_HEADER2
-OBJDES GV_MAIL_TITLE.
*  g_header-file_ext = 'TXT'.

  
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
    
EXPORTING
      
METHOD       GV_METHOD1
      OFFICE_USER  
SY-UNAME
      REF_DOCUMENT 
GS_REF_DOCUMENT
      NEW_PARENT   
GS_NEW_PARENT
    
IMPORTING
      AUTHORITY    
GV_AUTHORITY
    
TABLES
      OBJCONT      
GT_OBJCNT
      OBJHEAD      
GT_OBJHEAD
      OBJPARA      
GT_OBJPARA
      OBJPARB      
GT_OBJPARB
      RECIPIENTS   
GT_RECEIPIENTS
      ATTACHMENTS  
GT_ATTACHMENTS
      REFERENCES   
GT_REFERENCES
      FILES        
GT_FILES
    
CHANGING
      DOCUMENT     
GS_DOCUMENT
      HEADER_DATA  
GS_HEADER2.

ENDFORM.                    " DOCUMENT_REPOSITORY
*&---------------------------------------------------------------------*
*&      Form  CREAT_ATTACHMENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CREAT_ATTACHMENTS .

* File from the pc to send..
  GV_METHOD1 
'ATTCREATEFROMPC'.

*  GV_SAVE_PATHT = P_FILE.
  GT_FILES
-TEXT 'C:\附件文件.xlsx'.

  
APPEND GT_FILES.

  
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
    
EXPORTING
      
METHOD       GV_METHOD1
      OFFICE_USER  
GV_OWNER
      REF_DOCUMENT 
GS_REF_DOCUMENT
      NEW_PARENT   
GS_NEW_PARENT
    
IMPORTING
      AUTHORITY    
GV_AUTHORITY
    
TABLES
      OBJCONT      
GT_OBJCNT
      OBJHEAD      
GT_OBJHEAD
      OBJPARA      
GT_OBJPARA
      OBJPARB      
GT_OBJPARB
      RECIPIENTS   
GT_RECEIPIENTS
      ATTACHMENTS  
GT_ATTACHMENTS
      REFERENCES   
GT_REFERENCES
      FILES        
GT_FILES
    
CHANGING
      DOCUMENT     
GS_DOCUMENT
      HEADER_DATA  
GS_HEADER2.

ENDFORM.                    " CREAT_ATTACHMENTS
*&---------------------------------------------------------------------*
*&      Form  SEND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SEND .
  
CLEARGS_FOLDER_ID,GS_ORDER_ID.
  GS_FOLDER_ID
-OBJTP GS_DOCUMENT-FOLTP .
  GS_FOLDER_ID
-OBJYR GS_DOCUMENT-FOLYR.
  GS_FOLDER_ID
-OBJNO GS_DOCUMENT-FOLNO.

  GS_ORDER_ID
-OBJTP GS_DOCUMENT-OBJTP.
  GS_ORDER_ID
-OBJYR GS_DOCUMENT-OBJYR.
  GS_ORDER_ID
-OBJNO GS_DOCUMENT-OBJNO.


*收件人信息可以添加多个收件人-----------------------------------
  
REFRESH GT_RECEIVERS.
  GT_RECEIVERS
-RECESC 'U'.
  GT_RECEIVERS
-SNDEX  = 'X'.
  GT_RECEIVERS
-RECEXTNAM 'name@163.com'.
  
APPEND GT_RECEIVERS.


  
CALL FUNCTION 'SO_OBJECT_SEND'
    
EXPORTING
      FOLDER_ID                  
GS_FOLDER_ID
      OBJECT_ID                  
GS_ORDER_ID
    
TABLES
      OBJCONT                    
GT_OBJCNT
      OBJHEAD                    
GT_OBJHEAD
      OBJPARA                    
GT_OBJPARA
      OBJPARB                    
GT_OBJPARB
      RECEIVERS                  
GT_RECEIVERS
      PACKING_LIST               
GT_ATTACHMENTS
    
EXCEPTIONS
      ACTIVE_USER_NOT_EXIST      
1
      COMMUNICATION_FAILURE      
2
      COMPONENT_NOT_AVAILABLE    
3
      FOLDER_NOT_EXIST           
4
      FOLDER_NO_AUTHORIZATION    
5
      FORWARDER_NOT_EXIST        
6
      NOTE_NOT_EXIST             
7
      OBJECT_NOT_EXIST           
8
      OBJECT_NOT_SENT            
9
      OBJECT_NO_AUTHORIZATION    
10
      OBJECT_TYPE_NOT_EXIST      
11
      OPERATION_NO_AUTHORIZATION 
12
      OWNER_NOT_EXIST            
13
      PARAMETER_ERROR            
14
      SUBSTITUTE_NOT_ACTIVE      
15
      SUBSTITUTE_NOT_DEFINED     
16
      SYSTEM_FAILURE             
17
      TOO_MUCH_RECEIVERS         
18
      USER_NOT_EXIST             
19
      X_ERROR                    
20
      
OTHERS                     21.

  
COMMIT WORK.

******直接发送邮件的代码********
  
SUBMIT RSCONN01 WITH MODE ='INT'
  
WITH OUTPUT 'X'
  
AND RETURN.
ENDFORM.                    " SEND

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页