09-11-2007 9:54 AM
Dear All,
I need ur help in a situation.
In a screen I have a Button -SEND. On clicking this I need to send a pdf - file as attachment in a mail to selected recipients with a message.
Can anybody plz send me the code.
09-11-2007 1:02 PM
----
FORM SEND_MAIL *
----
........ *
----
form send_mail .
clear reclist.
refresh reclist.
select * from zmmmapmail into table int_zmmmapmail
where werks = p_bwkey.
clear : line.
describe table downtab1 lines tab_lines.
read table downtab1 index tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + strlen( downtab1 ).
doc_chng-obj_name = 'Information'.
concatenate 'Auto Generated Alert Mail ' '.' into line
separated by space.
doc_chng-obj_descr = line.
Mail contents in downtab1
objtxt[] = downtab1[].
Attachment contents in downtab2
objbin[] = downtab2[].
objhead-line = 'Header Object'. append objhead.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
clear objpack-transf_bin.
*OBJPACK-TRANSF_BIN = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
*OBJPACK-BODY_NUM = 1.
objpack-doc_type = 'RAW'.
objpack-obj_name = 'Mail'.
objpack-obj_descr = 'First Mail'.
objpack-doc_size = 1 * 255.
append objpack.
clear objpack.
describe table objbin lines tab_lines.
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'PDF'.
objpack-obj_name = 'Materials'.
read table objbin index tab_lines.
objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ).
append objpack.
<<<<<<<* FILL LIKE THIS YOUR MAIL ID...>>>>>>
loop at int_zmmmapmail.
reclist-receiver = int_zmmmapmail-userid.
reclist-rec_type = 'U'.
reclist-com_type = 'INT'.
reclist-notif_del = 'X'.
reclist-notif_ndel = 'X'.
append reclist.
clear reclist.
endloop.
Sending the document
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
tables
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
receivers = reclist
exceptions
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
others = 99.
gd_error = sy-subrc.
endform.
&----
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
&----
Instructs mail send program for SAPCONNECT to send email.
----
form initiate_mail_execute_program.
wait up to 2 seconds.
if gd_error eq 0.
submit rsconn01 with mode = 'INT'
with output = 'X'.
endif.
endform. " INITIATE_MAIL_EXECUTE_PROGRAM
09-11-2007 10:00 AM
Refer the following link for more details:
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
09-11-2007 1:02 PM
----
FORM SEND_MAIL *
----
........ *
----
form send_mail .
clear reclist.
refresh reclist.
select * from zmmmapmail into table int_zmmmapmail
where werks = p_bwkey.
clear : line.
describe table downtab1 lines tab_lines.
read table downtab1 index tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + strlen( downtab1 ).
doc_chng-obj_name = 'Information'.
concatenate 'Auto Generated Alert Mail ' '.' into line
separated by space.
doc_chng-obj_descr = line.
Mail contents in downtab1
objtxt[] = downtab1[].
Attachment contents in downtab2
objbin[] = downtab2[].
objhead-line = 'Header Object'. append objhead.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
clear objpack-transf_bin.
*OBJPACK-TRANSF_BIN = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
*OBJPACK-BODY_NUM = 1.
objpack-doc_type = 'RAW'.
objpack-obj_name = 'Mail'.
objpack-obj_descr = 'First Mail'.
objpack-doc_size = 1 * 255.
append objpack.
clear objpack.
describe table objbin lines tab_lines.
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'PDF'.
objpack-obj_name = 'Materials'.
read table objbin index tab_lines.
objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ).
append objpack.
<<<<<<<* FILL LIKE THIS YOUR MAIL ID...>>>>>>
loop at int_zmmmapmail.
reclist-receiver = int_zmmmapmail-userid.
reclist-rec_type = 'U'.
reclist-com_type = 'INT'.
reclist-notif_del = 'X'.
reclist-notif_ndel = 'X'.
append reclist.
clear reclist.
endloop.
Sending the document
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
tables
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
receivers = reclist
exceptions
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
others = 99.
gd_error = sy-subrc.
endform.
&----
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
&----
Instructs mail send program for SAPCONNECT to send email.
----
form initiate_mail_execute_program.
wait up to 2 seconds.
if gd_error eq 0.
submit rsconn01 with mode = 'INT'
with output = 'X'.
endif.
endform. " INITIATE_MAIL_EXECUTE_PROGRAM
09-12-2007 3:06 PM
Dear Lakshmiraj,
Can you please send me the whole code instead of just a piece of code.
I tried to declare all the tables mentioned, and activated the program but when I executed it it gave an error in function module SO_NEW_DOCUMENT_ATT_SEND_API1
<b>ERROR</b> --> Exception condition "X_ERROR" raised.
Please help.
Thanks...............Amit