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: 

How to send an ALV report as an attachment to outside mail id

Former Member
0 Kudos

Hi all,

I have developed a report now my requirement is to send this report as an attachment to ouside email id, How can i achieve it. Please suggest.

Thanks,

Anup.

8 REPLIES 8

Former Member
0 Kudos

Hi,

Please chk this site, u have sample codes for your requirement.

http://www.sapdevelopment.co.uk/reporting/email/attachhome.htm

http://www.sapgenie.com/abap/code/abap31.htm

Regards,

Anjali

Former Member
0 Kudos

Hi,

Please take a look at these two weblogs from Thomas Jung:

1. /people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface, for 46D and lower

2. /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface, for 610 and higher

Regards

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

You need to make the rec_type = 'U' for sending mail to external id.

Check this link for code sample.

http://www.sap-img.com/fu016.htm

0 Kudos

This message was moderated.

Former Member
0 Kudos

Check following programs:

RSWUWFML

or

RSSOAPIS

or

RSRRRS01

or

RFASSIGNAR.

regards.

Former Member
0 Kudos

Hi Anjali,

Thanks for ur help. But when i run the code in the output list it says that you did not select the object. can u help.

Thnaks,

Annup.

0 Kudos

Hi,

Here is a code sample to send a mail with attachment:

http://www.sapdevelopment.co.uk/reporting/email/attach_xlsmod.htm


* This is a small code with mail without attachment.
* Just confirm me if this is working for you.
REPORT  zsendemail                    .

PARAMETERS: psubject(40) type c default  'Testing',
            p_email(40)   type c default 'anjalidevi@engineer.com'.  "use ur email id

data:   it_packing_list like sopcklsti1 occurs 0 with header line,
        it_contents like solisti1 occurs 0 with header line,
        it_receivers like somlreci1 occurs 0 with header line,
        it_attachment like solisti1 occurs 0 with header line,
        gd_cnt type i,
        gd_sent_all(1) type c,
        gd_doc_data like sodocchgi1,
        gd_error type sy-subrc.

data:   it_message type standard table of SOLISTI1 initial size 0
                with header line.

***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

Perform populate_message_table.

*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)
perform initiate_mail_execute_program.


*&---------------------------------------------------------------------*
*&      Form  POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------*
*       Adds text to email text table
*----------------------------------------------------------------------*
form populate_message_table.
  Append 'Line1' to it_message.
  Append 'Line2' to it_message.
  Append 'Line3' to it_message.
  Append 'Test- 1' to it_message.
endform.                    " POPULATE_MESSAGE_TABLE


*&---------------------------------------------------------------------*
*&      Form  SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
*       Send email message
*----------------------------------------------------------------------*
form send_email_message.
* Fill the document data.
  gd_doc_data-doc_size = 1.
*  DATA: TAB_LINES LIKE sy-tabix.
*
*  DESCRIBE TABLE it_message LINES TAB_LINES.
*  READ TABLE it_message INDEX TAB_LINES.
*  gd_doc_data-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( it_message )
*.

* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  gd_doc_data-obj_name  = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject.
  gd_doc_data-sensitivty = 'F'.

* Describe the body of the message
* Information about structure of data tables
  clear it_packing_list.
  refresh it_packing_list.
  it_packing_list-transf_bin = space.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 0.
  it_packing_list-body_start = 1.
  describe table it_message lines it_packing_list-body_num.
  it_packing_list-doc_type = 'RAW'.
  append it_packing_list.

* Add the recipients email address
  clear it_receivers.
  refresh it_receivers.
  it_receivers-receiver = p_email.
  it_receivers-rec_type = 'U'.
*  it_receivers-com_type = 'INT'.
*  it_receivers-notif_del = 'X'.
*  it_receivers-notif_ndel = 'X'.
  append it_receivers.

* Call the FM to post the message to SAPMAIL
  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
       exporting
            document_data              = gd_doc_data
            put_in_outbox              = 'X'
       importing
            sent_to_all                = gd_sent_all
       tables
            packing_list               = it_packing_list
            contents_txt               = it_message
            receivers                  = it_receivers
       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.

* Store function module return code
  gd_error = sy-subrc.

* Get it_receivers return code
  loop at it_receivers.
  endloop.
endform.                    " SEND_EMAIL_MESSAGE


*&---------------------------------------------------------------------
*&      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'
                    and return.
  endif.
endform.                    " INITIATE_MAIL_EXECUTE_PROGRAM

If a problem exists in this, Check out:

http://www.sapdevelopment.co.uk/reporting/email/email_sendproc.htm

Please let me know if this is working for you.

Regards,

Anjali

0 Kudos

Hi Anjali,

actually my requirement is to send an (excel sheet ) email to the concerned vendor email address when the user select the checkbox at the alv output.

with ur logic here iam able to send ( excel sheet ) to the vendor address but my problem is when iam selecting more than 1 row at the alv output for a particular vendor, all records are displaying in excel sheet in a single row instead of display in a different row. Ex: when iam selecting 3 row all the 3 row are displaying in a single row in the excel sheet instead of displaying 3 rows.

here iam using the tables: ekko,ekpo,ekbe,eket.

Please do needful help.

Thanks in advance.

Regards,

Aditya.