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 add data from internal table to a variable

Former Member
0 Kudos

Hello Experts.

I have two entries in internal table , both of the entries are text of length 10chars.

Now i want to display that in the output with a single variable.

ie for example in itab i have like 1st field = Indian

2nd field = Heros

Now i want to display like Indian Heros with the help of a single variable. so please tell me how to populate this internal table data into that single variable and make it as one sentence.

Thanks for all the replies

5 REPLIES 5

Former Member
0 Kudos

Hi shiva,

1. Take a new variable.

eg.

Data : mystr(25) type c.

2. Loop at itab.

concatenate itab-field1 itab-field2 into mystr separated by space.

write 😕 mystr.

endloop.

regards,

amit m.

former_member199581
Active Participant
0 Kudos

Try this:


DATA: variable TYPE string.

LOOP AT itab.
 CONCATENATE variable itab INTO variable SEPARATED BY space.
ENDLOOP.

SHIFT variable LEFT DELETING LEADING SPACES.

WRITE: / variable.

Hope I've understood well.

Roby.

johndeconinck
Participant
0 Kudos

Hi Shiva,

Could also be like this:

data: begin of itab occurs 0 with header line,

f1,

f2,

end of itab.

data: w_field(20) type c.

start-of-selection.

itab-f1 = 'Indian'.

itab-f2 = 'Heroes'.

append itab.

loop at itab.

concatenate itab-f1 ifab-f2 into w_field seperated by space.

write: / w_field.

endloop.

Kind regards,

John.

Former Member
0 Kudos

Hi Shiva,

all the other experts above are right, but keep in mind that you might work with an internal table WITHOUT header line. Given this case you have to modify the example coding from above:

DATA struc TYPE structure_with_two_fields.

DATA itab TYPE TABLE OF structure_with_two_fields.

DATA text TYPE string.

LOOP AT itab INTO struc.

CONCATENATE struc-field1 struc-field2 INTO lv_text SEPARATED BY SPACE.

ENDLOOP.

WRITE test.

Former Member
0 Kudos

hi,

do this.

data : text1(25) type c,

text2(25) type c.

loop at itab.

if sy-tabix eq = 1.

text2 = itab-field.

else.

concatenate itab-field text2 into text1 separated by space.

text2 = text1.

clear text1.

endif.

endloop.

text2 contains all the records as concatenated into one string.