데이터 이메일(e-mail) xls 파일로 보내기

report zmailtest.

parametersp_email type somlreci1receiver
default ‘aaa@naver.com’.

databegin of it001 occurs 0,
bukrs type t001bukrs,
butxt type t001butxt,
end of it001.

dataimessage type standard table of solisti1 with header line,
iattach type standard table of solisti1 with header line,
ipacking_list like sopcklsti1 occurs with header line,
ireceivers like somlreci1 occurs with header line,
iattachment like solisti1 occurs with header line.

start-of-selection.

  select bukrs butxt into table it001 from t001.

*Populate table with detaisl to be entered into .xls file
  perform build_xls_data .

*Populate message body text
  clear imessagerefresh imessage.
  imessage ‘Please find attached excel file’.
  append imessage.

*Send file by email as .xls speadsheet
  perform send_email_with_xls tables imessage
  iattach
  using p_email
  ‘Example Excel Attachment’
  ‘XLS’
  ‘TestFileName’
  ‘CompanyCodes’.

************************************************************************
form build_xls_data.
************************************************************************

*constants: con_cret type x value ‘0D’, “OK for non Unicode
*con_tab type x value ’09’. “OK for non Unicode

*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
*constants:
 constantscon_tab type value cl_abap_char_utilities=>horizontal_tab,
 con_cret type value cl_abap_char_utilities=>cr_lf.

  concatenate ‘BUKRS’ ‘BUTXT’
  into iattach separated by con_tab.

  concatenate con_cret iattach into iattach.
  append iattach.

  loop at it001.
    concatenate it001bukrs it001butxt
    into iattach separated by con_tab.
    concatenate con_cret iattach into iattach.
    append iattach.
  endloop.

endform.                    “BUILD_XLS_DATA

************************************************************************
************************************************************************
form send_email_with_xls tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription.

  dataxdocdata like sodocchgi1,
  xcnt type i.

*Fill the document data.
  xdocdatadoc_size 1.

*Populate the subject/generic message attributes
  xdocdataobj_langu sylangu.
  xdocdataobj_name ‘SAPRPT’.
  xdocdataobj_descr p_mtitle .

*Fill the document data and get size of attachment
  clear xdocdata.
  read table iattach index xcnt.
  xdocdatadoc_size =
  xcnt – 255 strleniattach ).
  xdocdataobj_langu sylangu.
  xdocdataobj_name ‘SAPRPT’.
  xdocdataobj_descr p_mtitle.
  clear iattachmentrefresh iattachment.
  iattachment[] pit_attach[].

*Describe the body of the message
  clear ipacking_listrefresh ipacking_list.
  ipacking_listtransf_bin space.
  ipacking_listhead_start 1.
  ipacking_listhead_num 0.
  ipacking_listbody_start 1.
  describe table imessage lines ipacking_listbody_num.
  ipacking_listdoc_type ‘RAW’.
  append ipacking_list.

*Create attachment notification
  ipacking_listtransf_bin ‘X’.
  ipacking_listhead_start 1.
  ipacking_listhead_num 1.
  ipacking_listbody_start 1.

  describe table iattachment lines ipacking_listbody_num.
  ipacking_listdoc_type p_format.
  ipacking_listobj_descr p_attdescription.
  ipacking_listobj_name p_filename.
  ipacking_listdoc_size ipacking_listbody_num * 255.
  append ipacking_list.

*Add the recipients email address
  clear ireceiversrefresh ireceivers.
  ireceiversreceiver p_email.
  ireceiversrec_type ‘U’.
  ireceiverscom_type ‘INT’.
  ireceiversnotif_del ‘X’.
  ireceiversnotif_ndel ‘X’.
  append ireceivers.

  call function ‘SO_DOCUMENT_SEND_API1’
    exporting
      document_data              xdocdata
      put_in_outbox              ‘X’
      commit_work                ‘X’
    tables
      packing_list               ipacking_list
      contents_bin               iattachment
      contents_txt               imessage
      receivers                  ireceivers
    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.

endform.                    “send_email_with_xls


2 Comments

avatar

좋은정보 감사합니다

avatar

4.6C 버전에서 이렇게 메일을 보내니 메일제목과 첨부파일제목등등 한글이 모두 깨져서 보내지는데 ecc 이상에서 사용하는

cl_abap_conv_in_ce 클래스는 4.6c에서는 사용하지 못하는데 방법이 없을까요?

Leave a Reply