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 variable with dynamic type

Former Member
0 Kudos

Hi,

how can i create dynamically a variable with a dynamic type. i know i can use the following instruction but my problem is too instantiate the TYPE.

CREATE DATA dref TYPE HANDLE struct_type.

For example i would like to create a new data with type P0001 (HR structure).

Thanks for your help.

Cheers

5 REPLIES 5

SuhaSaha
Advisor
Advisor
0 Kudos

Why do you use TYPE HANDLE for structure ?

You should use TYPE or TYPE TABLE to create data & then dereference it to a field symbol.

CREATE DATA dref TYPE struct_type.

ASSIGN dref->* TO <fs>

Former Member
0 Kudos

Ok, thanks but the struct_type must be dynamical.

0 Kudos

Hello Tora Tora,

You structure is dynamic then you can use dynamic tokens for it :

DATA:
V_STRUC TYPE STRUKNAME,
DREF TYPE DATA.

FIELD-SYMBOL:
<TAB> TYPE STANDARD TABLE,
<WA> TYPE ANY.

V_STRUC = 'PA0001'.

CREATE DATA DREF TYPE STANDARD TABLE OF (V_STRUC).
ASSIGN DREF->* TO <TAB>.
CLEAR DREF.

CREATE DATA DREF TYPE (V_STRUC).
ASSIGN DREF->* TO <WA>.
CLEAR DREF.

BR,

Suhas

satyajit_mohapatra
Active Contributor
0 Kudos

You can use a field catalog instead of any specific structure, while creating the dynamic internal table . The field catalog types can be modified as per logic/conditions.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = it_fldcat

importing

ep_table = new_table.

assign new_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data new_line like line of <dyn_table>.

assign new_line->* to <dyn_wa>.

Subhankar
Active Contributor
0 Kudos

Hi,

You can do this in different ways

1. if you know the structure name (i.e. mara or marc etc,)

directly you can create the internam table.

data: l_struc tyepe tabname value 'MARA'. -


> This can be changed as per your requirement

l_data tyepe ref to data.

field-symbols: <itab> type any table.

create data l_data type standard table of (l_struct).

assign l_data->* to <itab>.

2. If the structure you need to build programaically then you can do this using RTTS or creating field catalog then calling normal method cl_alv_table_create=>create_dynamic_table to create the dynamic table.

Thanks

Subhankar

Edited by: Subhankar Garani on Apr 8, 2010 9:17 PM