Selection screen.
output
Program code
REPORT ZABAP_TO_OUTLOOK.
tables : adr6.
type-pools ole2 .
data : ooutapp type ole2_object, "Outlook.Application
omail type ole2_object, "Outlook.MailItem
lattach type ole2_object , "Outlook.Attachment
lattachmsg type ole2_object.
"
types : begin of tp_file,
filename type LOCALFILE,
end of tp_file.
data : wa_files type tp_file,
it_files type STANDARD TABLE OF tp_file.
data : gv_to type string,
gv_cc type string,
gv_bcc type string.
SELECTION-SCREEN begin of BLOCK b1 WITH FRAME TITLE text-001.
select-OPTIONS : s_to for adr6-SMTP_ADDR no INTERVALS,
s_cc for adr6-SMTP_ADDR no INTERVALS,
s_bcc for adr6-SMTP_ADDR no INTERVALS.
PARAMETERS : p_sub type char100 LOWER CASE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN SKIP.
PARAMETERS : P_ATT1 type LOCALENAME,
P_ATT2 type LOCALENAME.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN SKIP.
PARAMETERS : P_BODY TYPE STRING LOWER CASE.
SELECTION-SCREEN SKIP.
PARAMETERS : R_TEXT RADIOBUTTON GROUP GRP,
R_HTML RADIOBUTTON GROUP GRP.
SELECTION-SCREEN end of BLOCK b1.
"file selection pop up
at SELECTION-SCREEN on VALUE-REQUEST FOR P_ATT1.
perform get_file_name CHANGING P_ATT1.
at SELECTION-SCREEN on VALUE-REQUEST FOR P_ATT2.
perform get_file_name CHANGING P_ATT2.
START-OF-SELECTION.
perform call_outlook.
end-of-SELECTION.
*&---------------------------------------------------------------------*
*& Form CALL_OUTLOOK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_OUTLOOK.
"create object for outlook
CREATE OBJECT ooutapp 'Outlook.Application'.
IF sy-subrc NE 0.
EXIT.
ENDIF.
CALL METHOD OF ooutapp 'CreateItem' = omail
EXPORTING
#1 = 0.
"to set priority as inportant i.e 1
SET PROPERTY OF omail 'Importance' = 1.
"set to ids
clear : GV_TO.
loop at S_TO.
CONCATENATE gv_to s_to-low into gv_to SEPARATED BY ';'.
clear : s_to.
endloop.
shift gv_to left deleting leading ';'. "remove first separator
if gv_to is NOT INITIAL.
SET PROPERTY OF omail 'To' = gv_to.
endif.
"set CC ids
clear : GV_CC.
loop at S_CC.
CONCATENATE gv_cc s_cc-low into gv_cc SEPARATED BY ';'.
clear : s_cc.
endloop.
shift gv_cc left deleting leading ';'. "remove first separator
if gv_cc is NOT INITIAL.
SET PROPERTY OF omail 'CC' = gv_cc.
endif.
"set BCC ids
clear : GV_BCC.
loop at S_BCC.
CONCATENATE gv_bcc s_bcc-low into gv_bcc SEPARATED BY ';'.
clear : s_bcc.
endloop.
shift gv_bcc left deleting leading ';'. "remove first separator
if gv_bcc is NOT INITIAL.
SET PROPERTY OF omail 'BCC' = gv_bcc.
endif.
"set subject
if P_SUB is NOT INITIAL.
SET PROPERTY OF omail 'Subject' = P_SUB.
endif.
"add attachments
if P_ATT1 is NOT INITIAL.
wa_files-filename = P_ATT1.
APPEND wa_files TO it_files.
endif.
if P_ATT2 is NOT INITIAL.
wa_files-filename = P_ATT2.
APPEND wa_files TO it_files.
endif.
LOOP AT it_files INTO wa_files.
CALL METHOD OF omail 'Attachments' = lattach.
CALL METHOD OF lattach 'Add'
EXPORTING
#1 = wa_files-filename.
clear : wa_files.
ENDLOOP.
"set plain or html body
if R_TEXT is NOT INITIAL and p_body is NOT INITIAL.
set PROPERTY OF omail 'body' = P_BODY.
elseif p_body is NOT INITIAL.
set PROPERTY OF omail 'htmlbody' = P_BODY.
endif.
* start outlook in display mode
CALL METHOD OF omail 'Display'.
* free
FREE OBJECT omail.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_FILE_NAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_P_ATT1 text
*----------------------------------------------------------------------*
FORM GET_FILE_NAME CHANGING P_P_ATT1.
data : lv_path type LOCALFILE.
CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = lv_path.
P_P_ATT1 = LV_PATH.
ENDFORM.
tables : adr6.
type-pools ole2 .
data : ooutapp type ole2_object, "Outlook.Application
omail type ole2_object, "Outlook.MailItem
lattach type ole2_object , "Outlook.Attachment
lattachmsg type ole2_object.
"
types : begin of tp_file,
filename type LOCALFILE,
end of tp_file.
data : wa_files type tp_file,
it_files type STANDARD TABLE OF tp_file.
data : gv_to type string,
gv_cc type string,
gv_bcc type string.
SELECTION-SCREEN begin of BLOCK b1 WITH FRAME TITLE text-001.
select-OPTIONS : s_to for adr6-SMTP_ADDR no INTERVALS,
s_cc for adr6-SMTP_ADDR no INTERVALS,
s_bcc for adr6-SMTP_ADDR no INTERVALS.
PARAMETERS : p_sub type char100 LOWER CASE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN SKIP.
PARAMETERS : P_ATT1 type LOCALENAME,
P_ATT2 type LOCALENAME.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN SKIP.
PARAMETERS : P_BODY TYPE STRING LOWER CASE.
SELECTION-SCREEN SKIP.
PARAMETERS : R_TEXT RADIOBUTTON GROUP GRP,
R_HTML RADIOBUTTON GROUP GRP.
SELECTION-SCREEN end of BLOCK b1.
"file selection pop up
at SELECTION-SCREEN on VALUE-REQUEST FOR P_ATT1.
perform get_file_name CHANGING P_ATT1.
at SELECTION-SCREEN on VALUE-REQUEST FOR P_ATT2.
perform get_file_name CHANGING P_ATT2.
START-OF-SELECTION.
perform call_outlook.
end-of-SELECTION.
*&---------------------------------------------------------------------*
*& Form CALL_OUTLOOK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_OUTLOOK.
"create object for outlook
CREATE OBJECT ooutapp 'Outlook.Application'.
IF sy-subrc NE 0.
EXIT.
ENDIF.
CALL METHOD OF ooutapp 'CreateItem' = omail
EXPORTING
#1 = 0.
"to set priority as inportant i.e 1
SET PROPERTY OF omail 'Importance' = 1.
"set to ids
clear : GV_TO.
loop at S_TO.
CONCATENATE gv_to s_to-low into gv_to SEPARATED BY ';'.
clear : s_to.
endloop.
shift gv_to left deleting leading ';'. "remove first separator
if gv_to is NOT INITIAL.
SET PROPERTY OF omail 'To' = gv_to.
endif.
"set CC ids
clear : GV_CC.
loop at S_CC.
CONCATENATE gv_cc s_cc-low into gv_cc SEPARATED BY ';'.
clear : s_cc.
endloop.
shift gv_cc left deleting leading ';'. "remove first separator
if gv_cc is NOT INITIAL.
SET PROPERTY OF omail 'CC' = gv_cc.
endif.
"set BCC ids
clear : GV_BCC.
loop at S_BCC.
CONCATENATE gv_bcc s_bcc-low into gv_bcc SEPARATED BY ';'.
clear : s_bcc.
endloop.
shift gv_bcc left deleting leading ';'. "remove first separator
if gv_bcc is NOT INITIAL.
SET PROPERTY OF omail 'BCC' = gv_bcc.
endif.
"set subject
if P_SUB is NOT INITIAL.
SET PROPERTY OF omail 'Subject' = P_SUB.
endif.
"add attachments
if P_ATT1 is NOT INITIAL.
wa_files-filename = P_ATT1.
APPEND wa_files TO it_files.
endif.
if P_ATT2 is NOT INITIAL.
wa_files-filename = P_ATT2.
APPEND wa_files TO it_files.
endif.
LOOP AT it_files INTO wa_files.
CALL METHOD OF omail 'Attachments' = lattach.
CALL METHOD OF lattach 'Add'
EXPORTING
#1 = wa_files-filename.
clear : wa_files.
ENDLOOP.
"set plain or html body
if R_TEXT is NOT INITIAL and p_body is NOT INITIAL.
set PROPERTY OF omail 'body' = P_BODY.
elseif p_body is NOT INITIAL.
set PROPERTY OF omail 'htmlbody' = P_BODY.
endif.
* start outlook in display mode
CALL METHOD OF omail 'Display'.
* free
FREE OBJECT omail.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_FILE_NAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_P_ATT1 text
*----------------------------------------------------------------------*
FORM GET_FILE_NAME CHANGING P_P_ATT1.
data : lv_path type LOCALFILE.
CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = lv_path.
P_P_ATT1 = LV_PATH.
ENDFORM.
1 Comments
Same like Can we read attachment from received Mail and store file in al11
ReplyDelete