‎2008 Jul 09 11:14 AM
Hi all,
Is there any method which can create an internal table with the given name and type?
for example:
i want an internal table to be created dynamically with the name "itab_1" and type "typ_itab".
i cant declare the internal table statically because the name of the internal table is dynamic
it ca be itab_1 or itab_2 or... itab_n.
thanks in advance
hyma
‎2008 Jul 09 11:40 AM
Hello Hyma
You may want to have a look at my Wiki posting
[Creating Flat and Complex Internal Tables Dynamically using RTTI|https://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI]
Regards
Uwe
‎2008 Jul 09 1:01 PM
You can do this dynamic "select into" by creating your internal table
and work area dynamically so you don't have to know the table and
structure ahead of time as it is all create at run time:
1) get the field catalog for you table (REUSE_ALV_FIELDCATALOG_MERGE -
this only works for DDIC tables not internal tables defined in your
code)
2) create the internal table and work area
data: gv_tfcat type lvc_t_fcat.
data: gv_tabl type ref to data.
data: gv_line type ref to data.
Data: tabnam type table_name.
field-symbols:
<gf_tab> type any table,
<gf_wa>,
<gf_fld>.
Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = gv_tfcat
importing
ep_table = gv_tabl.
assign gv_tabl->* to <gf_tab>.
Create dynamic work area and assign to FS
create data gv_line like line of <gf_tab>.
assign gv_line->* to <gf_wa>.
3) perform your selection:
select *
from (tabnam)
into corresponding fields of table <gf_tab>.
4) when you wish to use the table:
Loop at <gf_tab> into <gf_wa>.
do.
assign component sy-index
of structure <gf_wa> to <gf_fld>.
if sy-subrc <> 0.
exit.
endif.
............. your additional code here ...................
Its not my own code..... anyway i feel it clear's ur doubt..
‎2008 Jul 09 1:14 PM
I'm glad you pointed out it's not your own code. It would have been polite to post the link though.