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: 

Dynamic ITAB with reduced column set

michael_kilger
Explorer
0 Kudos
646

Hello,

the problem i try to solve: i have an database table with e.g. 50 columns.
I want to create an internal table with a subset of these columns (n<50), due to performance reasons.
The data load is huge and i want to reduce the computing time (operations on ITab) and "RAM wastage" by selecting only the columns really needed.

So the number of columns depends on user interaction (n can be between 1 and 50).

First i tried using following methods which does not work properly with all tables (SELECT-problems causes Unicode-Exception by some tables):
cl_abap_typedescr=>describe_by_name( 'tablename' )
cl_alv_table_create=>create_dynamic_table


With second try i used only RTTI-Methods (which seems to be a really smart way to deal with the problem):

ref_rowtype ?= cl_abap_typedescr=>describe_by_name( 'tablename' )
ref_tabletype = cl_abap_tabledescr=>create( p_line_type = ref_rowtype )

This solution works fine, but i am not able to reduce the number of columns (components).

Has anybody an idea how i can fix the request "dynamic choosing of columns", please 🙂 ?

Kind regards,
Michael Kilger

1 ACCEPTED SOLUTION

Former Member
414

Hello Michael,

Definitely RTTI is the way to go:

  1. Obtain the fields of the original structure using CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME('LONG_STRUCTURE_NAME')
  2. Create a dynamic row type using CL_ABAP_STRUCTDESCR=>GET where you only provide the required subset of the components from the structure descriptor you previously extracted
  3. Create a table type using the line type from step 2.

BR,
Gábor

5 REPLIES 5

Former Member
415

Hello Michael,

Definitely RTTI is the way to go:

  1. Obtain the fields of the original structure using CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME('LONG_STRUCTURE_NAME')
  2. Create a dynamic row type using CL_ABAP_STRUCTDESCR=>GET where you only provide the required subset of the components from the structure descriptor you previously extracted
  3. Create a table type using the line type from step 2.

BR,
Gábor

Sandra_Rossi
Active Contributor
414

Don't use cl_alv_table_create=>create_dynamic_table, use RTTS cf Gábor Márián answer (aka RTTC, RTTI).

DoanManhQuynh
Active Contributor
0 Kudos
414

if you are trying to delete unused components from database table, i suggest to do it opposite way:

1. Take all components from database table name.

2. Take columns that user chosen and check the existence in step 1.

3. Create a new table type with subset of components collected in step 2.

michael_kilger
Explorer
0 Kudos
414

Hello Gábor,

your proposal for solution worked fine.

I did not know how to use the modified components-Tab.

So, using the method-call "CL_ABAP_STRUCTDESCR=>GET( exporting P_COMPONENTS = lit_Components )" (with lit_Components modified in step before) was the missing link.

Thank you very much!

Kind regards to you (and all who answered 🙂 ),

Michael Kilger

414

Glad it worked. 🙂

In that case you should close the topic, so it will be obvious to everyone that it has been answered.