메뉴 건너뛰기

SAP 한국 커뮤니티



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

sapjoy 2014.10.10 09:06 조회 수 : 6675

report zmailtest.

parametersp_email type somlreci1-receiver
default 'aaa@naver.com'.

databegin of it001 occurs 0,
bukrs type t001-bukrs,
butxt type t001-butxt,
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 it001-bukrs it001-butxt
    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.
  xdocdata-doc_size 1.

*Populate the subject/generic message attributes
  xdocdata-obj_langu sy-langu.
  xdocdata-obj_name 'SAPRPT'.
  xdocdata-obj_descr p_mtitle .

*Fill the document data and get size of attachment
  clear xdocdata.
  read table iattach index xcnt.
  xdocdata-doc_size =
  xcnt 255 strleniattach ).
  xdocdata-obj_langu sy-langu.
  xdocdata-obj_name 'SAPRPT'.
  xdocdata-obj_descr p_mtitle.
  clear iattachmentrefresh iattachment.
  iattachment[] pit_attach[].

*Describe the body of the message
  clear ipacking_listrefresh ipacking_list.
  ipacking_list-transf_bin space.
  ipacking_list-head_start 1.
  ipacking_list-head_num 0.
  ipacking_list-body_start 1.
  describe table imessage lines ipacking_list-body_num.
  ipacking_list-doc_type 'RAW'.
  append ipacking_list.

*Create attachment notification
  ipacking_list-transf_bin 'X'.
  ipacking_list-head_start 1.
  ipacking_list-head_num 1.
  ipacking_list-body_start 1.

  describe table iattachment lines ipacking_list-body_num.
  ipacking_list-doc_type p_format.
  ipacking_list-obj_descr p_attdescription.
  ipacking_list-obj_name p_filename.
  ipacking_list-doc_size ipacking_list-body_num * 255.
  append ipacking_list.

*Add the recipients email address
  clear ireceiversrefresh ireceivers.
  ireceivers-receiver p_email.
  ireceivers-rec_type 'U'.
  ireceivers-com_type 'INT'.
  ireceivers-notif_del 'X'.
  ireceivers-notif_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
번호 제목 글쓴이 날짜 조회 수
107 KR_POSTCODE : 한국주소입력 Version 2.0 대략나 2021.03.31 980
106 HTTP 통신하는 로직 [3] 대략나 2016.12.20 5636
105 XML 을 아밥 스트럭쳐 또는 인터널테이블로 변경시키는 로직 [1] 대략나 2016.12.20 3790
104 ALV EDIT 샘플 프로그램 sapjoy 2015.06.26 9246
103 파일 메일(e-mail) 첨부로 보내기 [2] sapjoy 2014.10.10 7180
» 데이터 이메일(e-mail) xls 파일로 보내기 [2] sapjoy 2014.10.10 6675
101 Tree ALV 샘플 [5] 양키(이경환) 2014.02.05 10514
100 Split 의 사용 [1] 양키(이경환) 2014.02.05 10665
99 소수점 뒷자리 0 제거 로직 file 양키(이경환) 2014.01.19 9429
98 10이하의 홀수 마방진 은미짱 2013.10.18 6787
97 [Module pool] Container에 webpage 넣기. [2] 냥냥 2013.03.19 11196
96 COMAPY CODE에 할당된 Fiscal variant에 대한 calendar date 변환 paran 2013.02.28 10463
95 멀 어떻게 해야 하는건질 몰라 질문 드립니다 [5] 쏠라맨 2012.10.12 11662
94 nugg 프로그램을 sap 에 생성하기.. [3] file MadMax 2012.10.11 10825
93 인터널 테이블을 사용한 구구단 출력 두가지 입니다 - WRITE, ALV 이용 [1] kofnhuge 2012.10.10 14009
92 Search For Program/Function/Table Desc&Name [8] file 초짜 2011.09.30 9830
91 스크린에서 버튼을 tree 처럼 만들기. [32] file Jenny 2011.08.11 17655
90 통화단위, krw, usd 일반 필드에 변환시 로직(소수점, 자리수) [4] sapjoy 2011.07.19 15561
89 Dynamic Select 소스 [5] 떡밥 2011.06.03 17768
88 [onepaper] 참고자료 Archiving 세팅에 필요한 파일소스입니다. [7] file 원니컴 2011.03.22 13798