Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Send email with an attachment

Former Member
0 Kudos
128

Hello Experts

I have created one ALV report.

Now, my requirement is that

1. While selecting one checkbox (Send e-mail), I want to send e-mail while running this report in background.

2. Report should be Excel or text as an attachment of e-mail

Can we do that?

Points will be awarder immediately.

Regards

n.master

1 ACCEPTED SOLUTION

Former Member
0 Kudos
70

Hi,

Please use the function modules SO_DOCUMENT_SEND_API1 or SO_NEW_DOCUMENT_ATT_SEND_API1

I have used this in RFC calls. Thus I think u can send mails by using this function module in background.

Regs,

Saurabh

6 REPLIES 6

Former Member
0 Kudos
71

Hi,

Please use the function modules SO_DOCUMENT_SEND_API1 or SO_NEW_DOCUMENT_ATT_SEND_API1

I have used this in RFC calls. Thus I think u can send mails by using this function module in background.

Regs,

Saurabh

Former Member
0 Kudos
70

Hi

The code below will send the mail with PDF attachment.. you can modify the same for your txt format too..

but PDF is preffered as it is better in its look and feel..

&----


*& Form Spool_to_mail

&----


  • Getting the Spool number and the file in pdf format to given

  • EmailID

----


  • email----> Email id

  • SPOOL----> Spool No

----


FORM spool_to_mail USING p_email TYPE char255

p_spool TYPE sy-spono.

DATA: lv_arcpar TYPE arc_params,

lv_print_parms TYPE pri_params,

lv_bytecount TYPE i,

lv_rqident TYPE tsp01-rqident,

lv_mi_rqident TYPE tsp01-rqident,

lv_text TYPE pri_params-prtxt. "List Text

DATA: lv_gd_buffer TYPE string.

DATA : lt_mess_att TYPE STANDARD TABLE OF solisti1,

lt_mtab_pdf TYPE STANDARD TABLE OF tline,

lt_objpack TYPE STANDARD TABLE OF sopcklsti1,

lt_objtxt TYPE STANDARD TABLE OF solisti1,

lt_objbin TYPE STANDARD TABLE OF solisti1,

lt_reclist TYPE STANDARD TABLE OF somlreci1,

lt_doc_chng TYPE sodocchgi1,

lt_objhead TYPE soli_tab,

lv_l_attachment TYPE i,

lv_l_testo TYPE i.

DATA: lwa_mtab_pdf TYPE tline,

lwa_objpack TYPE sopcklsti1,

lwa_mess_att TYPE solisti1,

lwa_objtxt TYPE solisti1,

lwa_objbin TYPE solisti1,

lwa_reclist TYPE somlreci1.

DATA : lv_val(1).

CONSTANTS : lc_lines TYPE pri_params-linct VALUE 65, "Line count

lc_rows TYPE pri_params-linsz VALUE 255, "Rows

lc_temp_print_paart TYPE pri_params-paart VALUE

'X_65_255'.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

no_dialog = 'X'

IMPORTING

out_parameters = lv_print_parms

out_archive_parameters = lv_arcpar

valid = lv_val

EXCEPTIONS

archive_info_not_found = 1

invalid_print_params = 2

invalid_archive_params = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

lv_print_parms-paart = lc_temp_print_paart.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

in_archive_parameters = lv_arcpar

in_parameters = lv_print_parms

layout = 'X_65_255'

line_count = lc_lines

line_size = lc_rows

list_text = lv_text

no_dialog = 'X'

IMPORTING

out_archive_parameters = lv_arcpar

out_parameters = lv_print_parms

valid = lv_val

EXCEPTIONS

archive_info_not_found = 1

invalid_print_params = 2

invalid_archive_params = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

lv_mi_rqident = p_spool.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = lv_mi_rqident

no_dialog = 'X'

dst_device = lv_print_parms-pdest

IMPORTING

