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: 

Filling structure dynamic with internal table

TimVDB92
Participant
0 Kudos

Hi,


I want to fill my structure with the values of the internal table: it_temp.


My structure: [ref, keynr, col001, col002, col003, ...., col020]


What is the easiest way to fill my structure?

I was thinking to loop through the internal table and creating a dynamic field but I'm not able to do the concatenate.


Thanks for the help!


       

loop at it_datatab INTO lv_string.

       "Tabs splitsen en in interne tabel stoppen

       SPLIT lv_string  AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB  INTO TABLE it_temp.

       "Structure invullen

       ls_data-ref = p_fname.

       ls_data-keynr = sy-tabix.

       lv_i = 001.

       loop at it_temp into lv_string.


" This is not working, but I should do something like this

         ls_data-col + " " + lv_i  = lv_string.

         lv_i = lv_i + 1.

       endloop.

endloop.

1 ACCEPTED SOLUTION

former_member205488
Active Participant
0 Kudos

Hello!

You could use statement DO ..VARYING...FROM...NEXT. This is an example code:

TYPES: BEGIN OF ts_data,

          col01 TYPE i,

          col02 TYPE i,

          col03 TYPE i,

          col04 TYPE i,

          col05 TYPE i,

        END OF ts_data.

DATA ls_data TYPE ts_data.

DATA lv_col TYPE i.

DO 5 TIMES VARYING lv_col FROM ls_data-col01 NEXT ls_data-col02.

   lv_col = sy-index.

ENDDO.


As a result the structure ls_data is filled with values 1, 2, 3, 4, 5.



1 REPLY 1

former_member205488
Active Participant
0 Kudos

Hello!

You could use statement DO ..VARYING...FROM...NEXT. This is an example code:

TYPES: BEGIN OF ts_data,

          col01 TYPE i,

          col02 TYPE i,

          col03 TYPE i,

          col04 TYPE i,

          col05 TYPE i,

        END OF ts_data.

DATA ls_data TYPE ts_data.

DATA lv_col TYPE i.

DO 5 TIMES VARYING lv_col FROM ls_data-col01 NEXT ls_data-col02.

   lv_col = sy-index.

ENDDO.


As a result the structure ls_data is filled with values 1, 2, 3, 4, 5.