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: 

Urgent! fields of a table to be separated with space n comma

Former Member
0 Kudos

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

8 REPLIES 8

Former Member
0 Kudos

use REPLACE ' ' with ',' INTO string.

Former Member
0 Kudos

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

former_member585865
Contributor
0 Kudos

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.

0 Kudos

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.

0 Kudos

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

former_member624107
Contributor
0 Kudos

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

Former Member
0 Kudos

data: ch(2) type c value ','.

loop at itab.

concatenate answer itab-name into answer separated by ch.

endloop.

kesavadas_thekkillath
Active Contributor
0 Kudos

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.