Skip to Content
author's profile photo Former Member
Former Member

Convert column values into a row with a delimiter

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Jun 18, 2006 at 10:00 PM

    try this..

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

    ~Suresh

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2006 at 10:04 PM

    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!!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.