Application Development and Automation 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: 
Read only

How to concatenate dynamic Internal table data

Former Member
0 Likes
4,113

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,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,874

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

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,

8 REPLIES 8
Read only

ArthurParisius
Contributor
0 Likes
2,874

Try looking at DO VARYING.

Read only

0 Likes
2,874

hmmm it's said to be obsolete.

Read only

0 Likes
2,874

Also wont be a solution, obsolete DO VARYING and current ASSIGN INCREMENT are useful for similar fields in a sequential order.

Read only

Former Member
0 Likes
2,875

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

Read only

Frank_Haschick
Participant
0 Likes
2,874

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.
Read only

2,874

Another option: you could go via RTTI, read the structure and access the fields via their names (just in case if you want to have the fieldnames also in your string).

Would then be something like

lo_tabtypedescr = cl_abap_tabledescr=>describe_by_data( p_data = itab ).
lo_structypedescr = cl_abap_structdescr=>describe_by_name( p_name = lo_tabtypedescr->get_ddic_header( )-refname ).
 "get the type of the structure of the table and get an rtti object of it

lt_tabfieldtab = lo_structypedescr->get_ddic_object( ). "now you have all fieldnames in this field-tab and you can just loop through it

PS @SAP: the editor here is is really really bad

Read only

2,874

Hi Frank,

Just out of interest did you know that 'Is Assigned' is actually an Abap conditional ? My code is not pseudo code. You also duplicate the functionality of sy-Index.

Regards

Rich

Read only

Former Member
0 Likes
2,874

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,