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: 

Re: Need to send email with excel sheet as attachment: URGENT

Former Member
0 Kudos

Hi All,

Thanks for all your replies.,i have one more issue pending while sending mails. My program is sending a mail to the receiver with XLS as

attachment. But when i try to open the attachment, i get a Dialog Box with the following message

"The file is not in a recognizable format.

1. if you know the file is from another program whih is incompatible with Microsoft excel,click cancel,then open this file in its original

application

2.If you suspect the file is damaged, click help for more information about solving theproblem.

3.if you still want to see what text is contained in the file, click OK.Then click the text import wizard. "

when i click OK, the excel sheet is opening with all required data.

Can anyone kindly tell me why this is happening.

I am also attaching part of the coding related to this requirement.

Kindly reply me where i am doing mistake at the earliest possibletime

Thanks in advance,

C Nanda

************************************************************************

FORM send_file_as_email_attachment USING value(fp_wa_docdata) TYPE ty_docdata

fp_mailid TYPE so_recname

fp_mtitle TYPE so_obj_des

fp_format TYPE so_obj_tp

fp_i_message TYPE ty_message_tab

fp_i_final1 TYPE ty_t_final1

CHANGING fp_i_objpack TYPE ty_objpack_tab

fp_i_reclist TYPE ty_reclist_tab

fp_v_subrc TYPE sysubrc.

  • local variable declaration

DATA: l_v_mtitle LIKE sodocchgi1-obj_descr, "subject for the mail

l_v_email LIKE somlreci1-receiver, " emailid

l_v_format TYPE so_obj_tp , " document type

l_v_tab_lines1 TYPE i. " counter

  • local constants declaration.

CONSTANTS: l_c_u TYPE so_escape VALUE 'U'.

  • local work area declaration

DATA: l_wa_message TYPE ty_message,

l_i_objhead TYPE STANDARD TABLE OF ty_message,

l_wa_objhead TYPE ty_message, " workarea for object header

l_wa_reclist TYPE ty_reclist, " work area for the receivers

l_wa_objpack TYPE ty_objpack. " work area for packing list

l_v_email = fp_mailid. " mail id of the receiver

l_v_mtitle = fp_mtitle. " title of the mail

l_v_format = fp_format. " document type (XLS in this case)

  • Fill the document data and get size of attachment

CLEAR fp_wa_docdata.

    • Fill the document data.

DESCRIBE TABLE fp_i_message LINES l_v_tab_lines1.

READ TABLE fp_i_message INTO l_wa_message INDEX l_v_tab_lines1.

IF sy-subrc EQ c_s_0.

fp_wa_docdata-doc_size = ( l_v_tab_lines1 - c_1 ) * c_255 + STRLEN( l_wa_message ).

  • Populate the subject/generic message attributes

fp_wa_docdata-obj_langu = sy-langu.

fp_wa_docdata-obj_name = text-020. " Report

fp_wa_docdata-obj_descr = l_v_mtitle .

  • create the entry for the compressed document.

  • Describe the body of the message

CLEAR fp_i_objpack.

REFRESH fp_i_objpack.

  • Donot transfer the contents to BIN

l_wa_objpack-transf_bin = c_space.

  • Start of header

l_wa_objpack-head_start = c_1.

  • Size of header

l_wa_objpack-head_num = c_0.

  • Start of the attchment

l_wa_objpack-body_start = c_1.

  • Size of attachment

l_wa_objpack-body_num = l_v_tab_lines1.

  • Attachment Type

l_wa_objpack-doc_type = c_raw.

  • Append the work area to internal table

APPEND l_wa_objpack TO fp_i_objpack.

  • Create attachment notification

  • Donot transfer the contents to BIN

l_wa_objpack-transf_bin = c_x.

l_wa_objpack-head_start = c_1.

l_wa_objpack-head_num = c_1.

l_wa_objpack-body_start = c_1.

DESCRIBE TABLE fp_i_final1 LINES l_wa_objpack-body_num.

l_wa_objpack-doc_type = l_v_format.

l_wa_objpack-doc_size = l_wa_objpack-body_num * c_255.

APPEND l_wa_objpack TO fp_i_objpack.

  • fill the recipients mail address.

*clear and refresh the internal table

CLEAR fp_i_reclist.

REFRESH fp_i_reclist.

l_wa_reclist-receiver = l_v_email.

l_wa_reclist-rec_type = l_c_u. " for internet address

l_wa_reclist-com_type = c_int.

l_wa_reclist-notif_del = c_x.

l_wa_reclist-notif_ndel = c_x.

APPEND l_wa_reclist TO fp_i_reclist.

l_wa_objhead = text-014.

APPEND l_wa_objhead TO l_i_objhead.

  • function module that sends the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = fp_wa_docdata

put_in_outbox = c_x

commit_work = c_x

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = fp_i_objpack

object_header = l_i_objhead

contents_bin = fp_i_final1

contents_txt = fp_i_message

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = fp_i_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

.

CLEAR fp_v_subrc.

fp_v_subrc = sy-subrc.

CASE fp_v_subrc.

ENDCASE.

ENDIF.

ENDFORM. "send_file_as_email_attachment

3 REPLIES 3

Former Member
0 Kudos

Hi,

Try out this sample code:

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

Regards,

Anjali

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Just check the sy-subrc value after the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

And check whether all the parameters are passed correctly in debugging mode.

Former Member
0 Kudos

Hi Jayanthi,

I handled sy-subrc and its returning 0 only, every thing looks fine when i debug also.

The thing is i am getting the xls file with required records through mail as attachment, but i am not sure y i m getting a dialog box befor opening the XLS attachment.

Anjali: I have tried this link tooo..but itz not solving my problem.

To all: will be thankful if any one can help me in fixing the problem.

Thanks,

Nanda