Application Development 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: 

String to Xstring

Former Member
0 Kudos

Hello Experts,

Ca any one please suggest me some FM (SAP version in 4.6B) for converting String to Xstring..?

I have got the data in w_string in STRING format. The below FM is called in other FM which is created by me. But the requirement is to Export the data in Xstring format.

  • Convert table to to string

CALL FUNCTION 'CONVERT_TABLE_TO_STRING'

EXPORTING

i_tabline_length = '1024'

IMPORTING

e_string = w_string

TABLES

it_table = it_contents.

I will reward points points if helpful.

6 REPLIES 6

Sm1tje
Active Contributor
0 Kudos

possibly.....SCMS_STRING_TO_XSTRING

Edited by: Micky Oestreich on May 29, 2008 2:48 PM

It's an answer useful even after years !

Thanks for sharing.

Best regards,

Paskalo.

Former Member

Hi,

convert string to Xstring you can use the following FM

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = output " variable type string

IMPORTING

buffer = outputx. " variable type xstring

Regards

Kiran Sure

0 Kudos

Thanks to both of you.

But this FM does not exists in 4.6C...I work on this version..

Please tell me...if there is any other way..?

0 Kudos

The following code only works if the unicode validation is switched off:

dataa1(100) type c,

         a2(100) type x,

         s1 type string,     " source

         s2 type xstring.   " target

   s1 = 'My string to convert'.

   a1 = s1.

   FIELD-SYMBOLS: <char_container> TYPE c.

   ASSIGN a2 TO <char_container> CASTING.

  

   <char_container> = a1.

   s2 = a2.


Regards,

Ulrich



Former Member
0 Kudos

I tried this and it wroked well by me:

Data:

         lv_xstring      TYPE xstring,

         lv_mes_str    TYPE string,

         lv_length       TYPE i,

         lv_conv         TYPE REF TO cl_abap_conv_out_ce.

lv_mess_str = "This should be the message in the string too be converted to XSTRING"

** Call class method to convert data to  compatible xstring

   CLEAR: lv_length, lv_xstring, lv_conv.

   TRY.

       lv_conv = cl_abap_conv_out_ce=>create( ).

     CATCH cx_parameter_invalid_range .

* error handling

     CATCH cx_sy_codepage_converter_init .

* error handling

   ENDTRY.

   TRY.

       CALL METHOD lv_conv->write

         EXPORTING

           n    = -1

           data = lv_mes_str

*         VIEW =

         IMPORTING

           len  = lv_length.

     CATCH cx_sy_codepage_converter_init .

* error handling

     CATCH cx_sy_conversion_codepage .

* error handling

     CATCH cx_parameter_invalid_type .

* error handling

     CATCH cx_parameter_invalid_range .

* error handling

   ENDTRY.

   TRY.

       CALL METHOD lv_conv->get_buffer

         RECEIVING

           buffer = lv_xstring.

     CATCH cx_root.

* error handling

   ENDTRY.