Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

String to XString Conversion

Former Member
0 Likes
9,534

Hi,

I want to convert XML file into XString.

The XML file is in itab and this itab is converted into a String using CONVERT_TABLE_TO_STRING funciotn module. This XML file into String conversion is done correctly.

When I tried String to XString conversion using TREX_TEXT_TO_XSTRING, the xstring variable results with many special characters (in some other langauage).

Or, when I tried converting itab to xstring using itab_to_xstring, xstring results with many extra characters.

Encoding style in xml is UTF-8.

Please let me know the correct way to convert xml to xstring.

Thanks,

Uma

1 ACCEPTED SOLUTION
Read only

Former Member
6,410

Hello,

Try this fm:


*Convert STRING to XSTRING
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text           = iv_content
*     MIMETYPE       = ' '
*     ENCODING       =
   IMPORTING
     buffer         = ev_xstring
   EXCEPTIONS
     failed         = 1
     OTHERS         = 2.

  IF sy-subrc <> 0.
    ev_subrc = 4.
  ENDIF.

Regards.

5 REPLIES 5
Read only

Former Member
6,411

Hello,

Try this fm:


*Convert STRING to XSTRING
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text           = iv_content
*     MIMETYPE       = ' '
*     ENCODING       =
   IMPORTING
     buffer         = ev_xstring
   EXCEPTIONS
     failed         = 1
     OTHERS         = 2.

  IF sy-subrc <> 0.
    ev_subrc = 4.
  ENDIF.

Regards.

Read only

0 Likes
6,410

Hi David,

Thanks for your reply.

I tried this function module also. XString return with special characters.

Thanks,

Uma

Read only

0 Likes
6,410

Check out this [/people/thomas.jung3/blog/2004/08/09/bsp-download-to-excel-in-unicode-format]

This weblog talks about excel but applies to your case as well.

Regards.

Read only

0 Likes
6,410

Thanks David.

I changed my code as below

data:
    bdata           type xstring,
    G_STR         type STRING,
    APP_TYPE   type char30.

clear bdata.
APP_TYPE = 'text/unicode; charset=utf-16le'.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  EXPORTING
    TEXT           = G_STR
    MIMETYPE       = APP_TYPE
*   ENCODING       =
  IMPORTING
    BUFFER         = bdata
* EXCEPTIONS
*   FAILED         = 1
*   OTHERS         = 2
          .

But the xstring bdata results with "square box" character after each character.

Thanks,

Uma

Read only

0 Likes
6,410

are you viewing the xstring in debug mode? if yes this may happen. the correct way to test is to view it in the right viewer. for example if its a xml file, would suggest downloading to local file and viewing in browser or some other xml tools