메뉴 건너뛰기

SAP 한국 커뮤니티



excel 파일 첨부해서 E-mail 보내기

김영욱 2008.09.24 10:35 조회 수 : 642

자료실에 보니까 아래 소스 올려놓으셨는데


데이터 선언 부분이 없어서 프로그램 실행이 안되더라구요..


(누군가 데이터 선언부좀 올려달라는 답글을 보고..^^)


 


아직 제대로 실행을 해보지는 않았지만 데이터 선언부터 다 되어있어서 테스트 해 보실 수 있을 거같네요..


좀더 수정해서 완벽히 된다면 다시 수정해서 올리겠습니다..


 


혹..SAP에서 XLS 파일 첨부해서 보내는 소스 다른것 있으시면 공유좀 해주세요..^^;;


===============================================================================================================


 


Elde ettiğimiz sonuçların mail edilmesi ile alakalı daha önce bir rapor yazmıştım. Şimdiki rapor elde ettiğimiz internal table sonucunu XLS formatına çeviriyor. Elde edilen bu dosya gönderilecek e-mail adresine attach ediliyor.



Ekteki kodda sabit bir dosya yapısı oluşturulmakta (EBELN,EBLP… alanları manuel olarak create ediliyor) Bunu daha da geliştirip otomatik yapı oluşturabiliriz.



*———————————————————————*
* Report Name : YGECICI
*———————————————————————*
* Author : Mehmet Avşar
* Location : @Altunizade - Uskudar / Istanbul
* Date / Time : 05 Jan 2007
*———————————————————————*
REPORT YGECICI MESSAGE-ID 00
No Standard Page Heading
Line-Size 200
Line-Count 65.


TABLES: ekko.


PARAMETERS: p_email   TYPE somlreci1-receiver
DEFAULT ‘mavsar@hayat.com.tr’.


TYPESBEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.


