Skip to Content
-1

How to concatenate dynamic Internal table data

Hi Experts,

I have a requirement to read internal table and concatenate the fields data to a string variable and write a file into AL11 path. But the problem is internal table will hold dynamic columns.Anybody please help how to handle concatenate of dynamic fields.

Example.

ITAB

Clo1 Col2 Col3.............. Coln

1 2 3

8 9 5

7 3 8

Expect result

Concatenate col1 Col2 col3....Coln into variable separated by space.

Thanks,

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    Posted on Jan 30, 2019 at 12:48 PM

    DO VARYING is obsolete in our version of SAP.

    You could try:

    Do.
         Assign Component sy-Index Of Structure... To <fs>
         If <fs> Is Assigned.
            ....
            UnAssign <fs>.
         Else.
            Exit.
         EndIf.
    EndDo

    Regards

    Rich

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 30, 2019 at 01:52 PM

    I would do it quite similar to the approach of Rich:

      DATA: lv_index  TYPE i,
            lv_string TYPE string.
      LOOP AT itab ASSIGNING FIELD-SYMBOL(<ls_line>).
        lv_index = 0.
        CLEAR lv_string.
        DO.
          ASSIGN COMPONENT 0 OF STRUCTURE <ls_line> TO <lv_field>.
          IF sy-subrc EQ 0.
            CONCATENATE lv_string <lv_field> INTO lv_string SEPARATED BY space.
            ADD 1 TO lv_index.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.
        "now all columns of one table line are concatenated into lv_string
        "you could append it to a table or write it or whatever
      ENDLOOP.
    
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 30, 2019 at 10:35 AM
    -1

    Try looking at DO VARYING.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 31, 2019 at 09:37 AM
    -1

    Hello Experts,

    Above suggestions are worked and now i am facing some issue while placing file to some al11 path.

    I mean my requirement is one alv program in foreground giving time out error but in background spool generating, The problem is from spool i can't get data to excel because in my setting 10 page only can get. So i am planning to download that internal table data to al11 path/ share folder path. Anybody can help on this is there any better solution or how to write internal table data to excel file.

    Thanks,

    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.