Tabloyu Excel Olarak Email Atma
Internal tablo excel olarak attachmentlara eklenebilir. Renklendirme, sınır çizme gibi excel hücreleri özellikleri ile oynama yapılamaz.
FORM f_send_mail.
CLASS: cl_abap_char_utilities DEFINITION LOAD.
TYPES: BEGIN OF ty_email,
smtp_addr TYPE ad_smtpadr,
END OF ty_email.
DATA: lt_objpack TYPE STANDARD TABLE OF sopcklsti1,
lt_imessage TYPE STANDARD TABLE OF solisti1,
lt_reclist TYPE STANDARD TABLE OF somlreci1,
lt_objbin TYPE STANDARD TABLE OF solisti1,
lc_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
lc_ret TYPE c VALUE cl_abap_char_utilities=>newline,
ls_objbin LIKE LINE OF lt_objbin,
ls_imessage LIKE LINE OF lt_imessage,
ls_reclist TYPE somlreci1,
ls_doc_chng TYPE sodocchgi1,
ls_orders TYPE sfc_poco,
ls_objpack TYPE sopcklsti1.
DATA: lt_bname TYPE TABLE OF zpp_t_0415,
lt_email TYPE TABLE OF ty_email,
ls_email LIKE LINE OF lt_email,
lv_lines_bin TYPE i,
lv_message_lines TYPE i,
lv_tarih(10),
lv_kapasite(20),
lv_mevdrm(20),
lv_mevton(20),
lv_ort_vb(20),
lv_doluluk(20),
lv_mev_vb(20).
CHECK me->mt_100_itab IS NOT INITIAL.
"Alıcılar
SELECT * FROM zpp_t_0415 INTO TABLE lt_bname.
IF NOT lt_bname[] IS INITIAL.
SELECT smtp_addr FROM adr6
INNER JOIN usr21 ON usr21~persnumber = adr6~persnumber
AND usr21~addrnumber = adr6~addrnumber
INTO TABLE lt_email
FOR ALL ENTRIES IN lt_bname
WHERE bname EQ lt_bname-bname.
ENDIF.
LOOP AT lt_email INTO ls_email.
CLEAR ls_reclist.
ls_reclist-receiver = ls_email-smtp_addr.
ls_reclist-rec_type = `U`.
APPEND ls_reclist TO lt_reclist.
ENDLOOP.
CHECK lt_reclist[] IS NOT INITIAL.
"The text for body of the mail
CLEAR ls_imessage.
ls_imessage-line = `Sayın Yetkili,`.
APPEND ls_imessage TO lt_imessage.
CLEAR ls_imessage.
ls_imessage-line = ``.
APPEND ls_imessage TO lt_imessage.
CLEAR ls_imessage.
CONCATENATE `Günlük Raporu`
`ekteki excel dosyasında bulabilirsiniz` INTO ls_imessage-line
SEPARATED BY space.
APPEND ls_imessage TO lt_imessage.
"No of lines for body of mail
DESCRIBE TABLE lt_imessage LINES lv_message_lines.
READ TABLE lt_imessage INTO ls_imessage INDEX lv_message_lines.
"document information
ls_doc_chng-obj_name = `Excel`.
ls_doc_chng-obj_langu = sy-langu.
ls_doc_chng-obj_descr = `Günlük Doluluk Oranları`.
ls_doc_chng-sensitivty = `F`.
"Calculating total size of doc
ls_doc_chng-doc_size = ( lv_message_lines - 1 ) * 255 + strlen( ls_imessage-line ).
"Başlıklar
CONCATENATE `Tarih` `Açıklama` `Depo` `Kapasite`
INTO ls_objbin SEPARATED BY lc_tab.
APPEND ls_objbin TO lt_objbin.
LOOP AT me->mt_100_itab ASSIGNING FIELD-SYMBOL(<lfs_itab>).
CLEAR: ls_objbin.
TRANSLATE <lfs_itab>-tanim TO UPPER CASE.
CLEAR: lv_kapasite.
WRITE: <lfs_itab>-kapasite TO lv_kapasite.
CONDENSE: lv_kapasite.
CLEAR lv_tarih.
CONCATENATE sy-datum+6(2) `.` sy-datum+4(2) `.`
sy-datum(4) INTO lv_tarih.
CONCATENATE lv_tarih <lfs_itab>-tanim <lfs_itab>-depo lv_kapasite
INTO ls_objbin SEPARATED BY lc_tab.
CONCATENATE lc_ret ls_objbin INTO ls_objbin.
APPEND ls_objbin TO lt_objbin.
ENDLOOP.
UNASSIGN <lfs_itab>.
DESCRIBE TABLE lt_objbin LINES lv_lines_bin. "No of lines for excel data
" pack the data as RAW
CLEAR ls_objpack-transf_bin. "Obj. to be transported not in binary form
ls_objpack-head_start = 1.
ls_objpack-head_num = 0.
ls_objpack-body_start = 1.
ls_objpack-body_num = lv_message_lines.
ls_objpack-doc_type = `RAW`.
APPEND ls_objpack TO lt_objpack.
"Pack the data as excel
ls_objpack-transf_bin = `X`.
ls_objpack-head_start = 1.
ls_objpack-head_num = 1.
ls_objpack-body_start = 1.
ls_objpack-body_num = lv_lines_bin.
ls_objpack-doc_type = `XLA`. "XLS
ls_objpack-obj_name = `Doluluk`.
ls_objpack-obj_langu = sy-langu.
"Attachment name
CONCATENATE `Doluluk_` sy-datum `.XLA` INTO ls_objpack-obj_descr. "`.XLS`
ls_objpack-doc_size = lv_lines_bin * 255.
APPEND ls_objpack TO lt_objpack.
"Sending mail
CALL FUNCTION `SO_NEW_DOCUMENT_ATT_SEND_API1`
EXPORTING
document_data = ls_doc_chng
put_in_outbox = `X`
commit_work = `X`
TABLES
packing_list = lt_objpack
contents_bin = lt_objbin
contents_txt = lt_imessage
receivers = lt_reclist
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.
IF sy-subrc EQ 0.
MESSAGE s398(00) WITH ` Email Gönderildi!`.
ENDIF.
ENDFORM.