04-08-2010 12:47 PM
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
04-08-2010 12:51 PM
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>
04-08-2010 12:53 PM
04-08-2010 2:15 PM
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
04-08-2010 1:01 PM
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>.
04-08-2010 8:16 PM
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