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

build field catalog for dynamic data objects

Former Member
0 Likes
1,685

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,026

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

5 REPLIES 5
Read only

Former Member
0 Likes
1,027

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

Read only

0 Likes
1,026

Hi mike

thank u for the reply

could u please send a sample code for this

regards

badri

Read only

0 Likes
1,026

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

Read only

0 Likes
1,026

Hi Mike

Thank u very much for the timely help.

It solved my problem.

Thanks and regards

Badri

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,026

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