ABAP EFG_GEN_SEND_EMAIL fonksiyonu ile basit mail gönderme örneği


REPORT zpnt_fd_dnm2.
TYPES: BEGIN OF ty_lines,
line TYPE char255,
END OF ty_lines.
DATA: ti_lines TYPE STANDARD TABLE OF ty_lines,
wa_lines TYPE ty_lines.
DATA: title TYPE string,
sender_email TYPE string,
receiver_email TYPE string.

title = 'Mail başlığı-TEST'.

CLEAR wa_lines.
wa_lines-line = 'Merhaba.(Satır-1)'.
APPEND wa_lines TO ti_lines.

CLEAR wa_lines.
wa_lines-line = 'Bu bir test maili. (Satır-2)'.
APPEND wa_lines TO ti_lines.

sender_email = 'fdonmez@penti.com.tr'.
receiver_email = 'fdonmez@penti.com.tr'.

CALL FUNCTION 'EFG_GEN_SEND_EMAIL'
EXPORTING
i_title = title
i_sender = sender_email
i_recipient = receiver_email
i_flg_commit = 'X'
i_flg_send_immediately = 'X'
TABLES
i_tab_lines = ti_lines
EXCEPTIONS
not_qualified = 1
failed = 2
OTHERS = 3.

IF sy-subrc NE 0.
WRITE: 'hata...!'.
ELSE.
WRITE: 'basarili...!'.
ENDIF.

Mobil ITS servisi oluşturma

ITS, aşağıdaki avantajlara sahip mobil cihazlarda ABAP uygulamalarıdır:

Tüm uygulama ABAP çalışma tezgahı kullanılarak geliştirilebilir.
SAP GUI, Windows için ABAP hata ayıklaması yapmak için kullanılabilir ve sistem manzara karmaşık değildir.
Şablonlar ve oluşturulan HTML, işletme gereksinimlerine göre özelleştirilebilir.
Uygulamada cihaz türlerine göre HTML veya JavaScript kullanılabilir.
ITS mobil 1D ve 2D barkod tarama ile veri girişini destekler.

Farklı tarayıcı türleri:

Pocket Browser
Wavelink Industrial browser
Internet Explorer

Adımlar
1.Internet hizmetini oluşturma: SE80 ->Package ->Create->Other->Internet Service (Servis ismi kullanılacak t-code ile aynı ad olabilir).
2.Programdaki ekranların şablonlarının oluşturulması: SE80->Program-> Screen (Her ekrana ayrı ayrı)->Other Function->Create Template (Servis adı ve tema 99, stil No HTML table).
3. Internet Servisini yayına alma: SE80->Package->ITS Service->Service File + Complete Service (Parametre: ~TRANSACTION).
4. ICF bağlantısını yaratma: SICF:default_host/sap/bc/gui/sap/its ->New Sub-Element-> Service Data: GUI configuration (params:~ITSMOBILE: ~TRANSACTION: ~THEME:)+ Handler List(CL_HTTP_EXT_ITS ). + Error Pages: Sistem oturum açma->Servise özgü ayarlar
Save.Activate.Test Service.
se80->ITS Service->Start Service
https://blogs.sap.com/2015/02/09/sample-its-mobile-application/

ABAP: Bir tablonun html biçiminde mail olarak gönderilmesi.

Send internal table in html format to mail.

*---------------------------------------------------------------------*
* V A R I A B L E S *
*---------------------------------------------------------------------*
DATA:
t_header TYPE STANDARD TABLE OF w3head WITH HEADER LINE, "Header
t_fields TYPE STANDARD TABLE OF w3fields WITH HEADER LINE, "Fields
t_html TYPE STANDARD TABLE OF w3html, "Html
wa_header TYPE w3head,
w_head TYPE w3head.