pdf_bytecount = lv_bytecount

pdf_spoolid = lv_rqident

TABLES

pdf = lt_mtab_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.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

LOOP AT lt_mtab_pdf INTO lwa_mtab_pdf.

TRANSLATE lwa_mtab_pdf USING ' ~'.

CONCATENATE lv_gd_buffer lwa_mtab_pdf INTO lv_gd_buffer.

CLEAR lwa_mtab_pdf.

ENDLOOP.

TRANSLATE lv_gd_buffer USING '~ '.

DO.

lwa_mess_att = lv_gd_buffer.

APPEND lwa_mess_att TO lt_mess_att.

CLEAR lwa_mess_att.

SHIFT lv_gd_buffer LEFT BY 255 PLACES.

IF lv_gd_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

CLEAR: lwa_reclist, lt_reclist[],

lt_objhead, lt_objhead[],

lwa_objtxt, lt_objtxt[],

lwa_objbin, lt_objbin[],

lwa_objpack, lt_objpack[].

  • Object with PDF.

" CLEAR LT_OBJBIN.

REFRESH lt_objbin.

lt_objbin[] = lt_mess_att[].

DESCRIBE TABLE lt_objbin LINES lv_l_attachment.

  • Object with main text of the mail.

lwa_objtxt = ''.

APPEND lwa_objtxt TO lt_objtxt.

CLEAR lwa_objtxt.

DESCRIBE TABLE lt_objtxt LINES lv_l_testo.

  • Document information.

lt_doc_chng-obj_name = 'STATUS_REPORT'.

lt_doc_chng-expiry_dat = sy-datum + 10.

lt_doc_chng-obj_descr = 'Generated File'. "#EC NOTEXT

lt_doc_chng-sensitivty = 'F'.

lt_doc_chng-sensitivty = 'O'.

lt_doc_chng-obj_prio = '1'.

lt_doc_chng-doc_size = lv_l_testo * 255.

  • Pack to main body.

CLEAR lwa_objpack-transf_bin.

lwa_objpack-head_start = 1.

lwa_objpack-head_num = 0.

lwa_objpack-body_start = 1.

lwa_objpack-body_num = lv_l_testo.

lwa_objpack-doc_type = 'RAW'.

APPEND lwa_objpack TO lt_objpack.

CLEAR lwa_objpack.

  • Pack to PDF.

lwa_objpack-transf_bin = 'X' .

lwa_objpack-head_start = 1.

lwa_objpack-head_num = 1.

lwa_objpack-body_start = 1.

lwa_objpack-body_num = lv_l_attachment.

lwa_objpack-doc_type = 'PDF'.

lwa_objpack-obj_name ='SPOOL'.

lwa_objpack-obj_descr = 'Generated File details'. "#EC NOTEXT

lwa_objpack-doc_size = lv_l_attachment * 255.

APPEND lwa_objpack TO lt_objpack.

CLEAR lwa_objpack.

CLEAR lwa_reclist.

lwa_reclist-copy = 'X'.

  • e-mail receivers.

lwa_reclist-receiver = p_email.

lwa_reclist-rec_type = 'U'.

lwa_reclist-notif_del = 'X'.

lwa_reclist-notif_ndel = 'X'.

APPEND lwa_reclist TO lt_reclist.

  • funcion module for sending email.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lt_doc_chng

put_in_outbox = ' '

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.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

REFRESH : lt_objpack, lt_objhead, lt_objbin, lt_objtxt,

lt_reclist.

ENDFORM. "Spool_to_mail

0 Kudos
70

I have solved this question.

0 Kudos
70

Hi Nimesh

Let us know if you have solved the problem in a diffeernet way than the one we discussed.

-

Santosh

0 Kudos
70

Hi santosh,

I have used same logic but made slight diffrence for EXCEL file.

but now problem is that i cant stay with more than 255 character in message body where as my req. is to display selection screen details in the body of the mail.