2013 Aug 20 7:45 AM
Hi All.
String is truncated after special character “&” .
I am passing string from ABAP to outlook page.Contents are change into HTML format and displayed in outlook's mail body. If string contains special character “&”,getting problem.
Eg:Lv_string = ‘Production & Industrial plan’.
Expected output is “Production & Industrial plan” in HTML.
Current output is “Production “.
Issue: String is truncated after special character “&”.
I have no issues if string contains no “&”.
Could you please help me to resolve this issue?
Thanks.
NJ.
2013 Aug 20 7:54 AM
Hi Nagaraj,
Use and instead of '&'.
it will works
Pass values like this
<html>
<body>
<p>Production & Industrial plan</p>
</body>
</html>
2013 Aug 20 8:55 AM
Hi.
Thanks for your reply.
But i could not change string "&" to "and" because need to display what user is giving in abap.
Regards.
NJ
2013 Aug 20 10:28 AM
Hi Ramesh.
Checked your code.in code
loop at it_final into wa_final.
...
concatenate '<td>' wa_final-carrid '</td>' into wa_objtxt-line.
append wa_objtxt to t_objtxt.
.....
endloop.
Eg: at run time, if wa_final-carrid = 'Test & co' in above code. Is It will work?..Could you check and tell me Please.
Regards.
Nagarajan Jayaraman.
2013 Aug 20 10:58 AM
I tried like this way also i am getting &
*start-of-selection.
DATA:
t_objbin TYPE STANDARD TABLE OF solisti1, " Attachment data
t_objtxt TYPE STANDARD TABLE OF solisti1, " Message body
t_objpack TYPE STANDARD TABLE OF sopcklsti1, " Packing list
t_reclist TYPE STANDARD TABLE OF somlreci1, " Receipient list
t_objhead TYPE STANDARD TABLE OF solisti1. " Header
DATA: wa_docdata TYPE sodocchgi1, " Document data
wa_objtxt TYPE solisti1, " Message body
wa_objbin TYPE solisti1, " Attachment data
wa_objpack TYPE sopcklsti1, " Packing list
wa_reclist TYPE somlreci1. " Receipient list
DATA: w_tab_lines TYPE i. " Table lines
TYPES : BEGIN OF ty_sflight,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
price TYPE sflight-price,
currency TYPE sflight-currency,
planetype TYPE sflight-planetype,
END OF ty_sflight.
TYPES : BEGIN OF ty_final,
carrid(3) TYPE c,
connid(4) TYPE c,
fldate(8) TYPE c,
price(17) TYPE c,
currency(5) TYPE c,
planetype(10) TYPE c,
testfield(30) TYPE c,
END OF ty_final.
DATA : it_sflight TYPE TABLE OF ty_sflight,
wa_sflight TYPE ty_sflight.
DATA : it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
* Start-of-selection
START-OF-SELECTION.
SELECT carrid
connid
fldate
price
currency
planetype
FROM sflight INTO TABLE it_sflight UP TO 10 ROWS.
LOOP AT it_sflight INTO wa_sflight.
wa_final-carrid = wa_sflight-carrid.
wa_final-connid = wa_sflight-connid.
wa_final-fldate = wa_sflight-fldate.
wa_final-price = wa_sflight-price.
wa_final-currency = wa_sflight-currency.
wa_final-planetype = wa_sflight-planetype.
wa_final-testfield = 'Production & Industrial plan'.
APPEND wa_final TO it_final.
CLEAR wa_final.
ENDLOOP.
* Creating message
PERFORM create_message.
* Sending Message
PERFORM send_message.
*&---------------------------------------------------------------------*
*& Form create_message
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM create_message .
**1 Title, Description & Body
PERFORM create_title_desc_body.
**2 Receivers
PERFORM fill_receivers.
ENDFORM. " create_message
*&---------------------------------------------------------------------*
*& Form CREATE_TITLE_DESC_BODY
*&---------------------------------------------------------------------*
* Title, Description and body
*----------------------------------------------------------------------*
FORM create_title_desc_body.
*...Title
wa_docdata-obj_name = 'Email notification'.
*...Description
wa_docdata-obj_descr = 'Email body in HTML'.
*...Message Body in HMTL
wa_objtxt-line = '<html> <body style="background-color:#FFE4C4;">'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = '<p> List of Test materials </p>'.
APPEND wa_objtxt TO t_objtxt.
* table display
wa_objtxt-line = '<table style="MARGIN: 10px" bordercolor="#90EE90" '.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = ' cellspacing="0" cellpadding="3" width="400"'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = ' border="1"><tbody><tr>'.
APPEND wa_objtxt TO t_objtxt.
* table header
wa_objtxt-line = '<th bgcolor="#90EE90">Airline & Code</th>'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = '<th bgcolor="#90EE90">Flight Connection Number</th>'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = '<th bgcolor="#90EE90">Flight date</th>'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = '<th bgcolor="#90EE90">Airfare</th>'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = '<th bgcolor="#90EE90">Local currency of airline</th>'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = '<th bgcolor="#90EE90">Test Field for Production</th>'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = '<th bgcolor="#90EE90">Aircraft Type</th></tr>'.
APPEND wa_objtxt TO t_objtxt.
* table Contents
LOOP AT it_final INTO wa_final.
wa_objtxt-line = '<tr style="background-color:#eeeeee;">'.
APPEND wa_objtxt TO t_objtxt.
CONCATENATE '<td>' wa_final-carrid '</td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO t_objtxt.
CONCATENATE '<td>' wa_final-connid '</td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO t_objtxt.
CONCATENATE '<td>' wa_final-fldate '</td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO t_objtxt.
CONCATENATE '<td>' wa_final-price '</td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO t_objtxt.
CONCATENATE '<td>' wa_final-currency '</td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO t_objtxt.
CONCATENATE '<td>' wa_final-testfield '</td>' INTO wa_objtxt-line.
APPEND wa_objtxt TO t_objtxt.
CONCATENATE '<td>' wa_final-planetype '</td></tr>' INTO wa_objtxt-line.
APPEND wa_objtxt TO t_objtxt.
CLEAR wa_final.
ENDLOOP.
* table close
wa_objtxt-line = '</tbody> </table>'.
APPEND wa_objtxt TO t_objtxt.
* Signature with background color
wa_objtxt-line = '<br><br>'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = '<p> Regards,</p>'.
APPEND wa_objtxt TO t_objtxt.
wa_objtxt-line = '<p style="background-color:#1E90FF;"><b> Your Name</b></p>'.
APPEND wa_objtxt TO t_objtxt.
* HTML close
wa_objtxt-line = '</body> </html> '.
APPEND wa_objtxt TO t_objtxt.
* Document data
DESCRIBE TABLE t_objtxt LINES w_tab_lines.
READ TABLE t_objtxt INTO wa_objtxt INDEX w_tab_lines.
wa_docdata-doc_size =
( w_tab_lines - 1 ) * 255 + STRLEN( wa_objtxt ).
* Packing data
CLEAR wa_objpack-transf_bin.
wa_objpack-head_start = 1.
wa_objpack-head_num = 0.
wa_objpack-body_start = 1.
wa_objpack-body_num = w_tab_lines.
* we will pass the HTML, since we have created the message
* body in the HTML
wa_objpack-doc_type = 'HTML'.
APPEND wa_objpack TO t_objpack.
ENDFORM. " CREATE_TITLE_DESC_BODY
*&---------------------------------------------------------------------*
*& Form fill_receivers
*&---------------------------------------------------------------------*
* Filling up the Receivers
*----------------------------------------------------------------------*
FORM fill_receivers .
wa_reclist-receiver = 'i_am_a_fish@anchovyl.com'.
wa_reclist-rec_type = 'U'.
APPEND wa_reclist TO t_reclist.
CLEAR wa_reclist.
ENDFORM. " fill_receivers
*&---------------------------------------------------------------------*
*& Form send_message
*&---------------------------------------------------------------------*
* Sending Mail
*----------------------------------------------------------------------*
FORM send_message .
* Send Message to external Internet ID
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_docdata
put_in_outbox = 'X'
commit_work = 'X' "used from rel.6.10
TABLES
packing_list = t_objpack
object_header = t_objhead
contents_txt = t_objtxt
receivers = t_reclist
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.
IF sy-subrc NE 0.
WRITE: 'Sending Failed'.
ELSE.
WRITE: 'Sending Successful'.
ENDIF.
ENDFORM. " send_message
Message was edited by: Matthew Billingham - removed email address
2013 Aug 20 9:52 AM
Hi,
I think in HTML the "&" might have been interpreted as mark of begin of character code or HTML code. Try passing & or & might be interpreted correctly in HTML format.
Cheers,
Arindam
2013 Aug 20 10:06 AM
Hi Nagaraij,
Yes it just like Arindam said, your HTML characters need to be escaped properly before displaying to user.
E.g. & escaped will become &.
There is this static method CL_ABAP_DYN_PRG=>ESCAPE_XSS_XML_HTML that will help you will the conversion.
E.g. Me & You after escaped will above method will become ME & YOU, which will render correctly with HTML format and show to user.
Hope it helps. Cheers!
2013 Aug 20 10:54 AM
Hi Nguye.
Thanks for your reply,Could you please give me any sample for CL_ABAP_DYN_PRG=>ESCAPE_XSS_XML_HTML?
regards.
NJ
2014 Jun 10 11:26 AM