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

Convert standard table to Xstring and back

kevin_wang6
Product and Topic Expert
Product and Topic Expert
0 Likes
8,264

Hello,

there is a standard internal table, but I don't know how this internal table look like, could be any standard table.

My propose is to store this standard table in a field of flat structure(need to be converted back to standard table later),  it could be stored in a reference field, but in my case, i cannot use reference.

so I want to store standard table in a xstring, but i don't know how to convert a standard table to a xstring  and convert back.

Please give some samples.

Thanks in advance and best regards,

Kevin

Hello,

there is a standard internal table, but I don't know how this internal table look like, could be any standard table.

My propose is to store this standard table in a field of flat structure(need to be converted back to standard table later),  it could be stored in a reference field, but in my case, i cannot use reference.

so I want to store standard table in a xstring, but i don't know how to convert a standard table to a xstring  and convert back.

Please give some samples.

Thanks in advance and best regards,

Kevin

5 REPLIES 5
Read only

Former Member
3,282

hi Kevin

standard table to xstring:1 step using FM 'SCMS_TEXT_TO_BINARY', 2 step using FM 'SCMS_BINARY_TO_XSTRING''

xstring to standard table: 1 step using FM 'SCMS_XSTRING_TO_BINARY', 2 step using 'SCMS_BINARY_TO_TEXT'.

regards,

Archer

Read only

sivaganesh_krishnan
Contributor
0 Likes
3,282

HI kevin,

Please try this combination FM.

SOTR_SERV_TABLE_TO_STRING

SCMS_STRING_TO_XSTRING or SCMS_FTEXT_TO_XSTRING

At the end of this data would be in xstring.

For reverse process :

HR_KR_XSTRING_TO_STRING - converting to string

for converting from string to internal table. You can code it like


This is a sample code of mine

CONSTANTS:

  max TYPE i VALUE 15.

DATA:

  lv_string       TYPE string,

  lv_sum          TYPE i,

  lv_txt1(co_max) TYPE c,

  lt_txt1         LIKE TABLE OF lv_txt1,

  lv_len1         TYPE i,

  lv_txt2(co_max) TYPE c,

  lt_txt2         LIKE TABLE OF lv_txt2,

  lv_len2         TYPE i.

lv_string = 'WHERE BNAME = ''SFLIGHT*'' AND CONNID = ''AA'''.

SPLIT lv_string AT ' ' INTO TABLE lt_txt1.

LOOP AT lt_txt1 INTO lv_txt1.

  lv_len1 = strlen( lv_txt1 ).

  ASSERT lv_len1 <= max.

  lv_len2 = strlen( lv_txt2 ).

  lv_sum = lv_len1 + lv_len2 + 1.

  IF lv_sum <= max.

    CONCATENATE lv_txt2 lv_txt1 INTO lv_txt2 SEPARATED BY ' '.

    CONDENSE lv_txt2.

  ELSE.

    APPEND lv_txt2 TO lt_txt2.

    lv_txt2 = lv_txt1.

  ENDIF.

ENDLOOP.

APPEND lv_txt2 TO lt_txt2.

LOOP AT lt_txt2 INTO lv_txt2.

  WRITE: / lv_txt2.

ENDLOOP.


Regards,

Sivaganesh

Read only

Former Member
0 Likes
3,282

Declare a variable of type String and transfer the entire contents of your internal table to that variable.

Than call the FM below.


CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text           = html_string

*   MIMETYPE       = ' '

*   ENCODING       =

IMPORTING

buffer         = xhtml_string

EXCEPTIONS

failed         = 1

OTHERS         = 2.

Thanks

Abhinab

Read only

0 Likes
3,282

the problem is not from string to xstring. this piece we can just do

data(l_xstirng) = CL_ABAP_CODEPAGE=>convert_to(source = l_string)

or

data(l_string) = CL_ABAP_CODEPAGE=>convert_from(source = l_xstring)

Dr.Horst Keller has an example here in sdn.

the problem is, the internal table you have, may have mixed data types.

types: begin of ty_line,

a  type c,

b type p,

end of ty_line.

data: ls_line type ty_line,

lt_tab type standard table of ty_line.

here you can't simply write lt_tab to string because component b is a number.

you have to move b to data(l_string)

then concatenate your work with l_string to the final string.

George

Read only

kevin_wang6
Product and Topic Expert
Product and Topic Expert
0 Likes
3,282

Thank you for your answers, they are really helpful, this discussion is closed.