2019 Sep 24 5:00 PM
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
2019 Sep 24 5:25 PM
Hello Michael,
Definitely RTTI is the way to go:
BR,
Gábor
2019 Sep 24 5:25 PM
Hello Michael,
Definitely RTTI is the way to go:
BR,
Gábor
2019 Sep 24 8:05 PM
Don't use cl_alv_table_create=>create_dynamic_table, use RTTS cf Gábor Márián answer (aka RTTC, RTTI).
2019 Sep 25 1:00 AM
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.
2019 Sep 25 1:00 PM
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
2019 Sep 25 1:30 PM
Glad it worked. 🙂
In that case you should close the topic, so it will be obvious to everyone that it has been answered.