09-05-2006 2:36 PM
I need to send a mail through my ABAP Program. The content of the mail is Internal Table.
I need to format the content of the Internal Table with proper spacing and heading.
ex:how i am getting my data in mail body
empno empname city region
-
111 abcdef hyedarabad Ap
112 abcedfgh banglore KArnataka
113 abc mubmai maharastra
Somebody please help me in this regard.
09-05-2006 2:46 PM
You can use HTML in your email to format the body. Develop your "table" in a HTML editor like dreamweaver, then use this as a template. Works really good.
Here is a sample program using HTML in the email body.
report zrich_0002.
data: maildata like sodocchgi1.
data: mailtxt like solisti1 occurs 10 with header line.
data: mailrec like somlrec90 occurs 0 with header line.
start-of-selection.
clear: maildata, mailtxt, mailrec.
refresh: mailtxt, mailrec.
perform build_text_message.
perform build_receivers.
perform send_mail_nodialog..
************************************************************************
* Form BUILD_TEXT_MESSAGE
************************************************************************
form build_text_message.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test Subject'.
<b> mailtxt = '<html>'.
append mailtxt.
mailtxt = '<head>'.
append mailtxt.
mailtxt = '<title>Untitled Document</title>'.
append mailtxt.
mailtxt = '<meta http-equiv="Content-Type" content="text/html;'.
append mailtxt.
mailtxt = 'charset=iso-8859-1">'.
append mailtxt.
mailtxt = '</head>'.
append mailtxt.
mailtxt = '<body>'.
append mailtxt.
mailtxt = '<div align="center"><em><font' .
append mailtxt.
mailtxt = 'color="#0000FF" size="+7" face="Arial,'.
append mailtxt.
mailtxt = 'Helvetica, sans-serif">THIS'.
append mailtxt.
mailtxt = ' IS A TEST </font></em><font' .
append mailtxt.
mailtxt = 'color="#0000FF" size="+7" face="Arial,'.
append mailtxt.
mailtxt = 'Helvetica, sans-serif"></font>'.
append mailtxt.
mailtxt = '</div>'.
append mailtxt.
mailtxt = '</body>'.
append mailtxt.
mailtxt = '</html>'.
append mailtxt.</b>
endform.
************************************************************************
* Form BUILD_RECEIVERS
************************************************************************
form build_receivers.
* mailrec-receiver = 'you@yourcompany.com'.
mailrec-rec_type = 'U'.
append mailrec.
endform.
************************************************************************
* Form SEND_MAIL_NODIALOG
************************************************************************
form send_mail_nodialog.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
<b> document_type = 'HTM'</b>
put_in_outbox = 'X'
tables
object_header = mailtxt
object_content = mailtxt
receivers = mailrec
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform.
Regards,
Rich Heilman
09-07-2006 3:40 PM
Hi
could you please tell me how to develop my "table" in a HTML editor like dreamweaver,any example please send me
thanks in advance
09-07-2006 3:50 PM
Here is some sample HTML code for displaying a table, All you need to do is replace the text with your values. That's it. This table has 3 rows with 5 columns.
<table width="75%" border="1">
<tr>
<td width="20%">This is cell 1 1</td>
<td width="20%">This is cell 1 2</td>
<td width="20%">This is cell 1 3</td>
<td width="20%">This is cell 1 4</td>
<td width="20%">This is cell 1 5</td>
</tr>
<tr>
<td width="20%">This is cell 2 1</td>
<td width="20%">This is cell 2 2</td>
<td width="20%">This is cell 2 3</td>
<td width="20%">This is cell 2 4</td>
<td width="20%">This is cell 2 5</td>
</tr>
<tr>
<td width="20%">This is cell 3 1</td>
<td width="20%">This is cell 3 2</td>
<td width="20%">This is cell 3 3</td>
<td width="20%">This is cell 3 4</td>
<td width="20%">This is cell 3 5</td>
</tr>
</table>
Regards,
Rich Heilman
09-07-2006 5:13 PM
Hello,
From the email the allignment for empno and name seems to be fine but the problem comes for WBS/CostCentre..
As I can see from your code you are overlapping the fields
it_mailtext-line+0(8) = it_final-emp_pernr.
it_mailtext-line+13(23) = v_empname.
it_mailtext-line+28(47) = it_final-wbs.
it_mailtext-line+52(58) = it_final-total_hrs.
Line
Empno EmpName
12345678....12345678901234567890123
12345678
But your WBS fields starts at 28th position.
Instead try and check with the below and if it coming correctly or not !!
it_mailtext-line+0(8) = it_final-emp_pernr.
it_mailtext-line+13(13) = v_empname.
it_mailtext-line+28(22) = it_final-wbs.
it_mailtext-line+52(58) = it_final-total_hrs.
I know it truncates the values..but just check if it works.
Regards
Anurag
05-15-2007 5:48 PM
Hi Rich,
I have tried your code in our sandbox and it works well. However the mail never reached the internet mail address I put in the program(my Outlook) and it stayed in my SAP business workplace "Outbox" with a yellow triangle said "send process still running". But sending internet mail in SBWP by itself works fine. Could you please point me to the right direction what could be missing for the problem I had?
Thank you in advance,
Merta
12-26-2007 6:17 AM
Hi ,
I have used the logic that youhave given in the post its working fine but when i got the mail it also have the text
&SO
&SO_FORMAT=ASC
what is it ?????
The mail that i m getting is like this :-
The Notification 56 has been created due to abnormal measuring point 000000000010
Thanks and Regards
Contact : sap_basis@hpindia.com &SO
&SO_FORMAT=ASC
Could you please help me.
Thanks and Regards,
Rachit Khanna
09-05-2006 3:30 PM
The best way to do it is using WRITE with offset.
offset = 0.
Loop at itab.
describe field ifld length llen in character mode.
write ifld to ltext+offset(llen).
offset = llen + offset.
....=>u need to do it for all your fields.
at end of empno.
itext-line = ltext.
append itext.
endat.
endloop.
09-07-2006 8:11 AM
Hi Anurag Bankley
i tried as you said
but i did not get the proper alignment
i am getting the same alignment problem
09-07-2006 8:22 AM
Hi chanti,
1. This alignment will come.
2. Bcos it will come in normal word file also.
3. This is due to the FONT
and the width occupied
by different characters
(including 1 space, 1 capital character, 1 small character)
4. All the width is different.
5. If courier font is used,
it will be uniform for all characters.
regards,
amit m.
09-07-2006 8:42 AM
Can you please paste your code !!
Secondly hope the length of the text is not more than 65 or something which can lead to wrapping in the mail text.
Regards
Anurag
09-07-2006 8:51 AM
Hi,
this is the code
i dont want any attachment
***********************************************************************
*& Form process_mail
************************************************************************
form process_mail .
data: offset type i,
llen(40) type c.
sort it_final by manager_pernr.
loop at it_final .
To get the employee name
read table it_pa0001 with key pernr = it_final-emp_pernr.
if sy-subrc = 0.
v_empname = it_pa0001-ename.
endif.
at new manager_pernr.
To get the manager name
read table it_pa0001 with key pernr = it_final-manager_pernr.
if sy-subrc = 0.
v_managername = it_pa0001-ename.
endif.
Fill mail-text
perform mail_text.
endat.
if it_final-wbs is not initial.
offset = 0.
describe field it_final-emp_pernr length llen in character mode.
write it_final-emp_pernr to it_mailtext+offset(llen).
offset = llen + offset.
describe field v_empname length llen in character mode.
write v_empname to it_mailtext+offset(llen).
offset = llen + offset.
describe field it_final-wbs length llen in character mode.
write it_final-wbs to it_mailtext+offset(llen).
offset = llen + offset.
describe field it_final-total_hrs length llen in character mode.
write it_final-total_hrs to it_mailtext+offset(llen).
offset = llen + offset.
it_mailtext-line = it_mailtext.
append it_mailtext.
clear it_mailtext.
elseif it_final-kostl is not initial.
offset = 0.
describe field it_final-emp_pernr length llen in character mode.
write it_final-emp_pernr to it_mailtext+offset(llen).
offset = llen + offset.
describe field v_empname length llen in character mode.
write v_empname to it_mailtext+offset(llen).
offset = llen + offset.
describe field it_final-kostl length llen in character mode.
write it_final-kostl to it_mailtext+offset(llen).
offset = llen + offset.
describe field it_final-total_hrs length llen in character mode.
write it_final-total_hrs to it_mailtext+offset(llen).
offset = llen + offset.
it_mailtext-line = it_mailtext.
append it_mailtext.
clear it_mailtext.
endif.
at end of manager_pernr.
clear it_mailtext.
append it_mailtext.
append it_mailtext.
it_mailtext-line = 'Regards,'.
append it_mailtext.
clear it_mailtext.
it_mailtext-line = 'Team'.
append it_mailtext.
clear it_mailtext.
append lines of it_mailtext to it_objtext.
append it_mailtext.
clear it_mailtext.
append it_mailtext.
concatenate 'This is an auto notification.'
'Please do not reply to this mail ID'
into it_mailtext-line separated by space.
append it_mailtext.
clear it_mailtext.
append it_mailtext.
Creation of the entry for the compressed document
clear it_objpack-transf_bin.
it_objpack-transf_bin = ' '.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-doc_type = 'RAW'.
append it_objpack.
perform send_mail.
endat.
endloop.
endform. " process_mail
************************************************************************
*& Form mail_text
************************************************************************
form mail_text .
data :head_desc like it_mailtext,
body_desc like it_mailtext.
clear it_mailtext.
refresh it_mailtext.
concatenate 'Dear' v_managername
into it_mailtext-line separated by space.
concatenate it_mailtext-line ','
into it_mailtext-line.
append it_mailtext.
clear it_mailtext.
append it_mailtext.
concatenate 'The following unapproved timesheets'
'exist in your ESS.'
into it_mailtext-line separated by space.
append it_mailtext.
clear it_mailtext.
concatenate 'Please ignore this mail if already'
'approved.'
into it_mailtext-line separated by space.
append it_mailtext.
clear it_mailtext.
append it_mailtext.
it_mailtext-line+2(8) = 'Emp-No'.
it_mailtext-line+15(8) = 'Emp-Name'.
it_mailtext-line+65(20) = 'WBS/CostCenter'.
it_mailtext-line+84(10) = 'Total Hrs'.
append it_mailtext.
clear it_mailtext.
concatenate '----
'
'----
'
'----
'
into it_mailtext-line .
append it_mailtext.
clear it_mailtext.
append it_mailtext.
endform. " mail_text
************************************************************************
*& Form send_mail
************************************************************************
form send_mail .
clear v_error.
clear fs_object_hd_change.
clear v_approver_mailid.
fs_object_hd_change-objla = sy-langu.
fs_object_hd_change-objnam = 'MAIL'.
fs_object_hd_change-objdes = 'Unapproved Timesheets'.
fs_object_hd_change-objpri = 3.
fs_object_hd_change-objsns = 'F'.
fs_object_hd_change-ownnam = v_usrid.
refresh it_receivers_text.
clear it_receivers_text.
move sy-datum to it_receivers_text-rcdat .
move sy-uzeit to it_receivers_text-rctim.
move '1' to it_receivers_text-sndpri.
move 'X' to it_receivers_text-sndex.
move 'U-' to it_receivers_text-recnam.
move 'U' to it_receivers_text-recesc.
move 'INT' to it_receivers_text-sndart.
move '5' to it_receivers_text-sortclass.
append it_receivers_text.
v_approver = it_final-manager_pernr.
if v_approver_mailid is initial.
call function 'ZBAPI_GET_MAIL_ID_FROM_PERNR'
exporting
pernr = v_approver
importing
mail_id = v_approver_mailid.
if v_approver_mailid is initial.
v_error = 'X'.
v_message = 'Failed to obtain approver''s mailid'.
endif.
endif.
it_receivers_text-recextnam = v_approver_mailid.
append it_receivers_text.
if v_sim_mode = '0'. " Not in simulation mode
v_owner = v_usrid.
else.
v_owner = sy-uname.
endif.
call function 'SO_OBJECT_SEND'
exporting
object_hd_change = fs_object_hd_change
object_type = 'RAW'
outbox_flag = 'X'
owner = v_owner
tables
objcont = it_mailtext
receivers = it_receivers_text
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
forwarder_not_exist = 6
note_not_exist = 7
object_not_exist = 8
object_not_sent = 9
object_no_authorization = 10
object_type_not_exist = 11
operation_no_authorization = 12
owner_not_exist = 13
parameter_error = 14
substitute_not_active = 15
substitute_not_defined = 16
system_failure = 17
too_much_receivers = 18
user_not_exist = 19
originator_not_exist = 20
x_error = 21
others = 22.
v_char_subrc = sy-subrc.
if sy-subrc ne 0.
v_error = 'X'.
concatenate 'Error:'
v_char_subrc
'Could not send email to ' v_mailid
into v_message
separated by space.
else.
commit work.
v_message = 'Approval mails sent'.
endif.
09-07-2006 9:19 AM
write it_final-emp_pernr to it_mailtext+offset(llen).
Change it to ...
write it_final-emp_pernr to it_mailtext-line+offset(llen).
It would be nice if you cut paste the output of it even ...and also please check in debug mode the table it_mailtext if the fields are coming below each other !!
Regards
Anurag
09-07-2006 11:00 AM
HI
this is the output in mail body
Emp-No Emp-Name WBS/CostCenter Total Hrs
-
00010000xxxxxxxx xxxxxxxx I/xxxxxxxxxx/0000x0 49.00
0001xx10xxxxxxx MOHAMMED I/000000xxxx/000010 36.00
00012xx6PAxxxxxx xxxxRU IxxxC 60.00
0001xxx9SHxx xxxxxx I/000000xxxx/000050 40.00
000100x1Rxxxxx xxxxxxI IxxxN 39.00
09-07-2006 11:06 AM
Can you please check in debug mode the entries in table mailtext. If the fields are alligned correctly...
Also, you can use the field length instead of describe statement..example if you empno is 5 char...than write to mailtext-line+0(5)...second field empname is 10 char.
write empname to mailtext-line+6(10).
Please check if there is no overalap.
09-07-2006 11:29 AM
i tried in that way also
in debug mode i am getting corect alignment for this code
write empname to mailtext-line+6(10).
insted of write,i am using like this
it_mailtext-line+0(8) = it_final-emp_pernr.
it_mailtext-line+13(23) = v_empname.
it_mailtext-line+28(47) = it_final-wbs.
it_mailtext-line+52(58) = it_final-total_hrs.
09-07-2006 11:42 AM
That is interesting ..can you forward a copy of the email to my email id anurag.bankley@ge.com
If the above is not a problem for you !!