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: 

How to convert an internal table to string

0 Kudos
4,131

Hi all;

I want to convert an internal table to string, but I can't find one way to realize it.

By the way, the table more than on field.

Like this

1 ACCEPTED SOLUTION

ThorstenHoefer
Active Contributor
3,832
data: l_sep,
l_result type string.

LOOP AT lt_data assinging field-symbol(<wa_data>).
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_data> TO field-symbol(<fs>).
IF sy-subrc <> 0.
EXIT.
ENDIF.
l_result = |{ l_result }{ l_sep }{ <fs> }|.
l_sep = ','.
ENDDO.
ENDLOOP.
8 REPLIES 8

matt
Active Contributor
3,832

Concatenate fields str1 to str14 together, then use REDUCE to concatenate each record in the internal table, with whatever separator you choose.

It's a strange structure to have. It has no benefit that I can see over simple using a string_table type.

ThorstenHoefer
Active Contributor
3,833
data: l_sep,
l_result type string.

LOOP AT lt_data assinging field-symbol(<wa_data>).
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa_data> TO field-symbol(<fs>).
IF sy-subrc <> 0.
EXIT.
ENDIF.
l_result = |{ l_result }{ l_sep }{ <fs> }|.
l_sep = ','.
ENDDO.
ENDLOOP.

0 Kudos
3,832

Thanks for sharing, I'll try

Sandra_Rossi
Active Contributor
0 Kudos
3,832

Please post the code as text instead of image, so that one can easily answer by copying your code in order to complete it.

Sandra_Rossi
Active Contributor
0 Kudos
3,832

Many ways. I would opt for REDUCE. But just to simplify my answer I show you how to concatenate strings:

DATA(concat_all_lines) = ``.
LOOP AT lt_mail REFERENCE INTO DATA(r).
  DATA(concat_one_line) = r-str1 && r-str2 && r-str3 && r-str4 && r-str5 && r-str6 && r-str7
              && r-str8 && r-str9 && r-str10 && r-str11 && r-str12 && r-str13 && r-str14.
  concat_all_lines = concat_all_lines && concat_one_line.
ENDLOOP.

0 Kudos
3,832

Thanks for shareing

touzik_itc
Active Participant
0 Kudos
3,832

Or something like that:

CONCATENATE LINES OF VALUE string_t( FOR <s> IN lt_mail ( <s>-str1 && <s>-str2 && <s>-str3 ) ) INTO DATA(result).

0 Kudos
3,832

Thank you, I know a new grammar