We have a long XML string which we want to send by email as a UTF-8 attachment. But SAP constantly corrupts the attachment by inserting newlines.
So we tried to break the string into lines with one element per line (xml1.png).
We then convert this to an internal table (xml2.png) of type srm_t_solisti1 using SPLIT.
When we then use SO_RAW_TO_RTF to convert it for email it get's corrupted as the Function breaks the double-byte characters (xml3.png).
Surely there must be a simple way to send this XML via Email as UTF-8 without all these steps, confusion and corruption?
**********************************************************************
DATA: lt_att TYPE rmps_t_post_content,
ls_att TYPE rmps_post_content,
lv_to TYPE zemail,
lv_subject TYPE text50,
lv_xml TYPE string,
lt_xml TYPE srm_t_solisti1.
**********************************************************************
" 1. Get data (deep structure) as XML
CALL TRANSFORMATION id
SOURCE data = change
OPTIONS
xml_header = 'NO'
RESULT XML lv_xml.
" 2. Convert to text table
DATA lvs TYPE string. CONCATENATE '>' cl_abap_char_utilities=>newline '<' INTO lvs.
REPLACE ALL OCCURRENCES OF '><' IN lv_xml WITH lvs.
DATA: lts TYPE zstring_tt, lss TYPE solisti1.
SPLIT lv_xml AT cl_abap_char_utilities=>newline INTO TABLE lts.
LOOP AT lts INTO lvs.
lss-line = lvs && cl_abap_char_utilities=>newline.
APPEND lss TO lt_xml.
ENDLOOP.
" 3. Prepare for attachment
CALL FUNCTION 'SO_RAW_TO_RTF'
TABLES
objcont_old = lt_xml
objcont_new = lt_xml.
" 4. Create attachment
ls_att-subject = 'change.xml'.
ls_att-objtp = 'txt'.
ls_att-cont_text[] = lt_xml.
APPEND ls_att TO lt_att.