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: 

dynamically creating a structure

Former Member
0 Kudos

Hi,

Is it possible to dynamically define a structure? I know only one field which will be static and the other fields will be obtained only at runtime. I tried a definition which was like:

TYPES: BEGIN of struct1,

FIELD1 TYPE STRING,

INCLUDE TYPE (struct2),

END OF struct1.

But I am unable to do this, the error message says (struct2) is invalid. Can I achieve this in any other way? Thank you.

Regards,

Nithya

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

This code snippet tells u how to get data into I_table which is created dynamically....

DATA: r_dyn_table TYPE REF TO data,

r_wa_dyn_table TYPE REF TO data,

l_fields_table type SOI_FIELDS_TABLE.

FIELD-SYMBOLS: <t_dyn_table> TYPE STANDARD TABLE,

<wa_dyn_table> TYPE ANY,

<w_field1> TYPE ANY,

<w_field2> TYPE ANY.

DATA: l_oref_structure TYPE REF TO cl_abap_structdescr,

l_abap_compdescr type abap_compdescr.

data: check1 type i,

check2 type i,

l_range(20).

r_dyn_table = IL_DYNDATA-r_dyn_table.

ASSIGN r_dyn_table->* TO <t_dyn_table>.

CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.

ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.

l_oref_structure ?= cl_abap_typedescr=>describe_by_data(

wa_supl ).

loop at il_fill_itab into wa_supl.

loop at l_oref_structure->COMPONENTS into l_abap_compdescr.

ASSIGN COMPONENT l_abap_compdescr-name

OF STRUCTURE wa_supl TO <w_field1>.

check1 = sy-subrc.

ASSIGN COMPONENT l_abap_compdescr-name

OF STRUCTURE <wa_dyn_table> TO <w_field2>.

check2 = sy-subrc.

if check1 = 0 and check2 = 0.

<w_field2> = <w_field1>.

endif.

endloop.

APPEND <wa_dyn_table> TO <t_dyn_table>.

endloop.

You can access your dynamic internal table via a field symbol.

reward points if it helps u...

with regards,

Manikandan R

2 REPLIES 2

former_member188685
Active Contributor
0 Kudos

hi,

check this thread..

thanks

vijay

Former Member
0 Kudos

Hi,

This code snippet tells u how to get data into I_table which is created dynamically....

DATA: r_dyn_table TYPE REF TO data,

r_wa_dyn_table TYPE REF TO data,

l_fields_table type SOI_FIELDS_TABLE.

FIELD-SYMBOLS: <t_dyn_table> TYPE STANDARD TABLE,

<wa_dyn_table> TYPE ANY,

<w_field1> TYPE ANY,

<w_field2> TYPE ANY.

DATA: l_oref_structure TYPE REF TO cl_abap_structdescr,

l_abap_compdescr type abap_compdescr.

data: check1 type i,

check2 type i,

l_range(20).

r_dyn_table = IL_DYNDATA-r_dyn_table.

ASSIGN r_dyn_table->* TO <t_dyn_table>.

CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.

ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.

l_oref_structure ?= cl_abap_typedescr=>describe_by_data(

wa_supl ).

loop at il_fill_itab into wa_supl.

loop at l_oref_structure->COMPONENTS into l_abap_compdescr.

ASSIGN COMPONENT l_abap_compdescr-name

OF STRUCTURE wa_supl TO <w_field1>.

check1 = sy-subrc.

ASSIGN COMPONENT l_abap_compdescr-name

OF STRUCTURE <wa_dyn_table> TO <w_field2>.

check2 = sy-subrc.

if check1 = 0 and check2 = 0.

<w_field2> = <w_field1>.

endif.

endloop.

APPEND <wa_dyn_table> TO <t_dyn_table>.

endloop.

You can access your dynamic internal table via a field symbol.

reward points if it helps u...

with regards,

Manikandan R