04-03-2009 11:44 AM
Hi,
I want to send an email with the result of report O4B1 as attachment Excel with columns separated in Excel.
Best regards.
04-03-2009 11:49 AM
REPORT YJAJUR_EMAILOPTIONS .
tables: kna1.
data: begin of it_kna1 occurs 0," with header line,
kunnr like kna1-kunnr,
land1 like kna1-land1,
name1 like kna1-name1,
end of it_kna1.
data: w_sender like somlreci1-receiver.
CONSTANTS:
con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
data: it_mess_att like solisti1 occurs 0 with header line,
gd_attachment_desc type sopcklsti1-obj_descr.
data: gd_subject like sodocchgi1-obj_descr,
it_mess_bod like solisti1 occurs 0 with header line,
gd_sender_type like soextreci1-adr_typ,
gd_attachment_name type so_obj_des.
select-options: p_email for w_sender no intervals.
PARAMETER mailid TYPE adr6-smtp_addr NO-DISPLAY.
data : it_kna2 type kna1 occurs 0 with header line.
select kunnr
land1
name1
from kna1 into table it_kna1 .
select * from kna1 into table it_kna2.
concatenate 'EMSIL OPTIONS DONE BY sANTOSH.s.jAJU' 'MODEL WISE upto' Into gd_attachment_desc separated by space.
concatenate 'Custmer' 'custmer name' 'custmer land1' con_tab into
it_mess_att separaTED BY con_tab.
CONCATENATE con_cret it_mess_att INTO it_mess_att.
APPEND it_mess_att.
CLEAR it_mess_att.
*loop at p_email.
*endloop.
data: i1 type string.
perform email.
loop at p_email.
i1 = i1 + 1.
concatenate 'email' ':' i1 space p_email-low into it_mess_bod.
it_mess_bod = p_email-low..
APPEND it_mess_bod.
clear it_mess_bod.
perform send_mail.
endloop.
perform display_data..
&----
*& Form email
&----
text
----
--> p1 text
<-- p2 text
----
FORM email .
loop at it_kna2.
concatenate con_cret it_kna2-kunnr con_tab
it_kna2-name1 con_tab it_kna2-land1 into it_mess_att.
APPEND it_mess_att.
CLEAR it_mess_att.
endloop.
ENDFORM. " email
&----
*& Form send_mail
&----
text
----
--> p1 text
<-- p2 text
----
FORM send_mail .
DATA: send_request TYPE REF TO cl_bcs,
document TYPE REF TO cl_document_bcs,
recipient TYPE REF TO cl_cam_address_bcs,
bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean,
lt_tab TYPE TABLE OF makt,
lt_fields TYPE TABLE OF w3fields,
lt_html TYPE TABLE OF w3html.
data: ld_error type sy-subrc,
ld_reciever type sy-subrc,
ld_mtitle like sodocchgi1-obj_descr,
ld_email like somlreci1-receiver,
ld_format type so_obj_tp ,
ld_attdescription type sopcklsti1-obj_descr,
ld_attfilename type so_obj_des ,
ld_sender_address like soextreci1-receiver,
ld_sender_address_type like soextreci1-adr_typ,
ld_receiver like sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
MOVE P_EMAIL TO MAILID.
SELECT * FROM makt UP TO 10 ROWS INTO TABLE lt_tab WHERE spras = 'E'.
CALL FUNCTION 'WWW_ITAB_TO_HTML'
TABLES
html = lt_html[]
fields = lt_fields
itable = lt_tab.
TRY.
send_request = cl_bcs=>create_persistent( ).
document = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = lt_html
i_subject = 'Table' ).
send_request->set_document( document ).
recipient = cl_cam_address_bcs=>create_internet_address( MAILID ).
send_request->add_recipient( EXPORTING i_recipient = recipient
i_express = 'X' ).
send_request->set_send_immediately( 'X' ).
send_request->send( EXPORTING i_with_error_screen = 'X'
RECEIVING result = sent_to_all ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
EXIT.
ENDTRY.
ld_email = p_email-low.
ld_mtitle = gd_attachment_desc.
ld_format = 'XLS'.
ld_attdescription = gd_attachment_desc.
concatenate gd_attachment_desc '.XLS' into ld_attfilename.
ld_attfilename = p_filename.
ld_sender_address = w_sender.
ld_sender_address_type = 'INT'.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
clear w_doc_data.
read table it_mess_att index 1.
w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + strlen( it_mess_att ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = gd_attachment_desc.
w_doc_data-sensitivty = 'F'.
clear t_attachment.
refresh t_attachment.
t_attachment[] = it_attach[].
Describe the body of the message
clear t_packing_list.
refresh t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
describe table it_mess_bod lines t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
append t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
describe table it_mess_att lines t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
append t_packing_list.
Add the recipients email address
clear t_receivers.
refresh t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
append t_receivers.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
importing
sent_to_all = w_sent_all
tables
packing_list = t_packing_list
contents_bin = it_mess_att
contents_txt = it_mess_bod
receivers = t_receivers
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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
loop at t_receivers.
ld_receiver = t_receivers-retrn_code.
endloop.
wait up to 5 seconds.
submit rsconn01 with mode = 'INT'
with output = 'X'
and return.
ENDFORM. " send_mail
&----
*& Form display_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM display_data .
loop at it_kna2.
write:/ it_kna2-kunnr,it_kna2-land1,it_kna2-name1.
endloop.
ENDFORM. " display_data
ref this code i guess this will works
04-03-2009 11:49 AM
REPORT YJAJUR_EMAILOPTIONS .
tables: kna1.
data: begin of it_kna1 occurs 0," with header line,
kunnr like kna1-kunnr,
land1 like kna1-land1,
name1 like kna1-name1,
end of it_kna1.
data: w_sender like somlreci1-receiver.
CONSTANTS:
con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
data: it_mess_att like solisti1 occurs 0 with header line,
gd_attachment_desc type sopcklsti1-obj_descr.
data: gd_subject like sodocchgi1-obj_descr,
it_mess_bod like solisti1 occurs 0 with header line,
gd_sender_type like soextreci1-adr_typ,
gd_attachment_name type so_obj_des.
select-options: p_email for w_sender no intervals.
PARAMETER mailid TYPE adr6-smtp_addr NO-DISPLAY.
data : it_kna2 type kna1 occurs 0 with header line.
select kunnr
land1
name1
from kna1 into table it_kna1 .
select * from kna1 into table it_kna2.
concatenate 'EMSIL OPTIONS DONE BY sANTOSH.s.jAJU' 'MODEL WISE upto' Into gd_attachment_desc separated by space.
concatenate 'Custmer' 'custmer name' 'custmer land1' con_tab into
it_mess_att separaTED BY con_tab.
CONCATENATE con_cret it_mess_att INTO it_mess_att.
APPEND it_mess_att.
CLEAR it_mess_att.
*loop at p_email.
*endloop.
data: i1 type string.
perform email.
loop at p_email.
i1 = i1 + 1.
concatenate 'email' ':' i1 space p_email-low into it_mess_bod.
it_mess_bod = p_email-low..
APPEND it_mess_bod.
clear it_mess_bod.
perform send_mail.
endloop.
perform display_data..
&----
*& Form email
&----
text
----
--> p1 text
<-- p2 text
----
FORM email .
loop at it_kna2.
concatenate con_cret it_kna2-kunnr con_tab
it_kna2-name1 con_tab it_kna2-land1 into it_mess_att.
APPEND it_mess_att.
CLEAR it_mess_att.
endloop.
ENDFORM. " email
&----
*& Form send_mail
&----
text
----
--> p1 text
<-- p2 text
----
FORM send_mail .
DATA: send_request TYPE REF TO cl_bcs,
document TYPE REF TO cl_document_bcs,
recipient TYPE REF TO cl_cam_address_bcs,
bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean,
lt_tab TYPE TABLE OF makt,
lt_fields TYPE TABLE OF w3fields,
lt_html TYPE TABLE OF w3html.
data: ld_error type sy-subrc,
ld_reciever type sy-subrc,
ld_mtitle like sodocchgi1-obj_descr,
ld_email like somlreci1-receiver,
ld_format type so_obj_tp ,
ld_attdescription type sopcklsti1-obj_descr,
ld_attfilename type so_obj_des ,
ld_sender_address like soextreci1-receiver,
ld_sender_address_type like soextreci1-adr_typ,
ld_receiver like sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
MOVE P_EMAIL TO MAILID.
SELECT * FROM makt UP TO 10 ROWS INTO TABLE lt_tab WHERE spras = 'E'.
CALL FUNCTION 'WWW_ITAB_TO_HTML'
TABLES
html = lt_html[]
fields = lt_fields
itable = lt_tab.
TRY.
send_request = cl_bcs=>create_persistent( ).
document = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = lt_html
i_subject = 'Table' ).
send_request->set_document( document ).
recipient = cl_cam_address_bcs=>create_internet_address( MAILID ).
send_request->add_recipient( EXPORTING i_recipient = recipient
i_express = 'X' ).
send_request->set_send_immediately( 'X' ).
send_request->send( EXPORTING i_with_error_screen = 'X'
RECEIVING result = sent_to_all ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
EXIT.
ENDTRY.
ld_email = p_email-low.
ld_mtitle = gd_attachment_desc.
ld_format = 'XLS'.
ld_attdescription = gd_attachment_desc.
concatenate gd_attachment_desc '.XLS' into ld_attfilename.
ld_attfilename = p_filename.
ld_sender_address = w_sender.
ld_sender_address_type = 'INT'.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
clear w_doc_data.
read table it_mess_att index 1.
w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + strlen( it_mess_att ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = gd_attachment_desc.
w_doc_data-sensitivty = 'F'.
clear t_attachment.
refresh t_attachment.
t_attachment[] = it_attach[].
Describe the body of the message
clear t_packing_list.
refresh t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
describe table it_mess_bod lines t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
append t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
describe table it_mess_att lines t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
append t_packing_list.
Add the recipients email address
clear t_receivers.
refresh t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
append t_receivers.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
importing
sent_to_all = w_sent_all
tables
packing_list = t_packing_list
contents_bin = it_mess_att
contents_txt = it_mess_bod
receivers = t_receivers
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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
loop at t_receivers.
ld_receiver = t_receivers-retrn_code.
endloop.
wait up to 5 seconds.
submit rsconn01 with mode = 'INT'
with output = 'X'
and return.
ENDFORM. " send_mail
&----
*& Form display_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM display_data .
loop at it_kna2.
write:/ it_kna2-kunnr,it_kna2-land1,it_kna2-name1.
endloop.
ENDFORM. " display_data
ref this code i guess this will works
04-03-2009 11:52 AM
Hi,
SUBMIT report EXPORTING LIST TO MEMORY
AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = i_objbin
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
For sending Excel Attachment.
Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = i_docdata
put_in_outbox = c_x
TABLES
packing_list = i_objpack
object_header = i_objhead
contents_bin = i_objbin
contents_txt = i_objtxt
receivers = i_reclist
and specify the document type
i_objpack-doc_type = 'XLS'.
ENDIF.
04-03-2009 11:58 AM
04-03-2009 12:48 PM
this is a sample report
TYPE-POOLS : slis.
DATA:
l_datum TYPE sy-datum,
ls_docdata TYPE sodocchgi1,
lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE,
lt_objhead TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_objbin TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_reclist TYPE TABLE OF somlreci1 WITH HEADER LINE,
lt_listobject TYPE TABLE OF abaplist WITH HEADER LINE,
l_tab_lines TYPE i,
l_att_type LIKE soodk-objtp.
DATA: name(60).
RANGES s_vorne FOR blpk-vorne. " Rep Opr No
&----
*& Include ZCRPT_SD_031_1_EXC_MAIL_FORMS
&----
&----
*& Form f_send_mail
&----
text
----
--> p1 text
<-- p2 text
----
FORM f_send_mail .
DATA: dd(2) TYPE n,
mm(2) TYPE n,
yy(4) TYPE n.
DATA :call_repname LIKE sy-repid.
DATA: f_date TYPE sy-datum,
t_date TYPE sy-datum.
*
DATA: tik TYPE n.
tik = 1.
READ TABLE email INDEX 1.
IF sy-subrc NE 0.
MESSAGE 'Enter Atleast One Email Id In To:' TYPE 'I'.
EXIT.
ENDIF.
SUBMIT zirpt_daily_cost
WITH p_werks EQ p_werks
WITH p_udate EQ p_udate
WITH p_bno EQ p_bno
EXPORTING LIST TO MEMORY AND RETURN.
Read list from memory into table
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = lt_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
Error in function module &1
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'LIST_FROM_MEMORY'.
ENDIF.
Because listobject is of size RAW(1000)
and objbin is of size CHAR(255) we make this table copy
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = lt_listobject
out = lt_objbin
EXCEPTIONS
compress_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
Error in function module &1
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'TABLE_COMPRESS'.
ENDIF.
NOTE: Creation of attachment is finished yet.
For your report, the attachment should be placed into table
objtxt for plain text or
objbin for binary content.
Now create the message and send the document.
Create Message Body
Title and Description
l_datum = sy-datum - 1.
l_datum = p_udate - p_bno .
dd = l_datum+6(2).
mm = l_datum+4(2).
yy = l_datum(4).
ls_docdata-obj_name = 'Cost Report'.
CONCATENATE p_subj '&Parameter= ' dd '/' mm '/' yy
INTO ls_docdata-obj_descr .
Main Text
lt_objtxt = 'Daily Cost Report'. "ls_docdata-obj_descr.
APPEND lt_objtxt.
Write Packing List (Main)
DESCRIBE TABLE lt_objtxt LINES l_tab_lines.
READ TABLE lt_objtxt INDEX l_tab_lines.
ls_docdata-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
CLEAR lt_objpack-transf_bin.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = 'RAW'.
APPEND lt_objpack.
Create Message Attachment
Write Packing List (Attachment)
l_att_type = 'ALI'.
DESCRIBE TABLE lt_objbin LINES l_tab_lines.
READ TABLE lt_objbin INDEX l_tab_lines.
lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objbin ).
lt_objpack-transf_bin = 'X'.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = l_att_type.
lt_objpack-obj_name = 'ATTACHMENT'.
lt_objpack-obj_descr = 'FLASH REPORT'. "#EC *
APPEND lt_objpack.
READ TABLE email INDEX 1.
IF sy-subrc = 0.
LOOP AT email.
lt_reclist-receiver = email-low.
lt_reclist-rec_type = 'U'.
lt_reclist-com_type = 'INT'.
APPEND lt_reclist.
ENDLOOP.
ENDIF.
READ TABLE cmail INDEX 1.
IF sy-subrc = 0.
LOOP AT cmail.
lt_reclist-receiver = cmail-low.
lt_reclist-rec_type = 'U'.
lt_reclist-com_type = 'INT'.
lt_reclist-copy = 'X'.
APPEND lt_reclist.
ENDLOOP.
ENDIF.
Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ls_docdata
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = lt_objbin
contents_txt = lt_objtxt
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 = 0.
Document sent
MESSAGE ID 'SO' TYPE 'S' NUMBER '022'.
SUBMIT rsconn01 WITH mode = 'INT'
WITH OUTPUT = 'X'
AND RETURN.
ELSE.
Document <&> could not be sent
MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
WITH ls_docdata-obj_name.
ENDIF.
ENDFORM. " f_send_mail