`
jgtang82
  • 浏览: 406316 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

A quite easy way to send email in ABAP

    博客分类:
  • ABAP
阅读更多

report zrich_0002.
 
data: maildata   like sodocchgi1.
data: mailtxt    like solisti1 occurs 10 with header line.
data: mailrec    like somlrec90 occurs 0  with header line.
 
start-of-selection.
  clear:    maildata, mailtxt,  mailrec.
  refresh:  mailtxt, mailrec.
 
  maildata-obj_name = 'TEST'.
  maildata-obj_descr = 'Test Subject'.
 
  mailtxt  = '<html>'.
  append mailtxt.
 
  mailtxt  = '<body>'.
  append mailtxt.
 
  mailtxt  = '<b>This is SAP</b>'.
  append mailtxt.
 
  mailtxt  = '<a href="#" target="_blank">SAP Hyperlink</a> '.
  append mailtxt.
 
  mailtxt  = '</body>'.
  append mailtxt.
 
  mailtxt  = '</html>'.
  append mailtxt.
 
  mailrec-receiver = 'you@yourcompany.com'.
  mailrec-rec_type  = 'U'.
  append mailrec.
 
  call function 'SO_NEW_DOCUMENT_SEND_API1'
       exporting
            document_data              = maildata
            document_type              = 'HTM'
            put_in_outbox              = 'X'
       tables
            object_header              = mailtxt
            object_content             = mailtxt
            receivers                  = mailrec
       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.

 

---------------------------------------------------------------------------------------------

REPORT  zsendmail.

DATA: lv_title          TYPE so_obj_des,
      send_request   TYPE REF TO CL_BCS,
      document         TYPE REF TO CL_DOCUMENT_BCS,
      conlengths        TYPE so_obj_len,
      html                  TYPE STANDARD TABLE OF w3html,
      wa_html           TYPE w3html,
      sender_id         TYPE REF TO IF_SENDER_BCS,
      recipient           TYPE REF TO IF_RECIPIENT_BCS,
      sent_to_all       TYPE os_boolean,
      bcs_exception  TYPE REF TO cx_bcs,
      bcs_message   TYPE string.

 

lv_title = 'This is the title'.

wa_html-line = '<html><body>'.
APPEND wa_html TO html.
...
wa_html-line = '</body></html>'.
APPEND wa_html TO html.


TRY.
    CLEAR send_request.
    send_request = cl_bcs=>create_persistent( ).
   
    CLEAR document .
    document =  cl_document_bcs=>create_document(
                    i_type =    'HTM'
                    i_text =     html
                    i_length =  conlengths
                    i_subject = lv_title ).

*   Add document to send request
    CALL METHOD send_request->set_document( document ).

 

*   Construct sender and receiver
    CLEAR: sender_id , recipient .
    sender_id = cl_cam_address_bcs=>create_internet_address( 'abc@zh.cn' ).
    recipient = cl_cam_address_bcs=>create_internet_address( 'bcd@zh.cn' ).

 

*   Set sender
    CALL METHOD send_request->set_sender
      EXPORTING
        i_sender = sender_id.

 

*   Add recipient with its respective attributes to send request
    CALL METHOD send_request->add_recipient
      EXPORTING
        i_recipient = recipient
        i_express   = 'X'.

 

*   Set E-mail sending options
    CALL METHOD send_request->set_status_attributes
      EXPORTING
        i_requested_status = 'E'
        i_status_mail      = 'E'.
    CALL METHOD send_request->set_send_immediately( 'X' ).

 

*   Send document
    CALL METHOD send_request->send(
     EXPORTING
       i_with_error_screen = 'X'
     RECEIVING
       result = sent_to_all ).
      
    IF sent_to_all = 'X'.
      MESSAGE 'Mail sent successfully ' TYPE 'S'.
    ENDIF.
    COMMIT WORK.


  CATCH cx_bcs INTO bcs_exception.
    bcs_message = bcs_exception->get_text( ).
    MESSAGE bcs_exception TYPE 'E'.
    EXIT.
ENDTRY.

 

******************************************
<!----> * get sender email address.

<!----> CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
    EXPORTING
        USER_NAME              = LV_BNAME
*       READ_DB_DIRECTLY       = ' '
    IMPORTING
        USER_ADDRESS           = FS_ADDR
        USER_USR03             = FS_USR03
    EXCEPTIONS
        USER_ADDRESS_NOT_FOUND = 1
        OTHERS                 = 2.

分享到:
评论
2 楼 jgtang82 2008-04-25  
自己感兴趣,做得开心是最重要的。
1 楼 titanfoot 2008-04-24  
记得2001年的时候想搞Sap,学习学习ABAP,可是当时资料太少了,还是没有选这条路啊!赫赫

相关推荐

    SAP RFC Programming in ABAP

    根据给定的文件信息,我们可以深入探讨"SAP RFC Programming in ABAP"这一主题,这是一个在SAP系统中非常重要的技术领域,特别是在企业级应用集成和跨系统数据交换方面。 ### SAP RFC编程基础 SAP Remote Function...

    ABAP751 ABAP - Keyword Documentation

    A complete description of all ABAP keywords in their relevant context. ABAP - Quick Reference A short overview of all statements, ordered alphabetically. ABAP - Release-Specific Changes List ...

    BC415 Communication Interfaces in ABAP

    SAP BC415 Communication Interfaces in ABAP

    Enabling ABAP in Eclipse

    【Enabling ABAP in Eclipse】是一项让ABAP开发者能够在Eclipse集成开发环境中进行开发的工作。这一功能的引入为ABAP程序员提供了更为现代化和灵活的开发工具,与传统的SAP Development Workbench相比,Eclipse提供...

    abap plug-in eclipse

    Eclipse ABAP插件是开发SAP ABAP应用程序的一个强大工具,它允许开发人员在集成的开发环境中(IDE)编写、测试和调试ABAP代码。Eclipse作为一个高度可扩展的平台,通过添加特定的插件,如ABAP插件,可以支持多种编程...

    Advanced ABAP Programming for SAP

    This book assumes a basic familiarity with the ABAP language (formerly known as ABAP/4) and builds upon it, exposing the reader to ABAP's considerable customization and transaction-handling power ...

    ABAP in BW

    ABAP in BW是SAP BW(商务仓库)系统中用于编程和增强后端功能的ABAP(高级企业应用编程)技术的专称。本知识点将从ABAP在BW中的应用、性能优化、增强机制以及数据处理等方面进行详细解读。 首先,ABAP in BW的学习...

    External ABAP/4 Editor

    The ABAP/4 Development Workbench contains all the tools you need to create and maintain ABAP/4 programs, however the standard SAP ABAP/4 editor does not have the features like the development tools ...

    TCP-IP socket programming in ABAP_in_TCPIPABAP_

    在ABAP编程环境中,TCP/IP套接字编程是实现与外部系统进行网络通信的重要手段。TCP/IP协议族是互联网上最广泛使用的通信协议,而ABAP作为SAP系统的编程语言,支持通过TCP/IP进行socket通信,允许ABAP程序直接与任何...

    ABAP 调用ABAP PROXY

    在SAP系统中,ABAP调用ABAP Proxy是一种常见的技术操作,用于在不同系统间或者同一系统内的组件之间实现通信。ABAP Proxy是SAP提供的一个强大的接口技术,它允许开发者创建安全、高效的远程调用机制。接下来,我们将...

    ABAP 函数介绍

    ABAP 函数调用方法详解 ABAP 函数调用是 SAP 系统中的一种常用技术,用于实现业务逻辑的复杂处理。该技术可以实现同步调用和异步调用两种方式,本文将对这两种方式进行详细的介绍。 1. 异步调用 异步调用是指在主...

    SAP ABAP in 21 days.

    ### SAP ABAP in 21 Days #### 一、引言与学习目标 《SAP ABAP in 21 Days》是一本旨在帮助初学者快速掌握SAP ABAP编程语言的指南书。这本书通过为期三周的教学计划,系统地介绍了ABAP的基础知识和技术要点。作者...

    SAP RFC ABAP编辑器

    The User's Guide is a manual on the external ABAP/4 editor developed by Attila Borka (X-Direct Ltd.). Its aim is to • Describe the functions and the usage of the editor • Guide SAP Basis ...

    SAP Note 176336: Flat and deep structures in ABAP

    ### SAP Note 176336: Flat and Deep Structures in ABAP #### 概述 SAP Note 176336 主要关注 ABAP 编程语言中的扁平(flat)结构与深层(deep)结构的概念。在 ABAP 中,结构是一种复杂的数据类型,用于组织和...

    abap tips abap tips

    abap tips abap tips abap tips abap tips abap tips

    ABAP常用字符串操作

    ### ABAP常用字符串操作知识点详解 #### 一、字符串连接 在ABAP中,字符串连接是一种常见的操作方式,用于将两个或多个字符串合并成一个新的字符串。实现字符串连接的方法主要是通过`CONCATENATE`语句。 **语法...

    SAP_ABAP_4.7.rar_SAP abap4_abap_abap chm_abap 4_abap4

    《SAP ABAP 4.7开发指南》 在企业级信息技术领域,SAP系统扮演着至关重要的角色,尤其在企业资源规划(ERP)方面。SAP ABAP(Advanced Business Application Programming)是SAP系统中的一种编程语言,用于开发、...

    Remote Function Calls in ABAP

    本培训课程"Remote Function Calls in ABAP"旨在教授开发人员如何有效地利用RFC进行跨系统交互。 RFC是一种标准化的接口技术,使得ABAP程序能够调用远程系统中的函数模块,就像它们是本地函数模块一样。这在分布式...

    Developing UI5 Apps Purely in ABAP.zip

    标题“Developing UI5 Apps Purely in ABAP”指出,这个压缩包可能包含关于如何在ABAP环境中开发UI5应用程序的资源。UI5是SAP提供的一个开源框架,用于构建企业级的用户界面,而ABAP(Advanced Business Application...

Global site tag (gtag.js) - Google Analytics