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

Dynamic Structure in SE11

Former Member
0 Likes
1,733

Hi,

I want to create a dynamic structure in SE11...I do not want to use BDC...Is there any other Way to create????

Regards

Jiku

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,440

Hi,

You cant create dynamic structures in SE11..Its a global one..

Dynamic in the sense, you need to change the structure according to the requirement and thats done during run time..

You can do it programatically..

declare a structure in SE11 and in your program you can add more fields to that structure in run time..

rewards if useful,

regards,

nazeer

Hi,

I want to create a dynamic structure in SE11...I do not want to use BDC...Is there any other Way to create????

Regards

Jiku

6 REPLIES 6
Read only

Former Member
0 Likes
1,440

Hi, what do you mean by dynamic structure actually?

Read only

0 Likes
1,440

I want to create a structure with my fields programatically...

Read only

Former Member
0 Likes
1,441

Hi,

You cant create dynamic structures in SE11..Its a global one..

Dynamic in the sense, you need to change the structure according to the requirement and thats done during run time..

You can do it programatically..

declare a structure in SE11 and in your program you can add more fields to that structure in run time..

rewards if useful,

regards,

nazeer

Read only

0 Likes
1,440

Is there any FM to create a database table / structure programatically???

Read only

0 Likes
1,440

Hi Jiku,

There are RTTC (Runtime Type Creation) classes which facilitates creation of structures/ internal tables (not db tables) dynamically..

Here is sample code..

DATA vfn_data type ref to data.

DATA: lt_comp_tab TYPE abap_component_tab,

ls_comp TYPE LINE OF abap_component_tab.

DATA: lv_data_descr TYPE REF TO cl_abap_datadescr,

lv_type_descr TYPE REF TO cl_abap_typedescr,

lv_stru_descr TYPE REF TO cl_abap_structdescr.

  • lt_scenario_param is internal table which contains field names (param_id) and corresponding DDIC types (param_type)

LOOP AT lt_scenario_param INTO ls_scenario_param.

lv_data_descr ?= cl_abap_datadescr=>describe_by_name( p_name = ls_scenario_param-param_type ) .

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ls_comp-name = ls_scenario_param-param_id.

ls_comp-type = lv_data_descr.

APPEND ls_comp TO lt_comp_tab.

CLEAR: ls_comp.

ENDLOOP.

*TRY.

lv_stru_descr ?= cl_abap_structdescr=>create( p_components = lt_comp_tab ).

  • CATCH CX_SY_STRUCT_CREATION .

*ENDTRY.

CREATE DATA vfn_data TYPE HANDLE lv_stru_descr.

vfn_data is your dynamic structure!

Dynamic creation of database tables (basically data definition statements) are not possible in SAP.. you need to use data dictionary for this activity (not dynamic!)

Regards,

Abhijit

Read only

0 Likes
1,440

Hi,

You can create a strcutre dynamically as follows.

ls_comp-name = "COMPONENT_NAME.

ls_comp-type = cl_abap_elemdescr=>get_string( ).

APPEND ls_comp TO lt_comp.

*Add as many fields as you want using APPENDS.

DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr.

DATA: lt_comp TYPE cl_abap_structdescr=>component_table.

DATA: ls_comp LIKE LINE OF lt_comp.

CALL METHOD cl_abap_structdescr=>create

EXPORTING

p_components = lt_comp

p_strict = abap_false

RECEIVING

p_result = lr_rtti_struc.

You can create a DATA of that type using the below line.

CREATE DATA lr_data TYPE HANDLE lr_rtti_struc.

But if you know the fields you can as well create using

DATA: Begin of STRUCT,

*Your fields here

DATA: END OF STRUCT.

Regards,

Sesh