DATA:BEGIN OF it_data OCCURS 0,
UPDKZ LIKE ZPP_T_PRODORD_L-UPDKZ, " Icron güncelleme göst.
AUFNR LIKE ZPP_T_PRODORD_L-AUFNR, " Sipariş
MATNR LIKE ZPP_T_PRODORD_L-MATNR, " Malzeme
MENGE LIKE ZPP_T_PRODORD_L-MENGE, " Miktar
MEINS LIKE ZPP_T_PRODORD_L-MEINS, " ÖB
BEDEN LIKE ZPP_T_PRODORD_L-BEDEN, " Matris
ZZMAKINA LIKE ZPP_T_PRODORD_L-ZZMAKINA, " Makina Kodu
TYPE LIKE ZPP_T_PRODORD_L-TYPE, " Mesaj Tipi
MESSAGE LIKE ZPP_T_PRODORD_L-MESSAGE, " Mesaj
CRNAM LIKE ZPP_T_PRODORD_L-CRNAM, " Yaratan
CRDAT LIKE ZPP_T_PRODORD_L-CRDAT, " Y.Tarihi
CRTIM LIKE ZPP_T_PRODORD_L-CRTIM, " Y.Saati
END OF it_data,
wa_data like LINE OF it_data.

* Data Declarations
DATA: LT_MAILSUBJECT TYPE SODOCCHGI1.
DATA: LT_MAILRECIPIENTS TYPE STANDARD TABLE OF SOMLREC90 WITH HEADER
LINE.
DATA: LT_MAILTXT TYPE STANDARD TABLE OF SOLI WITH HEADER
LINE.

DATA: BEGIN OF t_mail OCCURS 0,
receiver TYPE ZPP_T_MAILGRUP-SMTP_ADDR,
END OF t_mail,
ls_mail LIKE LINE OF t_mail.
*---------------------------------------------------------------------*
* S E L E C T I O N S C R E E N *
*---------------------------------------------------------------------*
*SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-000.
*PARAMETERS : P_WERKS LIKE T001W-WERKS OBLIGATORY.
*SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.
*SELECTION-SCREEN END OF BLOCK BL1 .

*---------------------------------------------------------------------*
* E V E N T S *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
INITIALIZATION.
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*---------------------------------------------------------------------*
* Validate Input At Selection Screen
*PERFORM screen_validation.

*---------------------------------------------------------------------*
START-OF-SELECTION.
*---------------------------------------------------------------------*
PERFORM build_data.
PERFORM send_mail.
*---------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form BUILD_DATA
*&---------------------------------------------------------------------*

FORM BUILD_DATA .
DATA: LV_DATE1 TYPE SY-DATUM.
DATA: LV_DATE2 TYPE SY-DATUM.

LV_DATE1 = SY-DATUM .
LV_DATE2 = SY-DATUM - 1.

* başarılı olmayan üretim siparişi işlemleri
SELECT log~UPDKZ
log~AUFNR
log~MATNR
log~MENGE
log~MEINS
log~BEDEN
log~ZZMAKINA
log~TYPE
log~MESSAGE
log~CRNAM
log~CRDAT
log~CRTIM
FROM ZPP_T_PRODORD_L as log
INTO TABLE it_data
where TYPE ne 'S'
AND ( ( log~CRDAT EQ LV_DATE1 AND log~CRTIM LE SY-UZEIT )
OR ( log~CRDAT eq LV_DATE2 AND log~CRTIM GE SY-UZEIT ) ).

* mak no boş olan siparişler
SELECT log~UPDKZ
log~AUFNR
log~MATNR
log~MENGE
log~MEINS
log~BEDEN
log~ZZMAKINA
log~TYPE
log~MESSAGE
log~CRNAM
log~CRDAT
log~CRTIM FROM ZPP_T_PRODORD_L as log
INNER JOIN aufk
on log~aufnr eq aufk~aufnr
APPENDING TABLE it_data
where ( ( log~CRDAT eq LV_DATE1 AND log~CRTIM LE SY-UZEIT )
OR ( log~CRDAT eq LV_DATE2 AND log~CRTIM ge SY-UZEIT ) )
and aufk~LOEKZ eq ''
and aufk~ZZMAKINA eq ''.

