Internal Tablonun HTML olarak Email Atılması
`WWW_ITAB_TO_HTML` fonksiyonunu kullanarak itabı html olarak email içinde atılması.
PERFORM f_send_mail.
*&---------------------------------------------------------------------*
*& Form F_SEND_MAIL
*&---------------------------------------------------------------------*
FORM f_send_mail.
DATA: t_objbin TYPE STANDARD TABLE OF solisti1 , " Attachment data
t_objtxt TYPE STANDARD TABLE OF solisti1 , " Message body
t_objpack TYPE STANDARD TABLE OF sopcklsti1, " Packing list
t_reclist TYPE STANDARD TABLE OF somlreci1 , " Receipient list
t_objhead TYPE STANDARD TABLE OF solisti1 , " Header
wa_docdata TYPE sodocchgi1, " Document data
wa_objbin TYPE solisti1 , " Attachment data
wa_objtxt TYPE solisti1 , " Message body
wa_objpack TYPE sopcklsti1, " Packing list
wa_reclist TYPE somlreci1 , " Receipient list
lv_body TYPE string.
DATA: ls_sso_hata LIKE LINE OF gt_sso_hata,
lt_sso_mail TYPE TABLE OF zsd_t_mail,
lt_hata TYPE TABLE OF zsd_s_hata_mail,
ls_hata LIKE LINE OF lt_hata.
DATA: BEGIN OF lt_email OCCURS 0,
smtp_addr TYPE ad_smtpadr,
END OF lt_email.
CHECK gt_sso_hata[] IS NOT INITIAL.
PERFORM f_build_fcat_mail.
REFRESH lt_hata[].
LOOP AT gt_sso_hata INTO ls_sso_hata.
CLEAR ls_hata.
MOVE-CORRESPONDING ls_sso_hata TO ls_hata.
APPEND ls_hata TO lt_hata.
ENDLOOP.
*- Başlık
wa_docdata-obj_descr = `Arayüz Hataları` .
wa_objtxt-line = `Sayın yetkili,`.
APPEND wa_objtxt TO t_objtxt.CLEAR wa_objtxt.
CLEAR wa_objtxt-line.
APPEND wa_objtxt TO t_objtxt.CLEAR wa_objtxt.
CONCATENATE `Aşağıda bulunan Organizasyon ID aktarım hatalarını`
`ZSD_T_HATA tablosundan kontrol ediniz!`
INTO lv_body SEPARATED BY space .
wa_objtxt-line = lv_body .
APPEND wa_objtxt TO t_objtxt.CLEAR wa_objtxt.
wa_objtxt-line = `
`.
APPEND wa_objtxt TO t_objtxt.CLEAR wa_objtxt.
PERFORM itab_to_html TABLES lt_hata
t_objtxt.
wa_objtxt-line = `
`.
APPEND wa_objtxt TO t_objtxt.CLEAR wa_objtxt.
APPEND wa_objtxt TO t_objtxt.CLEAR wa_objtxt.
*- Alıcı
SELECT * FROM zsd_t_mail INTO TABLE lt_sso_mail.
IF NOT lt_sso_mail[] 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_sso_mail
WHERE bname EQ lt_sso_mail-bname.
ENDIF.
LOOP AT lt_email.
wa_reclist-receiver = lt_email-smtp_addr.
wa_reclist-rec_type = `U` .
APPEND wa_reclist TO t_reclist.
ENDLOOP.
CHECK t_reclist[] IS NOT INITIAL.
*- Mailin Gönderilmesi
PERFORM f_call_mail_func TABLES t_objpack
t_objhead
t_objtxt
t_reclist
USING wa_docdata .
ENDFORM. " F_SEND_MAIL
*&---------------------------------------------------------------------*
*& Form F_BUILD_FCAT_MAIL
*&---------------------------------------------------------------------*
FORM f_build_fcat_mail.
FIELD-SYMBOLS: LIKE LINE OF gt_fieldcat.
CALL FUNCTION `REUSE_ALV_FIELDCATALOG_MERGE`
EXPORTING
i_program_name = sy-repid
i_structure_name = `ZSD_S_HATA_MAIL`
i_inclname = sy-repid
CHANGING
ct_fieldcat = gt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
LOOP AT gt_fieldcat ASSIGNING .
CASE -fieldname.
WHEN `TID` .
-reptext_ddic = -seltext_l =
-seltext_m = -seltext_s = `TID`.
-ddictxt = `L`.
WHEN `TARIH` .
-reptext_ddic = -seltext_l =
-seltext_m = -seltext_s = `Tarih`.
-ddictxt = `L`.
WHEN `MESAJ` .
-reptext_ddic = `Hata Açıklaması`.
-seltext_l = `Hata Açıklaması`.
-seltext_m = `Hata`.
-seltext_s = `Hata`.
-ddictxt = `L`.
ENDCASE .
ENDLOOP.
UNASSIGN .
ENDFORM. " F_BUILD_FCAT_MAIL
*&---------------------------------------------------------------------*
*& Form ITAB_TO_HTML
*&---------------------------------------------------------------------*
FORM itab_to_html TABLES pt_out STRUCTURE zsdka_s_sso_hata_mail
pt_objtxt STRUCTURE solisti1.
DATA : ihtml TYPE TABLE OF w3html WITH HEADER LINE ,
ifields TYPE TABLE OF w3fields WITH HEADER LINE ,
ls_header TYPE w3head ,
lt_header TYPE TABLE OF w3head WITH HEADER LINE ,
wa_objtxt TYPE solisti1 . " Message body
DATA: lv_sira TYPE int4,
ls_fieldcat LIKE LINE OF gt_fieldcat.
wa_objtxt-line = ``.
APPEND wa_objtxt TO pt_objtxt.CLEAR wa_objtxt.
wa_objtxt-line = ``.
APPEND wa_objtxt TO pt_objtxt.CLEAR wa_objtxt.
LOOP AT gt_fieldcat INTO ls_fieldcat.
lv_sira = lv_sira + 1 .
lt_header-just = ls_fieldcat-just.
lt_header-icon = ls_fieldcat-icon.
lt_header-nr = lv_sira.
lt_header-lnr = ls_fieldcat-row_pos.
lt_header-text = ls_fieldcat-seltext_m.
APPEND lt_header .
ENDLOOP.
CALL FUNCTION `WWW_ITAB_TO_HTML`
EXPORTING
table_header = ls_header
all_fields = ` `
TABLES
html = ihtml
fields = ifields
row_header = lt_header
itable = pt_out.
LOOP AT ihtml.
wa_objtxt-line = ihtml-line.
APPEND wa_objtxt TO pt_objtxt.CLEAR wa_objtxt.
ENDLOOP.
wa_objtxt-line = ``.
APPEND wa_objtxt TO pt_objtxt.CLEAR wa_objtxt.
wa_objtxt-line = ``.
APPEND wa_objtxt TO pt_objtxt.CLEAR wa_objtxt.
ENDFORM. " ITAB_TO_HTML
*&---------------------------------------------------------------------*
*& Form F_CALL_MAIL_FUNC
*&---------------------------------------------------------------------*
FORM f_call_mail_func TABLES pt_objpack STRUCTURE sopcklsti1
pt_objhead STRUCTURE solisti1
pt_objtxt STRUCTURE solisti1
pt_reclist STRUCTURE somlreci1
USING ps_docdata TYPE sodocchgi1.
DATA : wa_docdata TYPE sodocchgi1, " Document data
wa_objbin TYPE solisti1 , " Attachment data
wa_objtxt TYPE solisti1 , " Message body
wa_objpack TYPE sopcklsti1, " Packing list
wa_reclist TYPE somlreci1 . " Receipient list
DATA: lv_lines TYPE i.
* Packing data
DESCRIBE TABLE pt_objtxt LINES lv_lines.
READ TABLE pt_objtxt INTO pt_objtxt INDEX lv_lines.
wa_docdata-doc_size = ( lv_lines - 1 ) * 255
+ STRLEN( pt_objtxt ) .
CLEAR wa_objpack-transf_bin.
wa_objpack-head_start = 1.
wa_objpack-head_num = 0.
wa_objpack-body_start = 1.
wa_objpack-body_num = lv_lines.
wa_objpack-doc_type = `HTM`.
APPEND wa_objpack TO pt_objpack.
CALL FUNCTION `SO_NEW_DOCUMENT_ATT_SEND_API1`
EXPORTING
document_data = ps_docdata
put_in_outbox = `X`
commit_work = `X`
TABLES
packing_list = pt_objpack
object_header = pt_objhead
contents_txt = pt_objtxt
receivers = pt_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 <> 0.
ENDIF.
ENDFORM. " F_CALL_MAIL_FUNC