2006 Jun 14 8:08 PM
hi all,
we have a requirement to send an e-mail to the external system.
the content of the e-mail has to be filled with the entries of an Internal table.
how do we do this ?
Thanks in Advance,
Kishore Kumar Yerra.
hi all,
we have a requirement to send an e-mail to the external system.
the content of the e-mail has to be filled with the entries of an Internal table.
how do we do this ?
Thanks in Advance,
Kishore Kumar Yerra.
2006 Jun 14 8:10 PM
hi Kishore,
Have a look at this program
http://www.sapdevelopment.co.uk/reporting/email/email_mbody.htm
Regards,
santosh
2006 Jun 14 8:13 PM
hi kishore,
check this code...
tables: mara, makt.
data: objpack like sopcklsti1 occurs 2 with header line.
data: objhead like solisti1 occurs 1 with header line.
data: objbin like solisti1 occurs 10 with header line.
data: objtxt like solisti1 occurs 10 with header line.
*DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
data: doc_chng like sodocchgi1.
data: tab_lines like sy-tabix.
*creation of document to be sent.
doc_chng-obj_name = 'Mailing List'.
doc_chng-obj_descr = 'Materials report'.
*type declarations
*To store material data
types: begin of t_mara,
matnr type mara-matnr,
pstat type mara-pstat,
mtart type mara-mtart,
mbrsh type mara-mbrsh,
meins type mara-meins,
end of t_mara.
*--To store Material Description
types: begin of t_makt,
matnr type makt-matnr, " Material Number
maktx type makt-maktx, " Material Description
end of t_makt.
types: begin of t_final,
matnr type mara-matnr,
maktx type makt-maktx,
pstat type mara-pstat,
mtart type mara-mtart,
mbrsh type mara-mbrsh,
meins type mara-meins,
end of t_final.
*Internal table declarations.
*--Internal Table to store Material Description
data: it_makt type standard table of t_makt,
*--Internal Table to store Material details
it_mara type standard table of t_mara,
it_objtxt type standard table of solisti1 , "object text
it_objpack type standard table of sopcklsti1 ,
" attachment table
it_objbin type standard table of solisti1 ,
" binary table
it_objhead type standard table of solisti1 ,
" object header table
*--Internal Table to hold Final records to download/display
it_final type standard table of t_final.
data: it_reclist type standard table of somlreci1. "Workarea for internal table
data: x_makt type t_makt, "Work area for IT_MAKT
x_mara type t_mara, "Work area for IT_MARA
x_final type t_final, "Work area for IT_FINAL
v_text(255) type c.
*--Work area for all the internal tables used
data : wa_objpack type sopcklsti1,
wa_objhead type solisti1 ,
wa_objbin type solisti1 ,
wa_objtxt type solisti1 ,
wa_reclist type somlreci1 .
constants: c_tab type c value cl_abap_char_utilities=>horizontal_tab.
*selection screen.
selection-screen: begin of block b1 with frame title text-001.
select-options: s_matnr for mara-matnr.
selection-screen: end of block b1.
*at selection screen.
*AT SELECTION-SCREEN.
PERFORM VALIDATE_SCREEN.
*
*start of selection.
start-of-selection.
perform get_mara_details.
perform get_makt_details.
perform final_data.
*end of selection
end-of-selection.
perform send_mail_data.
perform display_data.
&----
*& Form validate_screen
&----
text
----
--> p1 text
<-- p2 text
----
*FORM VALIDATE_SCREEN .
*
DATA: LV_MATNR TYPE MARA-MATNR.
*
IF NOT S_MATNR[] IS INITIAL.
*
SELECT MATNR INTO
LV_MATNR
UP TO 1 ROWS
FROM MARA
WHERE MATNR IN S_MATNR.
*
ENDSELECT.
ENDIF.
IF SY-SUBRC <> 0.
MESSAGE E000 WITH 'Invalid material'.
ENDIF.
*ENDFORM. " validate_screen
*
&----
*& Form get_mara_details
&----
text
----
--> p1 text
<-- p2 text
----
form get_mara_details .
select matnr
pstat
mtart
mbrsh
meins
into table it_mara
from
mara where
matnr in s_matnr.
if sy-subrc <> 0.
message i000 with 'No doc found'.
endif.
sort it_mara by matnr.
delete adjacent duplicates from it_mara comparing matnr.
endform. " get_mara_details
&----
*& Form get_makt_details
&----
text
----
--> p1 text
<-- p2 text
----
form get_makt_details .
select matnr
maktx
from makt
into table it_makt
for all entries in it_mara
where matnr = it_mara-matnr and
spras = sy-langu.
endform. " get_makt_details
&----
*& Form final_data
&----
text
----
--> p1 text
<-- p2 text
----
form final_data .
loop at it_mara into x_mara.
clear x_final.
read table it_makt into x_makt with key matnr = x_mara-matnr.
if sy-subrc = 0.
x_final-maktx = x_makt-maktx.
endif.
x_final-matnr = x_mara-matnr.
x_final-pstat = x_mara-pstat.
x_final-mtart = x_mara-mtart.
x_final-mbrsh = x_mara-mbrsh.
x_final-meins = x_mara-meins.
append x_final to it_final.
endloop.
endform. " final_data
&----
*& Form send_mail_data
&----
text
----
--> p1 text
<-- p2 text
----
form send_mail_data .
wa_reclist-rec_type = 'B'.
wa_reclist-express = 'X'.
wa_reclist-receiver = 'DEV02'.
append wa_reclist to it_reclist.
concatenate 'MATERIAL DATA'(021)
sy-datum into doc_chng-obj_descr separated by space.
*--Mail body
concatenate 'MATERIAL DESCRIPTION'(022) 'ATTACHMENT' into wa_objtxt sePARATED BY SPACE.
append wa_objtxt to it_objtxt.
describe table it_objtxt lines tab_lines.
read table it_objtxt into wa_objtxt index tab_lines .
doc_chng-doc_size =
( tab_lines - 1 ) * 255 + strlen( wa_objtxt ).
*-populate packing list for body text
wa_objpack-head_start = 1.
wa_objpack-head_num = 0.
wa_objpack-body_start = 1.
wa_objpack-body_num = tab_lines.
wa_objpack-doc_type = 'RAW'.
append wa_objpack to it_objpack.
clear wa_objpack.
*--for attachment
*--Populate Column headings
concatenate text-040 " Material Number
text-041 " Material Description
text-042 " Maintenence status
text-043 " Material type
text-044 " Industry sector
text-045 " Base unit of measure
into v_text separated by c_tab.
CONCATENATE V_TEXT
C_CR_LF
INTO V_TEXT.
wa_objbin = v_text.
append wa_objbin to it_objbin.
clear wa_objbin.
*--Populate Data to the attachment
loop at it_final into x_final.
concatenate x_final-matnr
x_final-maktx
x_final-pstat
x_final-mtart
x_final-mbrsh
x_final-meins
into v_text separated by c_tab.
*--Go to next line after this record.
CONCATENATE V_TEXT
C_CR_LF
INTO V_TEXT.
wa_objbin = v_text.
append wa_objbin to it_objbin.
clear wa_objbin.
endloop.
CLEAR : TAB_LINES.
describe table it_objbin lines tab_lines.
*1ST ATTACHMENT : MAT 5000 PLANT
*2ND ATT : MAT 5010 PLANTS
sort it_final by meins.
data : v_begin type sy-tabix,
v_end type sy-tabix.
loop at it_final into x_final.
at end of meins.
if v_begin is initial.
v_begin = 1.
else.
v_begin = v_end + 1.
endif.
v_end = sy-tabix.
wa_objpack-transf_bin = 'X'.
wa_objpack-head_start = 1.
wa_objpack-head_num = 1.
wa_objpack-body_start = v_begin.
wa_objpack-body_num = v_end.
wa_objpack-doc_type = 'RAW' .
wa_objpack-obj_name = 'MATERIAL'.
wa_objpack-obj_descr = 'attachment'.
wa_objpack-doc_size = tab_lines * 255.
append wa_objpack to it_objpack.
endat.
endloop.
*-populate object header(attachment name)
wa_objhead = 'MATERIAL DETAILS'.
append wa_objhead to it_objhead.
clear wa_objhead.
*-packing list for attachment
wa_objpack-transf_bin = 'X'.
wa_objpack-head_start = 1.
wa_objpack-head_num = 1.
wa_objpack-body_start = 1.
wa_objpack-body_num = tab_lines .
wa_objpack-doc_type = 'RAW' .
wa_objpack-obj_name = 'MATERIAL'.
wa_objpack-obj_descr = 'ATTACHMENT DESCRIPTION'.
wa_objpack-doc_size = tab_lines * 255.
append wa_objpack to it_objpack.
clear wa_objpack.
*-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 = it_objpack
object_header = it_objhead
contents_bin = it_objbin
contents_txt = it_objtxt
receivers = it_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.
message e000 with 'Error occurred in sending mail'(039).
else.
message i000 with 'Mail sent'(010).
endif.
endform. " send_mail_data
&----
*& Form DISPLAY_DATA
&----
text
----
--> p1 text
<-- p2 text
----
form display_data .
write 😕 sy-uline.
write:/1 sy-vline,
2 'Material No'(024),
19 sy-vline,
20 'Material Description'(025),
61 sy-vline,
62 'Maintainence Status'(026),
71 sy-vline,
72 'Material type'(027),
89 sy-vline,
90 'Industry sector'(028),
107 sy-vline,
108 'Base unit of measure'(029),
125 sy-vline.
write:/1 sy-vline,
19 sy-vline,
61 sy-vline,
71 sy-vline,
89 sy-vline,
107 sy-vline,
125 sy-vline.
write 😕 sy-uline.
endform. " DISPLAY_DATA
hope this helps,
do reward if it helps,
priya.
2006 Jun 15 2:25 AM
Hi Kishore,
<b>1</b>.
Have a look at this program.
REPORT zvenkat_mail.
TABLES :
tsp01.
*----
Itabs and variables .
*Tables
DATA:
BEGIN OF i_mard OCCURS 0,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
labst TYPE mard-labst,
umlme TYPE mard-umlme,
insme TYPE mard-insme,
einme TYPE mard-einme,
END OF i_mard.
DATA :
g_sy_spono LIKE sy-spono.
*----
Mail related Variables and i tabs.
DATA:
w_subject LIKE sodocchgi1,
i_pack_list LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
i_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
i_contents_text LIKE solisti1 OCCURS 10 WITH HEADER LINE,
i_cont_bin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
i_objhex LIKE solix OCCURS 10 WITH HEADER LINE,
i_receiver LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
i_listobject LIKE abaplist OCCURS 1 WITH HEADER LINE,
pdf LIKE tline OCCURS 100 WITH HEADER LINE,
content_out LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA:
tab_lines TYPE i,
doc_size TYPE i,
att_type LIKE soodk-objtp,
obj_desc LIKE w_subject-obj_descr,
sent_to_all LIKE sonv-flag,
client LIKE tst01-dclient,
name LIKE tst01-dname,
objtype LIKE rststype-type,
type LIKE rststype-type,
is_otf TYPE c ,
no_of_bytes TYPE i,
pdf_spoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount,
pn_begda LIKE sy-datum,
val(1) TYPE c,
pripar TYPE pri_params,
arcpar TYPE arc_params,
lay TYPE pri_params-paart,
lines TYPE pri_params-linct,
cols TYPE pri_params-linsz,
spool_name TYPE pri_params-plist.
&----
*& START-OF-SELECTION.
&----
START-OF-SELECTION.
PERFORM get_data_from_database.
<b> PERFORM output_for_pdf.</b>
&----
*& END-OF-SELECTION.
&----
END-OF-SELECTION.
<b> PERFORM send_mail..</b>
&----
*& Form get_data_from_database
&----
FORM get_data_from_database .
SELECT matnr
werks
lgort
labst
umlme
insme
einme
FROM mard
INTO TABLE i_mard
UP TO 20 ROWS.
ENDFORM. " get_data_from_database
&----
*& Form output_for_pdf
&----
FORM output_for_pdf .
PERFORM get_print_params.
LOOP AT i_mard.
WRITE:/ sy-vline, i_mard-matnr,
sy-vline, i_mard-werks,
sy-vline, i_mard-lgort,
sy-vline, i_mard-labst,
sy-vline, i_mard-umlme,
sy-vline, i_mard-insme,
sy-vline, i_mard-einme,
sy-vline.
ENDLOOP.
ULINE .
g_sy_spono = sy-spono.
NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
ENDFORM. " output_for_pdf
&----
*& Form send_mail
&----
FORM send_mail .
<b> PERFORM mail_without_attachment.
PERFORM mail_with_pdf_attachment.</b>
ENDFORM. " send_mail
&----
*& Form mail_without_attachment
&----
FORM mail_without_attachment .
CLEAR :w_subject,
sent_to_all,
i_pack_list[],
i_objhead[],
i_cont_bin[],
i_contents_text[],
i_receiver[].
i_cont_bin = ' | '.
APPEND i_cont_bin.
<b>*----
Subject of the mail.</b>
obj_desc = 'SDN Friends' .
w_subject-obj_name = 'MAIL_ALI'.
w_subject-obj_descr = obj_desc.
<b>*----
Body of the mail</b>
DATA :head_desc LIKE i_contents_text,
body_desc LIKE i_contents_text.
i_contents_text = space.
APPEND i_contents_text.
CLEAR i_contents_text.
<b> This is the place where u have to loop ur internal table and fill this table if u want email without Attachment </b>
CONCATENATE
'This mail has been generated for Test purpose.'
'Please dont hesitate to ask any type of question in the forum.'
INTO body_desc
SEPARATED BY space.
i_contents_text = body_desc.
APPEND i_contents_text.
CLEAR i_contents_text.
CLEAR body_desc.
i_contents_text = 'Thank You.'.
APPEND i_contents_text.
CLEAR i_contents_text.
i_contents_text = 'Fellow SDN member,'.
APPEND i_contents_text.
CLEAR i_contents_text.
i_contents_text = 'Venkat.O'.
APPEND i_contents_text.
CLEAR i_contents_text.
i_contents_text = space.
APPEND i_contents_text.
CLEAR i_contents_text.
CONCATENATE '(Note: This is system generated message, please'
'do not reply'
'to this Email.)'
INTO i_contents_text
SEPARATED BY space.
APPEND i_contents_text.
CLEAR i_contents_text.
<b>*----
Write Packing List (Body)</b>
DESCRIBE TABLE i_contents_text LINES tab_lines.
READ TABLE i_contents_text INDEX tab_lines.
w_subject-doc_size = ( tab_lines - 1 ) * 255 + STRLEN(
i_contents_text ).
CLEAR i_pack_list-transf_bin.
i_pack_list-head_start = 1.
i_pack_list-head_num = 0.
i_pack_list-body_start = 1.
i_pack_list-body_num = tab_lines.
i_pack_list-doc_type = 'RAW'.
APPEND i_pack_list.
CLEAR i_pack_list.
<b>*----
Create receiver list</b>
i_receiver-receiver = '[email protected]'..
i_receiver-rec_type = 'U'.
APPEND i_receiver.
CLEAR i_receiver.
<b> CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'</b>
EXPORTING
document_data = w_subject
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = sent_to_all
TABLES
packing_list = i_pack_list
object_header = i_objhead
contents_bin = i_cont_bin
contents_txt = i_contents_text
receivers = i_receiver
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 NE 0.
ENDIF.
ENDFORM. " mail_without_attachment
&----
*& Form mail_with_pdf_attachment
&----
FORM mail_with_pdf_attachment .
CLEAR :w_subject,
sent_to_all,
i_pack_list[],
i_objhead[],
i_cont_bin[],
i_contents_text[],
i_receiver[].
i_cont_bin = ' | '.
APPEND i_cont_bin.
*----
Subject of the mail.
obj_desc = 'Hello SDN Friends ' .
w_subject-obj_name = 'MAIL_ALI'.
w_subject-obj_descr = obj_desc.
*----
Body of the mail
DATA :head_desc LIKE i_contents_text,
body_desc LIKE i_contents_text.
i_contents_text = space.
APPEND i_contents_text.
CLEAR i_contents_text.
CONCATENATE
'This mail has been generated for Test purpose.'
'Please dont hesitate to ask any type of question in the forum.'
INTO body_desc
SEPARATED BY space.
i_contents_text = body_desc.
APPEND i_contents_text.
CLEAR i_contents_text.
CLEAR body_desc.
i_contents_text = 'Thank You.'.
APPEND i_contents_text.
CLEAR i_contents_text.
i_contents_text = 'Fellow SDN member,'.
APPEND i_contents_text.
CLEAR i_contents_text.
i_contents_text = 'Venkat.O'.
APPEND i_contents_text.
CLEAR i_contents_text.
i_contents_text = space.
APPEND i_contents_text.
CLEAR i_contents_text.
CONCATENATE '(Note: This is system generated message, please'
'do not reply'
'to this Email.)'
INTO i_contents_text
SEPARATED BY space.
APPEND i_contents_text.
CLEAR i_contents_text.
*----
Write Packing List (Body)
DESCRIBE TABLE i_contents_text LINES tab_lines.
READ TABLE i_contents_text INDEX tab_lines.
w_subject-doc_size = ( tab_lines - 1 ) * 255 + STRLEN(
i_contents_text ).
CLEAR i_pack_list-transf_bin.
i_pack_list-head_start = 1.
i_pack_list-head_num = 0.
i_pack_list-body_start = 1.
i_pack_list-body_num = tab_lines.
i_pack_list-doc_type = 'RAW'.
APPEND i_pack_list.
CLEAR i_pack_list.
*----
Create receiver list
i_receiver-receiver = '[email protected]'..
i_receiver-rec_type = 'U'.
APPEND i_receiver.
CLEAR i_receiver.
*----
Select query for Spool requests
REFRESH content_out.
IF sy-subrc = 0.
SELECT SINGLE *
FROM tsp01
WHERE rqident = g_sy_spono.
IF sy-subrc <> 0.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
ELSE.
client = tsp01-rqclient.
name = tsp01-rqo1name.
ENDIF.
ENDIF.
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
authority = 'SP01'
client = client
name = name
part = 1
IMPORTING
type = type
objtype = objtype
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4
OTHERS = 5.
IF objtype(3) = 'OTF'.
is_otf = 'X'.
ELSE.
is_otf = space.
ENDIF.
*----
Convert Spool job to PDF
IF is_otf = 'X'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = tsp01-rqident "Spool req number
no_dialog = ' '
IMPORTING
pdf_bytecount = no_of_bytes
pdf_spoolid = pdf_spoolid
btc_jobname = jobname
btc_jobcount = jobcount
TABLES
pdf = pdf
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CASE sy-subrc.
WHEN 0.
WHEN 1.
MESSAGE s000(0k) WITH 'No OTF Spool Job'.
EXIT.
WHEN 2.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
WHEN 3.
MESSAGE s000(0k) WITH 'No permission for spool'.
EXIT.
WHEN OTHERS.
MESSAGE s000(0k) WITH 'Error in Function CONVERT_OTFSPOOLJOB_2_PDF'.
EXIT.
ENDCASE.
ELSE.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = tsp01-rqident
no_dialog = ' '
IMPORTING
pdf_bytecount = no_of_bytes
pdf_spoolid = pdf_spoolid
btc_jobname = jobname
btc_jobcount = jobcount
TABLES
pdf = pdf
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CASE sy-subrc.
WHEN 0.
WHEN 1.
MESSAGE s000(0k) WITH 'No ABAP Spool Job'.
EXIT.
WHEN 2.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
WHEN 3.
MESSAGE s000(0k) WITH 'No permission for spool'.
EXIT.
WHEN OTHERS.
MESSAGE s000(0k)
WITH 'Error in Function CONVERT_ABAPSPOOLJOB_2_PDF'.
EXIT.
ENDCASE.
ENDIF.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = pdf
content_out = content_out
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE s000(0k) WITH 'Conversion Failed'.
EXIT.
ENDIF.
---------------------Create Message Attachment
DESCRIBE TABLE i_cont_bin LINES tab_lines.
i_pack_list-transf_bin = 'X'.
i_pack_list-head_start = tab_lines + 1.
i_pack_list-head_num = 0.
i_pack_list-body_start = tab_lines + 1.
APPEND LINES OF content_out[] TO i_cont_bin[].
DESCRIBE TABLE content_out LINES tab_lines.
i_pack_list-doc_size = tab_lines * 255.
i_pack_list-body_num = tab_lines.
i_pack_list-doc_type = 'PDF'.
i_pack_list-obj_name = 'ATTACHMENT'.
i_pack_list-obj_descr = 'Materials and their Quantities' .
APPEND i_pack_list.
CLEAR i_pack_list.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_subject
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = sent_to_all
TABLES
packing_list = i_pack_list
object_header = i_objhead
contents_bin = i_cont_bin
contents_txt = i_contents_text
receivers = i_receiver
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 NE 0.
ENDIF.
ENDFORM. " mail_with_pdf_attachment
&----
*& Form get_print_params
&----
FORM get_print_params .
lay = 'X_65_132'.
lines = 65.
cols = 132.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
in_archive_parameters = arcpar
in_parameters = pripar
layout = lay
line_count = lines
line_size = cols
no_dialog = 'X'
IMPORTING
out_archive_parameters = arcpar
out_parameters = pripar
valid = val
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
IF val <> space AND sy-subrc = 0.
pripar-prrel = space.
pripar-primm = space.
NEW-PAGE PRINT ON
NEW-SECTION
PARAMETERS pripar
ARCHIVE PARAMETERS arcpar
NO DIALOG.
ENDIF.
ENDFORM. " get_print_params
I hope that it helps u .
<b>Thanks,
Venkat.O</b>
2006 Jun 15 4:04 AM
Hi Kishore,
There is another method of sending email..
The from address will be the SAP system... You can send it to any external address..
This is quite easy. It uses the unix command to send email.
The following is the code to send an email.
This program extract does two things
1. Sends file contents as body of the mail
2. Sends a file as attachment.
Before going through the code, just check
the unix command for sending email, given below.
_____________________________________________
(cat 'filename containing the body of email' ; uuencode 'name of file to be attached' 'Name of attached file to be displayed in the email') | /bin/mailx -s "
Subject of the mail " 'To email address'
______________________________________________
Cat sends the file contents as body of email and uuencode sends the file as attachment
(cat content ; uuencode filename fname) | /bin/mailx -s "
'Subject of the mail' " 'To email address'
_____________________________________________
This is the internal table containing the data to be filled in as the mail content
DATA: BEGIN OF mail_body OCCURS 0,
content(250),
END OF mail_body.
********************
FORM mail_message USING username filename.
DATA: BEGIN OF file OCCURS 0,
line(250),
END OF file.
Attached file will be displayed in the mail as 'fname'
'filename' is the file that will be send as attachment in the email.
DATA : filename(100) TYPE c VALUE '/data/logs/lfile.txt'
DATA : fname(25) VALUE 'Logfile.txt'.
DATA: parcom(300) TYPE c,
pbody1(50) VALUE
'Please find the log details as an attachment
(This is the body of email) '
Content contains the file which contains the body of the mail.
Username contains the email address to which the mail has to be sent.
DATA : content(50) VALUE '/usr/sap/tmp/body'.
DATA : username(50) VALUE '[email protected]'.
CLEAR parcom.
TRANSLATE username TO LOWER CASE.
TRANSLATE filename TO LOWER CASE.
TRANSLATE content TO LOWER CASE.
Writing the body of the mail to the file
OPEN DATASET content FOR OUTPUT IN TEXT MODE.
loop at mail_body.
TRANSFER mail_body-content TO content.
endloop
CLOSE DATASET content.
CONCATENATE '(cat ' content '; uuencode ' filename fname ') |' '/bin/mailx -s "'
'Subject of the mail' '"' username
INTO parcom SEPARATED BY space.
*
REFRESH file.
CLEAR file.
Send The Message.
CALL 'SYSTEM' ID 'COMMAND' FIELD parcom
ID 'TAB' FIELD file-sys.
if sy-subrc = '0'.
write: / 'Mail message successfully sent'.
else.
write: / 'Mail message failed'.
endif.
ENDFORM.
___________________________________________________
You will get the mail in the address specified with the body contents as the data in file content.( and attachment if also needed, filename will be send as attachment.
Thanks,
Susmitha
Just let me know if you have got any doubts on this.
Message was edited by: Susmitha Thomas
Message was edited by: Susmitha Thomas
2006 Jun 15 6:17 AM
2006 Jun 15 6:35 AM
Hi Kishore,
Here is a sample program to send mail.
data: maildata type sodocchgi1.
data: mailtxt type table of solisti1 with header line.
data: mailrec type table of somlrec90 with header line.
start-of-selection.
clear: maildata, mailtxt, mailrec.
refresh: mailtxt, mailrec.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test'.
maildata-obj_langu = sy-langu.
mailtxt-line = 'This is a test'.
append mailtxt.
mailrec-receiver = '[email protected]'.
mailrec-rec_type = 'U'.
append mailrec.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type = 'RAW'
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.
Also have a look at these links:
Version 610 and Higher - BCS Interface:
/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface
Version 46D and Lower - API Interface
/people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface
Reward points if helpful,
Thanks & Regards,
Sumana
2006 Jun 15 7:02 AM
HI
GOOD
GO THROUGH THESE CODE AND IMPLEMENT SIMILARLY IN YOUR REPORT
ABAP CODE
Email ITAB structure
DATA: BEGIN OF EMAIL_ITAB OCCURS 10.
INCLUDE STRUCTURE SOLI.
DATA: END OF EMAIL_ITAB.
DATA: T_EMAIL LIKE SOOS1-RECEXTNAM. "EMail distribution list
CONSTANTS: C_EMAIL_DISTRIBUTION LIKE SOOS1-RECEXTNAM VALUE
[email protected],[email protected].
Initialization
REFRESH EMAIL_ITAB.
Populate data
EMAIL_ITAB-LINE = Email body text 1.
APPEND EMAIL_ITAB.
EMAIL_ITAB-LINE = Email body text 2.
APPEND EMAIL_ITAB.
T_EMAIL = C_EMAIL_DISTRIBUTION.
--- EMAIL FUNCTION ---------------------------------------------------
REQUIRMENTS:
1) The user running the program needs a valid email address in their
address portion of tx SU01 under external comms -> SMTP -> internet
address.
2) A job called SAP_EMAIL is running with the following parameters:
Program: RSCONN01 Variant: INT User: XXX
This program moves mail from the outbox to the mail server using
RFC destination: SAP_INTERNET_GATEWAY_SERVER
INTERFACE:
1) APPLICATION: Anything
2) EMAILTITLE: EMail subject
3) RECEXTNAM: EMail distribution lists separated by commas
4) TEXTTAB: Internal table for lines of the email message
EXCEPTIONS:
Send OK = 0 otherwise there was a problem with the send.
----------------------------------------------------------------------
CALL FUNCTION 'Z_SEND_EMAIL_ITAB'
EXPORTING
APPLICATION = 'EMAIL'
EMAILTITLE = 'Email Subject'
RECEXTNAM = T_EMAIL
TABLES
TEXTTAB = EMAIL_ITAB
EXCEPTIONS
OTHERS = 1.
Function Z_SEND_EMAIL_ITAB
""Local interface:
*" IMPORTING
*" VALUE(APPLICATION) LIKE SOOD1-OBJNAM
*" VALUE(EMAILTITLE) LIKE SOOD1-OBJDES
*" VALUE(RECEXTNAM) LIKE SOOS1-RECEXTNAM
*" TABLES
*" TEXTTAB STRUCTURE SOLI
*"----
*- local data declaration
DATA: OHD LIKE SOOD1,
OID LIKE SOODK,
TO_ALL LIKE SONV-FLAG,
OKEY LIKE SWOTOBJID-OBJKEY.
DATA: BEGIN OF RECEIVERS OCCURS 0.
INCLUDE STRUCTURE SOOS1.
DATA: END OF RECEIVERS.
*- fill odh
CLEAR OHD.
OHD-OBJLA = SY-LANGU.
OHD-OBJNAM = APPLICATION.
OHD-OBJDES = EMAILTITLE.
OHD-OBJPRI = 3.
OHD-OBJSNS = 'F'.
OHD-OWNNAM = SY-UNAME.
*- send Email
CONDENSE RECEXTNAM NO-GAPS.
CHECK RECEXTNAM <> SPACE AND RECEXTNAM CS '@'.
*- for every individual recipient send an Email
(see OSS message 0120050409/0000362105/1999)
WHILE RECEXTNAM CS ','.
PERFORM INIT_REC TABLES RECEIVERS.
READ TABLE RECEIVERS INDEX 1.
RECEIVERS-RECEXTNAM = RECEXTNAM+0(SY-FDPOS).
ADD 1 TO SY-FDPOS.
SHIFT RECEXTNAM LEFT BY SY-FDPOS PLACES.
MODIFY RECEIVERS INDEX 1.
PERFORM SO_OBJECT_SEND_REC
TABLES TEXTTAB RECEIVERS
USING OHD.
ENDWHILE.
*- check last recipient in recipient list
IF RECEXTNAM <> SPACE.
PERFORM INIT_REC TABLES RECEIVERS.
READ TABLE RECEIVERS INDEX 1.
RECEIVERS-RECEXTNAM = RECEXTNAM.
MODIFY RECEIVERS INDEX 1.
PERFORM SO_OBJECT_SEND_REC
TABLES TEXTTAB RECEIVERS
USING OHD.
ENDIF.
ENDFUNCTION.
----
FORM SO_OBJECT_SEND_REC *
----
FORM SO_OBJECT_SEND_REC
TABLES OBJCONT STRUCTURE SOLI
RECEIVERS STRUCTURE SOOS1
USING OBJECT_HD STRUCTURE SOOD1.
DATA: OID LIKE SOODK,
TO_ALL LIKE SONV-FLAG,
OKEY LIKE SWOTOBJID-OBJKEY.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
EXTERN_ADDRESS = 'X'
OBJECT_HD_CHANGE = OBJECT_HD
OBJECT_TYPE = 'RAW'
OUTBOX_FLAG = 'X'
SENDER = SY-UNAME
IMPORTING
OBJECT_ID_NEW = OID
SENT_TO_ALL = TO_ALL
OFFICE_OBJECT_KEY = OKEY
TABLES
OBJCONT = OBJCONT
RECEIVERS = RECEIVERS
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
X_ERROR = 20
OTHERS = 21.
IF SY-SUBRC <> 0.
RAISE OTHERS.
ENDIF.
ENDFORM.
----
FORM INIT_REC *
----
FORM INIT_REC TABLES RECEIVERS STRUCTURE SOOS1.
CLEAR RECEIVERS.
REFRESH RECEIVERS.
MOVE SY-DATUM TO RECEIVERS-RCDAT .
MOVE SY-UZEIT TO RECEIVERS-RCTIM.
MOVE '1' TO RECEIVERS-SNDPRI.
MOVE 'X' TO RECEIVERS-SNDEX.
MOVE 'U-' TO RECEIVERS-RECNAM.
MOVE 'U' TO RECEIVERS-RECESC.
MOVE 'INT' TO RECEIVERS-SNDART.
MOVE '5' TO RECEIVERS-SORTCLASS.
APPEND RECEIVERS.
ENDFORM.
THANKS
MRUTYUN
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |