ABAP cookbook with #2


  • Create an email (Outlook) and attach a file

Create an email (Outlook) and attach a file 

cl_gui_frontend_services=>registry_get_value(
EXPORTING
root = cl_gui_frontend_services=>hkey_local_machine
key = 'SOFTWARE\Classes\Outlook.Application\CurVer'
IMPORTING
reg_value = lv_reg_value).

cl_gui_cfw=>flush( ).

DATA(lo_gen_ebpp_notification) = NEW cl_gen_ebpp_notification( ).
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
TABLES
otf = it_otf_data
lines = lt_lines


cl_gui_frontend_services=>get_temp_directory( CHANGING temp_dir = lv_temp_dir ).
cl_gui_cfw=>flush( ).


CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = gv_filename
filetype = 'BIN'
TABLES
data_tab = lt_lines


CALL FUNCTION 'AUTHORITY_CHECK_OLE'
EXPORTING
activity = sabc_act_call
application = 'Outlook.Application'.

DATA : 
lo_ooutapp TYPE ole2_object , "Outlook.Application
lo_omail TYPE ole2_object , "Outlook.MailItem
lo_lattach TYPE ole2_object , "Outlook.Attachment
lattachmsg TYPE ole2_object.
CREATE OBJECT lo_ooutapp 'Outlook.Application'.
CALL METHOD OF lo_ooutapp 'CreateItem' = lx_omail
EXPORTING #1 = 0.

SET PROPERTY OF lx_omail 'To' = lv_reciver.
SET PROPERTY OF lx_omail 'Subject' = lv_subject.
SET PROPERTY OF lx_omail 'BodyFormat' = '2'.
DATA(lv_body) = ....
CALL METHOD OF lo_omail 'ATTACHMENTS' = lx_lattach.
CALL METHOD OF lo_lattach 'ADD'
EXPORTING
#1 = lv_filename.

CALL METHOD OF o_omail 'Display'.

FREE OBJECT lo_omail.
FREE OBJECT lo_ooutapp.

Comments