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

Making into single internal table

Former Member
0 Likes
1,069

Hi,

I have a table which is declared as follows:

TYPES:BEGIN OF table_type,

fields TYPE tt_type OCCURS 0,

dyn_table TYPE ref to data,

END OF table_type.

DATA: t_tab type standard table of table_type.

dyn_table[] is having the corresponding records for fields[].

Now i want to make a single table with the fields[] and dyn_table[].Can anyone suggest how to achieve this.

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,039

NO...I HAVE MULTIPLE LINES IN THE INTERNAL TABLE.HENCE THE FIELDS table AND the DYN_TABLE has different field and values for each line.

Then, this is not right approach. You will have to create new dynamic table which will combine fields both from FIELDS table and DYN_TABLE. Right now you have:


TYPES:BEGIN OF table_type,
fields TYPE tt_type OCCURS 0,   "one field has table strcuture
dyn_table TYPE ref to data,           "and one field stores reference to different table structure
END OF table_type.

Using above you have two fields which in fact are itself tables. So you have two nested (and deep) tables within one.

First thing which I notice about your definition is that you can't use OCCURS together with types. You would have to do it like


TYPES: tt_type TYPE TABLE OF ...

TYPES:BEGIN OF table_type,
fields TYPE tt_type,
dyn_table TYPE ref to data,          
END OF table_type.

But as for the definition of table which would consolidate fields of these nested tables within one you have to create it dynamically. One approach would be creating fieldcatlog based on FIELDS and DYN_TABLE and using CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE which would return single dynamic table where you can copy all data from FIELDS and DYN_TABLE.

Another way would be using RTTS to structure component by component -> then table based on that structure.

Regards

Marcin

7 REPLIES 7
Read only

Kanagaraja_L
Active Contributor
0 Likes
1,039

As per my understanding both table fields and dyn_table having the same Fields so you can use any one of the tabel either FILEDS or DYN_TABLE.

Kanagaraja L

Read only

0 Likes
1,039

NO...I HAVE MULTIPLE LINES IN THE INTERNAL TABLE.HENCE THE FIELDS table AND the DYN_TABLE has different field and values for each line.

Read only

MarcinPciak
Active Contributor
0 Likes
1,040

NO...I HAVE MULTIPLE LINES IN THE INTERNAL TABLE.HENCE THE FIELDS table AND the DYN_TABLE has different field and values for each line.

Then, this is not right approach. You will have to create new dynamic table which will combine fields both from FIELDS table and DYN_TABLE. Right now you have:


TYPES:BEGIN OF table_type,
fields TYPE tt_type OCCURS 0,   "one field has table strcuture
dyn_table TYPE ref to data,           "and one field stores reference to different table structure
END OF table_type.

Using above you have two fields which in fact are itself tables. So you have two nested (and deep) tables within one.

First thing which I notice about your definition is that you can't use OCCURS together with types. You would have to do it like


TYPES: tt_type TYPE TABLE OF ...

TYPES:BEGIN OF table_type,
fields TYPE tt_type,
dyn_table TYPE ref to data,          
END OF table_type.

But as for the definition of table which would consolidate fields of these nested tables within one you have to create it dynamically. One approach would be creating fieldcatlog based on FIELDS and DYN_TABLE and using CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE which would return single dynamic table where you can copy all data from FIELDS and DYN_TABLE.

Another way would be using RTTS to structure component by component -> then table based on that structure.

Regards

Marcin

Read only

0 Likes
1,039

Hi Marcin,

Can you please be more clear? Bcz when I craete a dynamic internal tables using the fields, how can I fill the dynamic internal table?

Read only

0 Likes
1,039

Hmm, not sure now if I get you right.

Let's summarize:

- you have FIELDS table which holds some data - what is then this table structure?

- you have DYN_TABLE which holds some data - what is then the structrue of this table too?

- you want final table i.e. FINAL_TABLE which structure will be composed as (structure of table FIELDS + structure of table DYN_TABLE), is that right?

- finally you want to move data from FIELDS and DYN_TABLE to FINAL_TABLE, right?

Please confirm that, otherwise it will be hard to help you

Thanks

Marcin

Read only

0 Likes
1,039

Fields table contains the field names.

Example I have 3 fields as F1, F2, F3

DYN_TABLE contains the records.

Example I have the value of F1 as 1, for F2 as 2, for F3 as 3.

I want to make the final table with all the fields and values.

Example:

F1 F2 F3

1 2 3

Like this in multiple lines I have different tables inside the table.I want to mix all the fields into one table with the corresponding values.

Edited by: Jjammy on Jul 29, 2009 12:49 PM

Read only

0 Likes
1,039

One more thing which I don't get. Does DYN_TABLE holds values 1,2,3 as 3 records?

1) value 1

2) value 2

3) value 3

or

this is just one record with different fields, but you only want to copy those F1, F2, F3 fields for which values are like 1, 2, 3, to new table?

I think you mean the second, so this would be what you need


data: it_fcat type lvc_f_cat with header line.

"first creat field catalog based on fields names
loop at fields.
    it_fcat-fieldname = fields-name.
    
    "give field type, either excplicitly or via DDIC reference
    it_fcat-INTTYPE = ...
    it_fcat-INTLEN = ...
    append it_fcat.
endloop.

now create new dynamic table


field-symbols <new_tab> type any table.

data: new_table type ref to data.

    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = is_fcat
      IMPORTING
        ep_table        = new_table.

assign new_table->* to <new_tab>.

Last thing you need is to move values from DYN_TAB to corresponding NEW_TAB


data: wa_dyn_tab type ref to data,
          wa_new_tab type ref to data.

field-symbols <dyn_tab> type any table,
                         <wa_dyn> type any,
                         <wa_new> type any.

assign dyn_tab->* to <dyn_tab>.

"create work areas for both tables
create data: wa_dyn_tab like line of <tab>,
                      wa_new_tab like line of <new_tab>.

assign: wa_dyn_tab->* to <wa_dyn>,
               wa_new_tab->* to <wa_new>.      

"now copy content from DYN_TAB to NEW_TAB using <wa_dyn> and <wa_new>.
loop at <dyn_tab> into <wa_dyn>.
   move-corresponding <wa_dyn> to <wa_new>.  
   append <wa_new> to <new_tab>.   "now <new_tab> contains only corresponding values from <dyn_tab> based on FIELDS table
endloop.

Hope this is what you need

Regards

Marcin