‎2008 Feb 01 6:03 AM
Hi All,
Can any one send me the documentation on sending Email automatically using HTML code in BSP (Not HTMLB),I saw so many blogs but all of those are related to HTMLB.
thanks®ds,
Srinivas.
Edited by: Srinivas on Feb 1, 2008 7:14 AM
‎2008 Feb 01 6:06 AM
Hi Srinivas
Check this code.. it converts spool as HTML.. and e-mail's it..
data: list type table of abaplist with header line.
data: htmllines type table of w3html with header line.
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.
* Produce a list
do 100 times.
write:/ sy-index, at 30 sy-index, at 50 sy-index.
enddo.
* Save the list
call function 'SAVE_LIST'
tables
listobject = list
exceptions
list_index_invalid = 1
others = 2.
* Convert the list
call function 'WWW_LIST_TO_HTML'
tables
html = htmllines.
* Send mail
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test Subject'.
loop at htmllines.
mailtxt = htmllines.
append mailtxt.
endloop.
mailrec-receiver = 'you@yourcompany.com'.
mailrec-rec_type = 'U'.
append mailrec.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type = 'HTM'
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.
Award points if helpful.
‎2008 Feb 01 6:09 AM
Hi,
Check out this code.
DATA: ist_objcont type table of solisti1, " Document Content
wa_objcont type solisti1.
DATA: ist_reclist type table of somlreci1," Document recipients
wa_reclist type somlreci1.
DATA: doc_chng TYPE sodocchgi1. " Attributes of new document
DATA: entries TYPE I. "To find number of lines in Document Content
DATA : strbody(2000) TYPE c.
data: d_date(2) type c,
m_date(2) type c,
y_date(4) type c,
w_date(10) type c.
data:l_char(2) type c.
data:l_pernr(8) type c.
data: l_ind type i.
fill the document
doc_chng-obj_name = 'Subordinate Exit'.
doc_chng-obj_descr = 'Subordinate Exit'.
doc_chng-sensitivty = 'P'.
wa_objcont-line = '<html>'.
append wa_objcont to ist_objcont.
clear wa_objcont.
wa_objcont-line = '<body>'.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
concatenate 'Dear Manager' ',' into strbody .
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
wa_objcont-line = '<BR>'. " new line
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
wa_objcont-line = '<BR>'.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
move wa_pernr-ename to strbody.
l_pernr = wa_pernr-pernr.
write wa_pernr no-zero to l_pernr.
concatenate strbody '(' into strbody separated by space.
concatenate strbody l_pernr ')' into strbody.
concatenate strbody text-001 into strbody
separated by space.
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
write: l_date+6(2) to d_date.
write: l_date+4(2) to m_date.
write: l_date(4) to y_date.
clear w_date.
concatenate d_date '-' m_date '-' y_date into w_date.
concatenate w_date '.' into strbody.
concatenate strbody text-002 into strbody
separated by space.
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
move text-003 to strbody.
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
move text-004 to strbody.
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
move text-005 to strbody.
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
wa_objcont-line = '<BR>'.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
wa_objcont-line = '<BR>'.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
concatenate text-006 wa_pernr-ename '(' into strbody
separated by space.
clear l_pernr.
write wa_pernr no-zero to l_pernr.
l_pernr = wa_pernr-pernr.
concatenate strbody l_pernr ')' into strbody.
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
wa_objcont-line = '<BR>'.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
wa_objcont-line = '<BR>'.
append wa_objcont to ist_objcont.
*----
table
clear wa_objcont.
wa_objcont-line =
'<TABLE border=1 cellspacing =0 cellpadding = 0 bordercolor=black><tr>'.
append wa_objcont to ist_objcont.
*------column 1
clear: wa_objcont,strbody.
strbody = '<td><B>'.
concatenate strbody 'SR no' '</B></td>' into strbody .
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
*------column 2
clear: wa_objcont,strbody.
strbody = '<td><B>'.
concatenate strbody 'Employee Name' '</B></td>' into strbody .
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
*------column 3
clear: wa_objcont,strbody.
strbody = '<td><B>'.
concatenate strbody 'Sal Code' '</B></td>' into strbody .
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
loop at ist_main into wa_main where pernr = wa_pernr-pernr.
l_ind = l_ind + 1.
l_char = l_ind.
*------row 1 in table
clear: wa_objcont,strbody.
strbody = '<tr>'.
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
*------row 2 in table
strbody = '<td>'.
concatenate strbody l_char '</td>' into strbody.
wa_objcont-line = strbody .
append wa_objcont to ist_objcont.
clear: wa_objcont, strbody.
*------row 3 in table
strbody = '<td>'.
if wa_main-sname is initial.
concatenate strbody ' </td>' into strbody.
else.
concatenate strbody wa_main-sname '</td>' into strbody.
endif.
wa_objcont-line = strbody .
append wa_objcont to ist_objcont.
clear: wa_objcont, strbody.
strbody = '<td>'.
if wa_main-pernr is initial.
concatenate strbody ' </td>' into strbody.
else.
clear l_pernr.
write wa_main-subpernr no-zero to l_pernr.
concatenate strbody l_pernr '</td>' into strbody.
endif.
wa_objcont-line = strbody .
append wa_objcont to ist_objcont.
clear: wa_objcont,strbody.
strbody = '</tr>'.
wa_objcont-line = strbody.
append wa_objcont to ist_objcont.
endloop.
clear wa_objcont.
wa_objcont-line = '</table>'.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
wa_objcont-line = '<BR>'.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
wa_objcont-line = '<BR>'.
append wa_objcont to ist_objcont.
clear: strbody,wa_objcont.
wa_objcont-line = text-007.
append wa_objcont to ist_objcont.
clear wa_objcont.
wa_objcont-line = '</body></html>'.
append wa_objcont to ist_objcont.
DESCRIBE TABLE ist_objcont LINES entries.
READ TABLE ist_objcont INDEX entries into wa_objcont.
doc_chng-doc_size = ( entries - 1 ) * 255 + STRLEN( wa_objcont ).
perform get_superior using wa_pernr.
perform send_mail.
ENDFORM. " add_body_content
&----
*& Form get_superior
&----
FORM get_superior USING wa_PERNR type ty_pernr.
data: ist_hrplist type table of YHRS_HRP01,
wa_hrplist type yhrs_hrp01.
data: wa_pa0105 type pa0105.
***getting superior
CALL FUNCTION 'YHRF_COMN_GETSUPERIORS'
EXPORTING
PERNR = wa_pernr-pernr
ONDATE = sy-datum
MAXHLEVEL = '01'
TABLES
HRPLIST = ist_hrplist.
read table ist_hrplist into wa_hrplist with key hlevel = '01'.
if sy-subrc = 0.
getting superior official mail address
select single * from pa0105
into wa_pa0105
where pernr = wa_hrplist-pernr
and subty = '0010'
and begda <= sy-datum
and endda >= sy-datum.
if sy-subrc = 0.
clear: ist_reclist[], wa_reclist.
move wa_pa0105-usrid_long to wa_reclist-receiver.
move 'U' to wa_reclist-rec_type.
append wa_reclist to ist_reclist.
endif.
getting managers official mail address
clear wa_pa0105.
select single * from pa0105
into wa_pa0105
where pernr = wa_pernr-pernr
and subty = '0010'
and begda <= sy-datum
and endda >= sy-datum.
if sy-subrc = 0.
clear: wa_reclist.
move wa_pa0105-usrid_long to wa_reclist-receiver.
move 'U' to wa_reclist-rec_type.
move 'X' to wa_reclist-copy.
append wa_reclist to ist_reclist.
endif.
endif.
ENDFORM. " get_superior
&----
*& Form send_mail
&----
FORM send_mail .
***sending mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = doc_chng
DOCUMENT_TYPE = 'HTM'
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
OBJECT_CONTENT = ist_objcont
RECEIVERS = ist_reclist
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 8.
ENDFORM. " send_mail
regards,
Santosh Thorat
‎2008 Feb 01 6:46 AM
Hi
Check these links it will help u alot
BSP email with option (YES/NO) or (ACCEPT/REJECT)
Email from BSP
Sending An email from BSP
Sending E-Mails from BSP Applications
http://help.sap.com/saphelp_nw70/helpdata/en/58/97c43af280463ee10000000a114084/content.htm
Send Email from BSP --> Character Settings
Guidance on Internal Tables in BSP's & ABAP Functions
Check these blogs
/people/eddy.declercq/blog/2006/04/03/unknown-thus-unloved
Regards
Pavan