07-23-2006 12:55 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......
- Why not directly execute the call transformation to an xstring instead of a normal string?
- 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.
07-23-2006 1:18 PM
so i guess the data type of output is string.
is there anything special about the itab passed to call transformation?
as per the documentation the variable for xmloutput can be
<i>Data object of type string and xstring or as a standard table with flat character-type row type,</i>
but i have never tried using other than string.
- Any suggestions on what might create this unknown character?
may be encoding in causing this - try the option without encoding in call transformation.
let me understand your complete requirement.
you want to read data from some DB table , convert it to XML and email the same as attchment - is that right? confirm this i will post a complete sample code.
for emailing, i use CL_bcs class. you can refer the following code sample for this
Regards
Raja
07-23-2006 1:18 PM
so i guess the data type of output is string.
is there anything special about the itab passed to call transformation?
as per the documentation the variable for xmloutput can be
<i>Data object of type string and xstring or as a standard table with flat character-type row type,</i>
but i have never tried using other than string.
- Any suggestions on what might create this unknown character?
may be encoding in causing this - try the option without encoding in call transformation.
let me understand your complete requirement.
you want to read data from some DB table , convert it to XML and email the same as attchment - is that right? confirm this i will post a complete sample code.
for emailing, i use CL_bcs class. you can refer the following code sample for this
Regards
Raja
07-23-2006 1:57 PM
The itab which i pass is the sflight internal table filled with values from the sflight db table.
I guess when u use the xstring type in the transformation function no conversion from string to xstring is necsesary anymore.
i believe i do not use encoding?
"you want to read data from some DB table , convert it to XML and email the same as attchment - is that right? confirm this i will post a complete sample code."
Please do post a complete sample.
Thnx for your fast replies!
Regards,
Martijn.
07-24-2006 10:08 AM
here is the code sample.
REPORT ymailxml
NO STANDARD PAGE HEADING.
DATA: ftab TYPE STANDARD TABLE OF sflight .
DATA: xml_out TYPE Xstring .
DATA: binary_content TYPE solix_tab.
DATA : text_tab TYPE soli_tab .
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 if_sender_bcs.
DATA: recipient TYPE REF TO if_recipient_bcs.
DATA: bcs_exception TYPE REF TO cx_bcs.
DATA: sent_to_all TYPE os_boolean.
DATA: conlength TYPE i ,
conlengths TYPE so_obj_len ,
result_content TYPE string .
DATA: content_length TYPE w3param-cont_len ,
content_type TYPE w3param-cont_type,
return_code TYPE w3param-ret_code .
DATA: bcs_message TYPE string .
CLEAR: ftab.
REFRESH: ftab .
PARAMETERS: send_id TYPE ad_smtpadr LOWER CASE OBLIGATORY DEFAULT 'sender@xyz.com',
rec_id TYPE ad_smtpadr LOWER CASE OBLIGATORY DEFAULT 'receiver@xyz.com' .
START-OF-SELECTION .
SELECT * UP TO 10 ROWS FROM sflight INTO TABLE ftab .
CALL TRANSFORMATION (`ID`)
SOURCE itab = ftab[]
RESULT XML xml_out.
REFRESH binary_content .
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = xml_out
TABLES
binary_tab = binary_content.
TRY.
CLEAR send_request .
send_request = cl_bcs=>create_persistent( ).
CLEAR document .
APPEND 'Test XML Message' TO text .
document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = text
i_subject = 'Test' ).
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'xml'
i_attachment_subject = 'TestXML'
i_att_content_hex = binary_content.
* add document to send request
CALL METHOD send_request->set_document( document ).
CLEAR sender .
sender = cl_cam_address_bcs=>create_internet_address( send_id ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
CLEAR recipient .
recipient = cl_cam_address_bcs=>create_internet_address(
rec_id ).
* add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
CALL METHOD send_request->set_status_attributes
EXPORTING
i_requested_status = 'E'
i_status_mail = 'E'.
CALL METHOD send_request->set_send_immediately( 'X' ).
* ---------- send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
IF sent_to_all = 'X'.
WRITE:/ 'Mail sent successfully ' .
ENDIF.
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
bcs_message = bcs_exception->get_text( ).
WRITE:/ bcs_message .
EXIT.
ENDTRY.
Regards
Raja
07-24-2006 1:47 PM
Thnx Raja,
Good to see that you tried the transformation directly in a Xstring.
I copied your source code example to a local program. everything works well, except that the XML-file which is created, contains errors when i open it. When i edit it, the only thing i can find is that the file ends with alot of spaces. When i remove these spaces, the XML can be displayed fine.
Do you get the same or have any idea on what to do?
Regards,
Martijn.
07-25-2006 6:16 AM
<i>Do you get the same or have any idea on what to do?</i>
Yes i get the same error which i havent noticed, when i open the xml from mail, it opened in a small ie window and the xml error is at the bottom which i failed to notice.
The fix suggested below, removes this error.
Just add the content length to add attachment method. it should be alright.
calculate the length.
clear conlengths .
conlengths = xstrlen( xml_out ) .
replace the code for adding attchment with the following code.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'xml'
i_attachment_subject = 'TestXML'
<b> I_ATTACHMENT_SIZE = conlengths</b>
i_att_content_hex = binary_content.
Regards
Raja
Reward points to helpful answers and mark the thread as answered once your question is answered.
07-25-2006 7:23 AM
Raja,
Great! Many many many thanks! I had looked for a method to calculate the length of the RAW binary content table, which i couldn't find, but didn't think that i could also use the length of the xstring!
You've been a great help, sorry that i can only reward you with 10 points!
Many regards!
Martijn.