LOOP AT it_data INTO wa_data.
IF wa_data-TYPE eq 'S'.
wa_data-TYPE = 'E'.
wa_data-MESSAGE = 'SAP üretim siparişi Makine No boş olamaz!'.
modify it_data from wa_data.
ENDIF.
ENDLOOP.
IF it_data[] is INITIAL.
write: / 'Kayıt bulunamadı!'.
ENDIF.
ENDFORM. " BUILD_DATA
*&---------------------------------------------------------------------*
*& Form SEND_MAIL
*&---------------------------------------------------------------------*
FORM SEND_MAIL .
CHECK it_data[] is not INITIAL.
*-Fill the Column headings and Properties
DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
*Merge işlemi
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'IT_DATA'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = GT_FIELDCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
LOOP AT GT_FIELDCAT.
w_head-text = GT_FIELDCAT-SELTEXT_S.
IF GT_FIELDCAT-FIELDNAME = 'MESSAGE'.
w_head-text = 'Hata Mesajı'.
ENDIF.
*-Populate the Column Headings
CALL FUNCTION 'WWW_ITAB_TO_HTML_HEADERS'
EXPORTING
field_nr = sy-tabix
text = w_head-text
fgcolor = 'black'
bgcolor = 'orange'
TABLES
header = t_header.
*-Populate Column Properties
CALL FUNCTION 'WWW_ITAB_TO_HTML_LAYOUT'
EXPORTING
field_nr = sy-tabix
fgcolor = 'black'
size = '3'
TABLES
fields = t_fields.
ENDLOOP.
*-Title of the Display
wa_header-text = 'SAP Icron RFC hata detayları.' .
wa_header-font = 'Arial'.
wa_header-size = '2'.
*-Preparing the HTML from Intenal Table
REFRESH t_html.
CALL FUNCTION 'WWW_ITAB_TO_HTML'
EXPORTING
table_header = wa_header
TABLES
html = t_html
fields = t_fields
row_header = t_header
itable = it_data.

* Recipients
select SMTP_ADDR as receiver
from ZPP_T_MAILGRUP into TABLE t_mail
where PGMNA eq 'ZPP_R_ICRON_MAIL_HATA'.

IF T_MAIL[] IS INITIAL.
LT_MAILRECIPIENTS-receiver = 'user@domain.com.tr'.
LT_MAILRECIPIENTS-rec_type = 'U'.
APPEND LT_MAILRECIPIENTS .
CLEAR LT_MAILRECIPIENTS .
ELSE.
loop at t_mail INTO ls_mail.
LT_MAILRECIPIENTS-receiver = ls_mail-receiver.
LT_MAILRECIPIENTS-rec_type = 'U'.
APPEND LT_MAILRECIPIENTS .
CLEAR LT_MAILRECIPIENTS .
ENDLOOP.
ENDIF.

* Subject.
LT_MAILSUBJECT-OBJ_NAME = 'PENTI FABRIKA'.
LT_MAILSUBJECT-OBJ_LANGU = SY-LANGU.
LT_MAILSUBJECT-OBJ_DESCR = 'SAP Icron Örgü Üretim Siparişi Hata'.

* Mail Contents
LT_MAILTXT[] = t_html[].

* Send Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
COMMIT_WORK = ''
PUT_IN_OUTBOX = 'X'
DOCUMENT_DATA = LT_MAILSUBJECT
DOCUMENT_TYPE = 'HTM'
TABLES
OBJECT_CONTENT = LT_MAILTXT
RECEIVERS = LT_MAILRECIPIENTS
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.
COMMIT WORK AND WAIT.
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
write: / 'Mail gönderildi...'.
else.
write: / 'hata:',sy-subrc.
ENDIF.

ENDFORM. " SEND_MAIL