Skip to Content
0
Former Member
Jan 24, 2009 at 04:54 AM

Dynamic structure and Internal table error

34 Views

Dear All,

I have a requirement of creating a runtime ( dynamic ) strcuture and as well as the Internal table.

Requirement: Need to create a strucutre and internal table at runtime.

Note: I should not use any underlying DB or structure type to create the RT structure or internal table.

For Ex: My strcture should have two columns of type string.

Error information: Exception condition "TYPE_NOT_FOUND" raised

The code written by me as follows:

DATA lv_status TYPE string.

DATA: columntype TYPE REF TO cl_abap_structdescr.

DATA: linetype TYPE REF TO cl_abap_structdescr,

comp_tab TYPE cl_abap_structdescr=>component_table,

comp LIKE LINE OF comp_tab.

<<<<< columntype ?= cl_abap_typedescr=>describe_by_name( lv_status ). " Error is here.

comp-name = 'COLUMN1'.

comp-type = columntype.

APPEND comp TO comp_tab.

comp-name = 'COLUMN2'.

comp-type = columntype.

APPEND comp TO comp_tab.

linetype = cl_abap_structdescr=>create( comp_tab ).

  • dynamic internal table:

DATA: tabletype TYPE REF TO cl_abap_tabledescr,

key TYPE abap_keydescr_tab.

tabletype = cl_abap_tabledescr=>create(

p_line_type = linetype

p_table_kind = cl_abap_tabledescr=>tablekind_std ).

***********************************************************************

FIELD-SYMBOLS : <f_itab> TYPE STANDARD TABLE, " Table type

<f_wa> TYPE ANY, " WA type

<fs> TYPE ANY.

DATA: l_handle TYPE REF TO data.

DATA: l_handle_wa TYPE REF TO data.

TRY.

CREATE DATA l_handle TYPE HANDLE tabletype.

CATCH cx_sy_create_data_error.

ENDTRY.

ASSIGN l_handle->* TO <f_itab>.

TRY.

CREATE DATA l_handle_wa TYPE HANDLE linetype.

CATCH cx_sy_create_data_error.

ENDTRY.

ASSIGN l_handle_wa->* TO <f_wa>.

One more question is will this code work in WD4A? I am trying to write this in WDDOINIT method of the view.

Regards,

Shashikanth. D