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: 

Convert column values into a row with a delimiter

Former Member
0 Kudos

Hi Gurus,

This may be a trivial question to you. I have an internal table itab with a column called plant, internal table has 'n' records, by the end of loop, I need to convert the column into a row delimited by comma into one row (one field). This needs to be dynamic without hard-coding.

Plant

1000

2000

3000

4000

5000 ....

n....

Expected result of the field:

field1 value: 1000,2000,3000,4000,5000,...n

Let's set a limit to the field say it can hold upto 500 chars.

Thanks,

GP.

3 REPLIES 3

suresh_datti
Active Contributor
0 Kudos

try this..


data: w_fld(500).
loop at itab.
concatenate w_fld itab-plant into w_fld
separated by ','.
endloop.
write:/ w_fld.

~Suresh

0 Kudos

Hi,

I've already tried this:

ELSEIF <fs_dms_cv>-zca_cv_attr_ind = c_multiple.

w_plant = <fs_plant_ele>-werks.

concatenate w_string w_plant

into w_string separated by c_delimiter.

IF w_end_fl = c_on.

w_tabname = <fs_dms_cv>-dbtabname.

ASSIGN (w_tabname) TO <fs_tabname>.

IF sy-subrc = 0.

ASSIGN COMPONENT <fs_dms_cv>-name_komp OF

STRUCTURE <fs_tabname> TO <fs_destination>.

IF sy-subrc = 0.

<fs_destination> = w_string.

ENDIF.

ENDIF.

There are 2 issues here: One is that after first plant there will be two commas inserted, after that it's consistent. Secondly the key word concatenate is against our code standards.

Please let me know if there is any other way of doing this.

Thanks.

Former Member
0 Kudos

Hi ,

Pls use the following code to get reqd output.

*Code starts here

report ztest.

data: begin of itab occurs 0,

field1(10) type c,

end of itab.

data: wa_itab like itab.

data: wa_rec(500) type c.

data: vindex type i,

reclen type i,

count type i.

itab-field1 = '1000'.

append itab.

itab-field1 = '2000'.

append itab.

itab-field1 = '3000'.

append itab.

itab-field1 = '4000'.

append itab.

itab-field1 = '5000'.

append itab.

describe table itab lines count.

loop at itab into wa_itab.

reclen = strlen( wa_itab ).

wa_rec+vindex(reclen) = wa_itab.

if sy-tabix < count.

concatenate wa_rec ',' into wa_rec.

endif.

vindex = vindex + reclen + 1.

endloop.

write : wa_rec.

*Code ends here

Cheers,

Vikram

Pls reward for helpful replies!!