‎2008 Jan 21 6:57 AM
Hi
Could you please tell me how to build a field catalog (ooops alv) for an internal table which is a dynamic data object.
TYPES: BEGIN OF t_addsubty,
subty TYPE subty,
pernr TYPE persno,
END OF t_addsubty.
TYPES: ty_addsubty type t_addsubty occurs 1.
i have data object using these
CREATE DATA dref3 TYPE (g_type1).
ASSIGN dref3->* TO <fs_dp>.
where g_type1 refers a data type which i defined in the program. g_type1 = ty_addsubty.
now <fs_dp> refers to an internal table.
now i want to build a field catalog for this internal table.
In my program <fs_dp> structure is not always the same. i.e now it is ty_addsubty but for some other conditions the structure is different.
please help me out.
regards
badri
‎2008 Jan 21 8:22 AM
I guess, RTTI is what you are looking for. Hava e look at the ABAP Classes matching the pattern CL_ABAP_*DESCR.
You might use the Method DESCRIBE_BY_DATA_REF of Class CL_ABAP_TABLEDESCR to get an instance of this class. Then you might want to use the Instance Method GET_TABLE_LINE_TYPE to retrieve an according Instance of class CL_ABAP_STRUCTDESCR, which describes the elements of the structure of the internal table refenciated by "dref3". The Instance of CL_ABAP_STRUCTDESCR has an attribute called COMPONENTS, which you can use to build up your field catalogue.
Hope that helps...
--M0KE
‎2008 Jan 21 8:22 AM
I guess, RTTI is what you are looking for. Hava e look at the ABAP Classes matching the pattern CL_ABAP_*DESCR.
You might use the Method DESCRIBE_BY_DATA_REF of Class CL_ABAP_TABLEDESCR to get an instance of this class. Then you might want to use the Instance Method GET_TABLE_LINE_TYPE to retrieve an according Instance of class CL_ABAP_STRUCTDESCR, which describes the elements of the structure of the internal table refenciated by "dref3". The Instance of CL_ABAP_STRUCTDESCR has an attribute called COMPONENTS, which you can use to build up your field catalogue.
Hope that helps...
--M0KE
‎2008 Jan 21 11:35 AM
Hi mike
thank u for the reply
could u please send a sample code for this
regards
badri
‎2008 Jan 21 12:47 PM
Here some piece of code, which shows how it works:
<SNIP>
type-pools:
abap.
DATA:
lr_tabledescr TYPE REF TO cl_abap_tabledescr,
lr_structdescr TYPE REF TO cl_abap_structdescr.
field-symbols:
<lw_component> type abap_compdescr_tab.
TYPES:
BEGIN OF t_addsubty,
subty TYPE subty,
pernr TYPE persno,
END OF t_addsubty.
TYPES:
ty_addsubty type t_addsubty occurs 1.
CREATE DATA dref3 TYPE (g_type1).
ASSIGN dref3->* TO <fs_dp>.
lr_tabledescr ?= cl_abap_tabledescr=>describe_by_data( <fs_dp> ).
assert condition lr_tabledescr is bound.
lr_structdescr ?= lr_tabledescr->get_table_line_type( ).
loop at lr_structdescr->components assigning <lw_component>.
* do whatever you want with the information about
* the components of the structure
endloop.
</SNIP>
Do not forget to reward points...
‎2008 Jan 23 3:50 AM
Hi Mike
Thank u very much for the timely help.
It solved my problem.
Thanks and regards
Badri
‎2008 Jan 21 8:30 AM
Hello Badri
You may want to have a look at my Wiki posting
[Creating Flat and Complex Internal Tables Dynamically using RTTI|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/creating%2bflat%2band%2bcomplex%2binternal%2btables%2bdynamically%2busing%2brtti]
and the thread mentioned therein: [Creation of table of table dynamically|;
Regards,
Uwe