04-11-2006 9:50 AM
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
04-13-2006 7: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
04-11-2006 1: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
04-11-2006 1: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
04-12-2006 7:41 AM
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
04-12-2006 9: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
04-12-2006 3:01 PM
I guess its better to use add_attachment method to send attachments.
Regards
Raja
04-13-2006 7: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
04-15-2006 7:54 AM
i tried and its working, here is the code sample.
DATA: binary_content TYPE solix_tab.
DATA: xl_content TYPE xstring ,
output TYPE string .
DATA: flights TYPE flighttab .
CALL TRANSFORMATION (`ID`)
SOURCE flights = flights[]
RESULT XML output.
CLEAR: xl_content .
* xl_content = output .
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = output
* MIMETYPE = ' '
* ENCODING =
IMPORTING
buffer = xl_content
EXCEPTIONS
failed = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
REFRESH binary_content .
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = xl_content
TABLES
binary_tab = binary_content.
now add the attachment.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'XML'
i_attachment_subject = atta_sub
i_att_content_hex = binary_content.
Regards
Raja
06-22-2006 10:04 AM
Hi Raja,
I create XMX xstring in ABAB program and I would like this XML as attachment file via e-mail. I try use your examples and still don't work.
Thanks for your help.
King Regards
Pavel
06-22-2006 10:39 AM
Welcome to SDN.
Open it as a new thread and post your code, i will try and correct it.
Regards
Raja
07-23-2006 12:07 PM
Hi Raja,
I copied your code to a test program, but when i execute the "Call transformation" the generated string (output) contains an unknown character which causes the function module 'SCMS_STRING_TO_XSTRING' to raise an error(unknown character).
When i debug the program i see that the first character of the 'output'-string is a square. When i delete this first charcter, everything goes well......
Any suggestions on what might create this unknown character?
Any change you could post the rest of your code as a sample? So an example of the way you fill the rest of the document-object and which function you use to send the e-mail?
Kind regards,
Martijn de Jong.
Message was edited by: M. de Jong
07-23-2006 12:35 PM
whats the type of the variable which is holding the resulting xml string?
Can you open a new thread and post your code there, i will check and see whats the error.
Regards
Raja
07-23-2006 12:59 PM
Hi Raja,
I opened a new topic. I copied your code exactly, so type definitions are the same.
Regards,
Martijn.