12-13-2007 4:40 AM
Hi,
I have a table in which the entries have to be separated by a comma n space.
I have put the entries within an internal table.
I used the concatenate to do this but its getting overwritten.
Eg.I have atable with the field as name.
The entries for this field r say aaa bbb ccc ddd.
I have put these into an internal table itab.
The required output is aaa, bbb, ccc, ddd
For this I coded as
loop at itab.
concatenate itab-name ' ,' into answer separated by space.
endloop.
answer is a string which gets overwritten with one entry.Finally answer is having only ddd.
Please help me ASAP with the exact procedure and syntax.
Thankyou
12-13-2007 4:45 AM
12-13-2007 4:46 AM
hi,
Use the code.
Data lv_string type string.
loop at itab.
concatenate lv_string itab-name ' ,' space into lv_string.
endloop.
Thanks,
kasiraman R
12-13-2007 4:52 AM
Hi,
try like this,
data : wa(6) type c.
DATA : BEGIN OF ITAB OCCURS 0,
NAME(20) TYPE C,
END OF ITAB.
itab-name = 'aaa'.
append itab.
itab-name = 'bbb'.
append itab.
itab-name = 'ccc'.
append itab.
itab-name = 'ddd'.
append itab.
loop at itab.
concatenate itab-name ' ,' into wa separated by space.
write : wa.
endloop.
12-13-2007 5:00 AM
Hi,
Thankyou but this was just an example..The field will hve many entries so each time I cant write, itab-name = aaa,itab-name = bbb..So kindly tell me another solution.
Thankyou.
12-13-2007 5:04 AM
Hi
U r populating itab from database Table rit.???..
So wt s ur concern..??
after populating itab , u r trying to move contents if itab to variable answer..using
<b>loop at itab.
if sy-tabix = 1.
answer = itab-name.
else.
concatenate answer ' ,' itab-name into answer separated by space.
endif.
endloop.</b>
Message was edited by:
Sheeba Bhaskaran
12-13-2007 4:55 AM
Hi..
modify code like this
loop at itab.
<b>if sy-tabix = 1.
answer = itab-name.
else.
concatenate answer ' ,' itab-name into answer separated by space.
endif.</b>
endloop.
Message was edited by:
Sheeba Bhaskaran
12-13-2007 4:57 AM
data: ch(2) type c value ','.
loop at itab.
concatenate answer itab-name into answer separated by ch.
endloop.
12-13-2007 4:57 AM
data: var (500).
read table itab index 1.
if sy-subrc = 0.
var = itab-name.
endif.
loop at itab from 2.
concatenate var ',' itab-name into var seperated by space.
at last.
concatenate var '.' into var.
endat.
endloop.
reward if usefull.