Skip to Content
author's profile photo Former Member
Former Member

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

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


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



document_data = fp_wa_docdata

put_in_outbox = c_x

commit_work = c_x





packing_list = fp_i_objpack

object_header = l_i_objhead

contents_bin = fp_i_final1

contents_txt = fp_i_message




receivers = fp_i_reclist


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



CLEAR fp_v_subrc.

fp_v_subrc = sy-subrc.

CASE fp_v_subrc.



ENDFORM. "send_file_as_email_attachment

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 14, 2005 at 11:31 AM


    Try out this sample code:



    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 14, 2005 at 11:49 AM


    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 14, 2005 at 03:41 PM

    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.



    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.