TYPESBEGIN OF t_charekpo,
ebeln(10TYPE c,
ebelp(5)  TYPE c,
aedat(8)  TYPE c,
matnr(18TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.


DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.


DATA:   t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error    TYPE sy-subrc,
gd_reciever TYPE sy-subrc.


************************************************************************
*START_OF_SELECTION
START-OF-SELECTION.
*   Retrieve sample data from table ekpo
PERFORM data_retrieval.


*   Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.


************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
* Populate message body text
perform populate_email_message_body.


* Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
‘Example .xls documnet attachment’
‘XLS’
‘filename’
‘ ’
‘ ’
‘ ’
changing gd_error
gd_reciever.


*   Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.


*&———————————————————————*
*&      Form  DATA_RETRIEVAL
*&———————————————————————*
*       Retrieve data form EKPO table and populate itab it_ekko
*———————————————————————-*
FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
ENDFORM.                    “ DATA_RETRIEVAL


*&———————————————————————*
*&      Form  BUILD_XLS_DATA_TABLE
*&———————————————————————*
*       Build data table for .xls document
*———————————————————————-*
FORM build_xls_data_table.
CONSTANTS:
*             con_cret TYPE x VALUE ’0D’,  ”OK for non Unicode
*             con_tab TYPE x VALUE ’09′.   ”OK for non Unicode


con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.


*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:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
*    con_cret type c value cl_abap_char_utilities=>CR_LF.


CONCATENATE ‘EBELN’ ‘EBELP’ ‘AEDAT’ ‘MATNR’
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach  INTO it_attach.
APPEND  it_attach.


LOOP AT it_ekpo INTO wa_charekpo.
CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
wa_charekpo-aedat wa_charekpo-matnr
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach  INTO it_attach.
APPEND  it_attach.
ENDLOOP.
ENDFORM.                    “ BUILD_XLS_DATA_TABLE


*&———————————————————————*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&———————————————————————*
*       Send email
*———————————————————————-*
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.


DATA: ld_error    TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE  somlreci1-receiver,
ld_format TYPE  so_obj_tp ,
ld_attdescription TYPE  so_obj_nam ,
ld_attfilename TYPE  so_obj_des ,
ld_sender_address LIKE  soextreci1-receiver,
ld_sender_address_type LIKE  soextreci1-adr_typ,
ld_receiver LIKE  sy-subrc.


ld_email   = p_email.
ld_mtitle = p_mtitle.
ld_format              = p_format.
ld_attdescription      = p_attdescription.
ld_attfilename         = p_filename.
ld_sender_address      = p_sender_address.
ld_sender_address_type = p_sender_addres_type.


* Fill the document data.
w_doc_data-doc_size = 1.


* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name  = ‘SAPRPT’.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = ‘F’.


* Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu  = sy-langu.
w_doc_data-obj_name   = ‘SAPRPT’.
w_doc_data-obj_descr  = ld_mtitle.
w_doc_data-sensitivty = ‘F’.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].


* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = ‘RAW’.
APPEND t_packing_list.


* Create attachment notification
t_packing_list-transf_bin = ‘X’.
t_packing_list-head_start = 1.
t_packing_list-head_num   = 1.
t_packing_list-body_start = 1.


DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type   =  ld_format.
t_packing_list-obj_descr  =  ld_attdescription.
t_packing_list-obj_name   =  ld_attfilename.
t_packing_list-doc_size   =  t_packing_list-body_num * 255.
APPEND t_packing_list.


* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = ‘U’.
t_receivers-com_type = ‘INT’.
t_receivers-notif_del = ‘X’.
t_receivers-notif_ndel = ‘X’.
APPEND t_receivers.


CALL FUNCTION ‘SO_DOCUMENT_SEND_API1′
EXPORTING
document_data              = w_doc_data
put_in_outbox              = ‘X’
sender_address             = ld_sender_address
sender_address_type        = ld_sender_address_type
commit_work                = ‘X’
IMPORTING
sent_to_all                = w_sent_all
TABLES
packing_list               = t_packing_list
contents_bin               = t_attachment
contents_txt               = it_message
receivers                  = t_receivers
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.


* Populate zerror return code
ld_error = sy-subrc.


* Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.


*&———————————————————————*
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*&———————————————————————*
*       Instructs mail send program for SAPCONNECT to send email.
*———————————————————————-*
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = ‘INT’
WITH output = ‘X’
AND RETURN.
ENDFORM.                    “ INITIATE_MAIL_EXECUTE_PROGRAM


*&———————————————————————*
*&      Form  POPULATE_EMAIL_MESSAGE_BODY
*&———————————————————————*
*        Populate message body text
*———————————————————————-*
form populate_email_message_body.
REFRESH it_message.
it_message = ‘Please find attached a list test ekpo records’.
APPEND it_message.
endform.                    “ POPULATE_EMAIL_MESSAGE_BODY


* e-abap님에 의해서 게시물 이동되었습니다 (2008-10-14 10:05)
번호 제목 글쓴이 날짜 조회 수
238 <img src=b.gif>ABAP교육 PPT입니다.[추천자:e-abap] [12] file hooa 2009.08.07 1824
237 <img src=b.gif>DB연결방법 나름 정리했습니다.[추천:보나] [15] file 도련님 2010.01.27 1614
236 BTE Overview입니다.[추천:e-abap] [26] file Wowking 2007.08.13 1581
235 bapi 찾는 프로그램 [12] file 풍운사랑 2008.12.08 1520
234 [ABAP]ABAP정식교재_PDF [14] file sapjoy 2007.01.23 1458
233 ABAP EDITOR [1] file 솔로몬 2007.06.27 1412
232 SAP에서 EXCEL 첨부해서 E-MAIL 보내기2 [13] 김영욱 2008.10.02 1394
231 ABAP강의자료1~2 [7] file Delight 2008.04.23 1312
230 이벤트를 이용한 스케쥴잡을 정리하였습니다.썬바바님 감사합니다. [12] file 노름마치 2007.08.21 1310
229 병렬처리(parallel process) [9] file sapjoy 2007.01.29 1268
228 15장 SAP SCREIPT [2] file sapjoy 2007.03.28 1266
227 ABAP 초보탈출 교육교재 [30] file ㅇㅇㅇ 2008.03.17 1211
226 유저에 맞는 날짜 포맷 세팅하는 코딩.. [12] file 지의 2007.09.28 1177
225 ABAP_Review [8] file BC고 2009.05.14 1089
224 <img src=a.gif>OLE 엑셀 등록방법 및 출력 응용 예제 프로그램[추천:e-abap][추천:열공아밥]<img src=b.gif> [15] file 안규 2009.04.24 1073
223 <img src=c.gif>SAP Script 따라하기[추천:열공아밥][추천:e-abap] [18] file 초보보초보 2007.02.28 1063
222 릴리즈된 프로그램 다시 수정상태로 변경하는법 [21] file Zking 2008.11.18 956
221 ALV 템플릿 입니다.. [9] file wsj1122 2007.08.27 931
220 User-Exits 관련 파일 [21] file 스땐 2008.11.04 917
219 BDC 정리 파일 [29] file 하얀콩 2007.05.15 910