Skip to Content
avatar image
Former Member

Email Attachment format issues

Hi All,

I am using CL_BCS_DOCUMENT to send emails, as I need to send multiple attachments. Here is the code I am using.

vo_document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = it_message

i_subject = subject ).

CALL METHOD vo_document->add_attachment

EXPORTING

i_attachment_type = 'TXT'

i_attachment_subject = 'Input file'

i_att_content_text = it_data.

The issue is that the data in the attachment is not as formatted in the internal table. I think the data in the attachment is getting concatenated until 1024 chars are reached, and then spill over to the next line.

Suppose my internal table line size is 256 chars, then 4 lines will appear in the first line of the text attachment, and so on....

I want each line in the internal table to be a separate lines in the attachment.

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Aug 16, 2007 at 11:16 PM

    Please use SO_DOCUMENT_SEND_API1. Following is the working code

    &----


    *& Form f_send_file_as_email_attach

    &----


    *

    ----


    • -->PIT_MESSAGE Attached Message body for the emailing

    • -->PIT_ATTACH Attached Excel data file for emailing

    • -->P_EMAIL Email Address

    • -->P_MTITLE Subject of the Email

    • -->P_FORMAT Format of the attachment

    • -->P_FILENAME Name of the attached file

    • -->P_ATTDESCRIPTION Description of the attached file

    • -->P_SENDER_ADDRESS Senders Email Address

    • -->P_SENDER_ADDRES_TYPE Sender Email Type

    • -->P_ERROR Return Errors if any

    ----


    FORM f_send_file_as_email_attach tables pit_message

    pit_attach

    using p_email

    p_mtitle

    p_format

    p_filename

    p_attdescription

    p_sender_address

    p_sender_addres_type

    changing p_error.

    DATA: ld_error TYPE sy-subrc,

    ld_reciever TYPE sy-subrc,

    ld_mtitle LIKE sodocchgi1-obj_descr,

    ld_email LIKE somlreci1-receiver,

    ld_format TYPE so_obj_tp ,

    ld_attdescription TYPE so_obj_nam ,

    ld_attfilename TYPE so_obj_des ,

    ld_sender_address LIKE soextreci1-receiver,

    ld_sender_address_type LIKE soextreci1-adr_typ,

    ld_receiver LIKE sy-subrc.

    ld_email = p_email.

    ld_mtitle = p_mtitle.

    ld_format = p_format.

    ld_attdescription = p_attdescription.

    ld_attfilename = p_filename.

    ld_sender_address = p_sender_address.

    ld_sender_address_type = p_sender_addres_type.

    • Fill the document data.

    g_wa_doc_data-doc_size = 1.

    • Populate the subject/generic message attributes

    g_wa_doc_data-obj_langu = sy-langu.

    g_wa_doc_data-obj_name = 'SAPRPT'.

    g_wa_doc_data-obj_descr = ld_mtitle .

    g_wa_doc_data-sensitivty = 'F'.

    • Fill the document data and get size of attachment

    CLEAR g_wa_doc_data.

    READ TABLE g_i_attach INDEX g_cnt.

    g_wa_doc_data-doc_size =

    ( g_cnt - 1 ) * 255 + STRLEN( g_i_attach ).

    g_wa_doc_data-obj_langu = sy-langu.

    g_wa_doc_data-obj_name = 'SAPRPT'.

    g_wa_doc_data-obj_descr = ld_mtitle.

    g_wa_doc_data-sensitivty = 'F'.

    CLEAR g_i_attachment.

    REFRESH g_i_attachment.

    g_i_attachment[] = pit_attach[].

    • Describe the body of the message

    CLEAR g_i_packing_list.

    REFRESH g_i_packing_list.

    g_i_packing_list-transf_bin = space.

    g_i_packing_list-head_start = 1.

    g_i_packing_list-head_num = 0.

    g_i_packing_list-body_start = 1.

    • g_i_packing_list-obj_name = ld_attfilename.

    DESCRIBE TABLE g_i_message LINES g_i_packing_list-body_num.

    g_i_packing_list-doc_type = 'RAW'.

    APPEND g_i_packing_list.

    • Create attachment notification

    g_i_packing_list-transf_bin = 'X'.

    g_i_packing_list-head_start = 1.

    g_i_packing_list-head_num = 1.

    g_i_packing_list-body_start = 1.

    DESCRIBE TABLE g_i_attachment LINES g_i_packing_list-body_num.

    g_i_packing_list-doc_type = ld_format.

    g_i_packing_list-obj_descr = ld_attdescription.

    g_i_packing_list-obj_name = ld_attfilename.

    g_i_packing_list-doc_size = g_i_packing_list-body_num * 255.

    APPEND g_i_packing_list.

    • Add the recipients email address

    CLEAR g_i_receivers.

    REFRESH g_i_receivers.

    g_i_receivers-receiver = ld_email.

    g_i_receivers-rec_type = 'U'.

    g_i_receivers-com_type = 'INT'.

    g_i_receivers-notif_del = 'X'.

    g_i_receivers-notif_ndel = 'X'.

    APPEND g_i_receivers.

    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

    EXPORTING

    document_data = g_wa_doc_data

    put_in_outbox = 'X'

    sender_address = ld_sender_address

    sender_address_type = ld_sender_address_type

    commit_work = 'X'

    IMPORTING

    sent_to_all = g_sent_all

    TABLES

    packing_list = g_i_packing_list

    contents_bin = g_i_attachment

    contents_txt = g_i_message

    receivers = g_i_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.

    • Populate zerror return code

    ld_error = sy-subrc.

    • Populate zreceiver return code

    LOOP AT g_i_receivers.

    ld_receiver = g_i_receivers-retrn_code.

    ENDLOOP.

    ENDFORM. "f_send_file_as_email_attach

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 16, 2007 at 11:35 PM

    The requirement is to send multiple file attachments in a single mail. That why I am using the class CL_BCS_DOCUMENT.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 16, 2007 at 11:41 PM

    Hi Uday,

    USe CL_ABAP_CHAR_UTILITIES=>CR_LF at the end of each line in internal table.

    Regards,

    Atish

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 17, 2007 at 02:43 AM

    I tried putting CL_ABAP_CHAR_UTILITIES=>CR_LF, the output looks fine in SOST. But in actual mail, it still the same.

    Add comment
    10|10000 characters needed characters exceeded