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

creating an internal table

hymavathi_oruganti
Active Contributor
0 Likes
458

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

3 REPLIES 3
Read only

uwe_schieferstein
Active Contributor
0 Likes
439

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

Read only

Former Member
0 Likes
439

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

Read only

matt
Active Contributor
0 Likes
439

I'm glad you pointed out it's not your own code. It would have been polite to post the link though.

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/dynamic-internal-table-name-in-select-s...