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: 

Create Dynamic Structure based on Field-Symbol

former_member305388
Active Contributor
0 Kudos

Hi Experts!!

I need to create a structure with dynamic structure included within.

I have a parameter on sel. screen in which we provide table name.

PARAMETERS: p_table TYPE tabname.

FIELD-SYMBOLS: <gt_data> TYPE ANY TABLE.

CREATE DATA gr_data TYPE TABLE OF (p_table).

ASSIGN gr_data-* TO <gt_data>.

Now I need a structure like below:

TYPES: BEGIN OF type_test,

struct TYPE <gt_data>, " dynamic structure based on table name entered on sel. screen

fld1 TYPE c,

fld2 TYPE n,

END OF type_test.

Can somebody suggest how to achieve this?

Your help is highly appreciated. Thanks a lot

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor
0 Kudos

You can view this thread where our friend Marcin rocks ..


FIELD-SYMBOLS: <gt_data> TYPE ANY TABLE.
FIELD-SYMBOLS: <gs_wa> TYPE ANY.
data:wf_ref type ref to data.
DATA:i_comp TYPE cl_abap_structdescr=>component_table,
     i_tot_comp TYPE cl_abap_structdescr=>component_table.

CREATE DATA gr_data TYPE TABLE OF (p_table).
ASSIGN gr_data-* TO <gt_data>.
create data wf_ref like line of <gt_data>.
assign wf_ref->* to <gs_wa>.

*--Getting Compoents from existing type
  lf_struct ?= cl_abap_typedescr=>describe_by_name( '<GS_WA>' ).
  i_comp = lf_struct->get_components( ).
  APPEND LINES OF i_comp TO i_tot_comp.

The idea is Get all the field details available it to i_tot_comp, then append individual fields manually to

i_tot_comp as explained in the link and create a dynamic structure and table.

4 REPLIES 4

Former Member
0 Kudos

Hi,

You can achieve this with RTTS classes... mainly CL_ABAP_TYPEDESCR, CL_ABAP_STRUCDESCR & CL_ABAP_TABLEDESCR... There are a lot of examples on how to use them here or on the web.

Get back if you're still stuck

Kr,

Manu.

kesavadas_thekkillath
Active Contributor
0 Kudos

You can view this thread where our friend Marcin rocks ..


FIELD-SYMBOLS: <gt_data> TYPE ANY TABLE.
FIELD-SYMBOLS: <gs_wa> TYPE ANY.
data:wf_ref type ref to data.
DATA:i_comp TYPE cl_abap_structdescr=>component_table,
     i_tot_comp TYPE cl_abap_structdescr=>component_table.

CREATE DATA gr_data TYPE TABLE OF (p_table).
ASSIGN gr_data-* TO <gt_data>.
create data wf_ref like line of <gt_data>.
assign wf_ref->* to <gs_wa>.

*--Getting Compoents from existing type
  lf_struct ?= cl_abap_typedescr=>describe_by_name( '<GS_WA>' ).
  i_comp = lf_struct->get_components( ).
  APPEND LINES OF i_comp TO i_tot_comp.

The idea is Get all the field details available it to i_tot_comp, then append individual fields manually to

i_tot_comp as explained in the link and create a dynamic structure and table.

rajeevgoswami1
Participant
0 Kudos

Hi ,

for wa add the following code

declare a field symbol

FIELD-SYMBOLS: <fs_itab_line> TYPE ANY.

*create one data refrence

data: obj_itab_line TYPE REF TO data.

*wa instance

CREATE DATA:obj_itab_line TYPE (p_tab).

*assigne FS to wa instance

ASSIGN obj_itab_line->* TO <fs_itab_line>.

now this <fs_itab_line> will refer to wa of table which is entered in parameter.

I hope this will solve ur problem. if any issue please let me know..

Rajeev Goswami

Former Member
0 Kudos

Try ...............

data: obj TYPE REF TO data.

PARAMETERS: p_table TYPE tabname.

CREATE DATA:obj TYPE (p_table).

TYPES: BEGIN OF type_test,

struct like obj,

fld1 TYPE c,

fld2 TYPE n,

END OF type_test.