Skip to Content
avatar image
Former Member

Error when emailing XML document

Hi there

I am trying to email an XML document to an external vendor by using the CL_DOCUMENT_BCS class. The email is sent successfully and I receive it in the relevant mailbox. To make it an XML document, I move 'XML' to the I_TYPE parameter of the class. This sends it perfectly as an XML document.

The problem occurs when I receive the email and open the attachment. When I open the attachment, I get the error "Whitespace is not allowed at this location". To rectify this problem, I open the XML attachment in notepad, concatenate these lines by deleting the return characters and I save the file and open it again. It then displays perfectly.

When I send the email as a normal text document and I change the extension manually to 'XML', the XML can be viewed perfectly.

Can anyone assist in rectifying this so that there is no manual intervention?

Kind Regards

Gustav Coleske

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 13, 2006 at 06:42 AM

    Raja

    I tried using the add attachment method and it still has the same problem. I will just send this as a text document and ask the external system owner to change the extension on the file to .XML.

    Thanks for your help.

    Kind Regards

    Gustav

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 12, 2006 at 08:47 AM

    Raja

    The code is as follows:

    FORM send_data_via_email .

    *

    DATA: new_object_id LIKE sofolenti1-object_id,

    l_idx LIKE sy-tabix.

    *

    • All activities done via facade CL_BCS!

    DATA: send_request TYPE REF TO cl_bcs.

    DATA: text TYPE bcsy_text.

    DATA: document TYPE REF TO cl_document_bcs.

    DATA: sender TYPE REF TO cl_sapuser_bcs.

    DATA: recipient TYPE REF TO if_recipient_bcs.

    DATA: bcs_exception TYPE REF TO cx_bcs.

    DATA: lt_contents TYPE TABLE OF soli.

    DATA: lt_contents2 TYPE TABLE OF solix.

    DATA: lv_subject TYPE sood-objdes VALUE 'Rental Units'.

    DATA: lv_length TYPE i.

    DATA: lv_receiver_email_address TYPE adr6-smtp_addr.

    DATA: lv_string TYPE string.

    *

    • Select the record for email address to send to off parameter table

    SELECT SINGLE value FROM zca_partr INTO gs_real_recipients-receiver

    WHERE progid = sy-repid

    AND id = 'OUT_EMAIL'.

    *

    APPEND gs_real_recipients TO gt_real_recipients.

    CLEAR gs_real_recipients.

    *

    CLEAR new_object_id.

    gv_items_sent = 'X'.

    *

    • Send back non-delivery and delivery reports.

    LOOP AT gt_real_recipients INTO gs_real_recipients.

    *

    gs_real_recipients-notif_del = 'X'.

    gs_real_recipients-notif_ndel = 'X'.

    *

    gs_real_recipients-express = gv_express.

    *

    MODIFY gt_real_recipients FROM gs_real_recipients.

    *

    ENDLOOP.

    *

    gt_contents[] = gt_xml_out[].

    *

    • Set the subject of the email

    lv_subject = 'Rental Units for rent'.

    gs_packing_list-mail_subject = lv_subject.

    gs_packing_list-doc_type = 'XML'.

    *

    TRY.

    • Create persistent send request

    send_request = cl_bcs=>create_persistent( ).

    *

    • Create and set document

    • Create document from internal table with lt_content

    *

    lt_contents[] = gt_contents[].

    *

    DESCRIBE TABLE lt_contents[] LINES lv_length.

    *

    gs_packing_list-doc_size = lv_length * 255.

    *

    document = cl_document_bcs=>create_document(

    i_type = gs_packing_list-doc_type

    i_text = lt_contents

    i_length = gs_packing_list-doc_size

    i_subject = lv_subject

    i_language = sy-langu

    ).

    *

    • Set the subject for the sending of mails.

    *

    lv_string = gs_packing_list-mail_subject.

    *

    TRY .

    *

    CALL METHOD send_request->set_message_subject

    EXPORTING

    ip_subject = lv_string.

    *

    CATCH cx_sy_dyn_call_illegal_method .

    *

    ENDTRY.

    *

    • Add document to send request

    *

    CALL METHOD send_request->set_document( document ).

    *

    • Do send delivery info for successful mails

    *

    CALL METHOD send_request->set_status_attributes

    EXPORTING

    i_requested_status = 'E'

    i_status_mail = 'A'.

    *

    • Set sender

    *

    sender = cl_sapuser_bcs=>create( sy-uname ).

    *

    CALL METHOD send_request->set_sender

    EXPORTING

    i_sender = sender.

    *

    • Add recipients (e-mail addresses)

    *

    LOOP AT gt_real_recipients INTO gs_real_recipients.

    *

    • Create recipient

    *

    lv_receiver_email_address = gs_real_recipients-receiver.

    CHECK lv_receiver_email_address IS NOT INITIAL.

    recipient = cl_cam_address_bcs=>create_internet_address(

    lv_receiver_email_address ).

    *

    • Add recipient with its respective attributes to send request

    *

    CALL METHOD send_request->add_recipient

    EXPORTING

    i_recipient = recipient

    i_express = 'X'

    i_blind_copy = gs_real_recipients-blind_copy.

    ENDLOOP.

    *

    • Send document

    *

    CALL METHOD send_request->send(

    EXPORTING

    i_with_error_screen = 'X'

    RECEIVING

    result = gv_sent_to_all ).

    *

    • Exception handling

    *

    CATCH cx_bcs INTO bcs_exception.

    WRITE: text-001 , bcs_exception->error_type.

    EXIT.

    *

    ENDTRY.

    *

    COMMIT WORK.

    *

    *

    ENDFORM. " send_data_via_email

    I am not using the add_attachment method as the normal document create automatically creates the attachment. Would using this method be critical?

    Kind Regards

    Gustav

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 11, 2006 at 12:25 PM

    can you post the code how you are generating xml and how the generated xml is converted to table (the one used with add_attachment method).

    Regards

    Raja

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 11, 2006 at 12:38 PM

    Hi Raja

    I used the following code:

    CALL TRANSFORMATION (`ID`)

    SOURCE itab = gt_sap_to_eprop[]

    RESULT XML gt_xml_out.

    Kind Regards

    Gustav

    Add comment
    10|10000 characters needed characters exceeded

    • gt_xml_out will be in string format and how you are converting it to binary format to attach (the problem could be here) or you are attaching as text.

      i need to see your code for

      CALL METHOD document->add_attachment

      EXPORTING

      i_attachment_type = 'XML'

      i_attachment_subject = atta_sub

      i_att_content_hex = binary_content.

      and the data declration for the variables used in this method and how they are filled.

      Regards

      Raja

      Reward points to helpful answers by choosing the appropriate radiobutton next to the answers