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

Appending dynamic Internal table

kiran_k8
Active Contributor
0 Likes
459

Hi.

I am trying to create dynamic internal tables which can store data and can be used for

further processing in the program.Say,I have 4 ztable names maintained in TVRAVC table then

I should be able to create 4 internal tables which can store data and can be used for

further processing like looping,read etc.


field-symbols:<table> type standard table,
              <fs_t> type any.
 
data:     lr_data type ref to data,

*Creating dynmaic internal tables for further processing
data:g_var1(4) type c value 'itab_',
     g_var2(7) type c.
loop at g_t_rec assigning <fs_t>.
clear:g_t_tvarvc,g_source.
read table g_t_tvarvc with key name = c_tty1
                               low  = <fs_t>+0(2).
if sy-subrc = 0.
g_source  = g_t_tvarvc-low                            "KK
g_tabname = g_t_tvarvc-high.                          "ZTABLE1
concatenate g_var1 g_source into g_var2               "here i will get itab_KK
create data lr_data  type table of (g_tabname).  
assign lr_data->* to <table>.                         "here I got the Ztable structure
endif.
endloop.

How to get the internal table as ITAB_KK into which I can move the g_t_rec internal table data.Similary I intend to get 4 internal tables.Kindly let me know.

Thanks,

KIran

2 REPLIES 2
Read only

asik_shameem
Active Contributor
0 Likes
421

Hi,

Get field list of fields in main internal table G_T_REC and ITAB_* using methods of class cl_abap_structdescr and compare the field names of each and move the values from g_t_rec to itab_*.

(refer: - Jerry Coleman)

l_t_compdescr1  = l_r_structdescr->components. " of g_t_rec
 l_t_compdescr2  = l_r_structdescr->components. " of itab_kk

LOOP AG g_t_rec.
  LOOP AT l_t_compdescr1 
    READ TABLE l_t_compdescr2 WITH KEY name = l_t_compdescr1-name
    IF success.
      itab_kk-(l_t_compdescr1-name) = g_t_rec-(l_t_compdescr1-name).
      .....
      APPEND itab_kk.
    ENDIIF.
  ENDLOOP.
ENDLOOP.

Hope you got my point.

Read only

Former Member
0 Likes
421

Hi,

The steps you performed can create the dynamic tables

for further processing like loop at or read table try using assign component


*got data from TVARVC into IT_TVARVC
create d_tab type table of (IT_TVARVC-HIGH).      "suppose HIGH have table name
create d_wa type (IT_TVARVC-HIGH).
assign d_tab->* to <ftab>.
select * from (IT_TVARVC-HIGH) into table <ftab>
        where (condn).                             "dynamic condn
loop at <ftab> assiging <fwa>.
assign component sy-tabix  of structure <ftab> to <fld>.   "assigning values to fields
endloop.
* same for read stat
read table <ftab> assiging <fwa>.

Thanks,

Anmol.