메뉴 건너뛰기

SAP 한국 커뮤니티



CL_BCS를 이용한 E-Mail 즉시전송

사라다 2015.09.17 11:12 조회 수 : 6878 추천:2

SO_DOCUMENT_SEND_API1 펑션을 이용하면 백그라운드 작업에 의해 메일이 발송되서, 메일발송에 약간의 텀이 있길래

실행즉시 발송되는게 없을까 해서 구글링을 통해 찾아서 만들 CBO펑션입니다.


아마 다른 회원분께서 유사한걸 올렸을것 같지만, 제가 찾아볼때는 없길래 등록합니다 ^-^;;;;

혹시 중복이더라도 너그럽게 봐주세요~


<style type="text/css"> SPAN { font-family: "돋움체"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; background: #E6E6FA; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; } </style> FUNCTION ZBC_SEND_MAIL_IMMEDIATELY.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(I_SUBJECT) TYPE  SO_OBJ_DES              "메일 제목
*"  TABLES
*"      T_HTML STRUCTURE  SOLISTI1 OPTIONAL           "메일 내용
*"      T_RECV STRUCTURE  SOMLRECI1 OPTIONAL          "메일 수신자
*"  EXCEPTIONS
*"      MAIL_SENT_FAILED
*"----------------------------------------------------------------------

  DATA send_request       TYPE REF TO cl_bcs.
  DATA document           TYPE REF TO cl_document_bcs.
  DATA sender             TYPE REF TO cl_sapuser_bcs.
  DATA recipient          TYPE REF TO if_recipient_bcs.
  DATA exception_info     TYPE REF TO if_os_exception_info,
         bcs_exception      TYPE REF TO cx_bcs,
         t_hex              TYPE solix_tab,
         t_text              TYPE soli_tab,
         w_text like LINE OF t_text,
         html_string        TYPE string,
         xhtml_string       TYPE xstring,
         v_message(100),
         v_mail             TYPE  sza5_d0700-smtp_addr.


  CLEAR html_string.

  TRY.
*    Create persistent send request
    send_request cl_bcs=>create_persistent).

    loop at t_html.
      move t_html-line to w_text-line.
      append w_text to t_text.
    ENDLOOP.

    document cl_document_bcs=>create_document(
      i_type    'HTM'
      i_text    t_text
      "i_hex    = t_hex
      i_subject I_SUBJECT ).

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

*     Get sender object
    sender cl_sapuser_bcs=>createsy-uname ).

*     Add sender
    CALL METHOD send_request->set_sender
      EXPORTING
        i_sender sender.


    LOOP AT T_RECV.
      MOVE T_RECV-RECEIVER TO v_mail.

      recipient cl_cam_address_bcs=>create_internet_addressv_mail ).
*       Add recipient with its respective attributes to send request
      CALL METHOD send_request->add_recipient
        EXPORTING
          i_recipient recipient.
    ENDLOOP.

*     Set that you don't need a Return Status E-mail
    DATAstatus_mail TYPE bcs_stml.
    status_mail 'N'.

    CALL METHOD send_request->set_status_attributes
      EXPORTING
        i_requested_status status_mail
        i_status_mail      status_mail.

*     set send immediately flag
    send_request->set_send_immediately'X' ).

*     Send document
    CALL METHOD send_request->send).

    COMMIT WORK.

  CATCH cx_bcs INTO bcs_exception.
    v_message bcs_exception->get_text).
    RAISE MAIL_SENT_FAILED.
  ENDTRY.

ENDFUNCTION.