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: 

Dynamic structure and Internal table error

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

In your case, you must use :

columntype ?= cl_abap_typedescr=>describe_by_DATA( lv_status ).

instead of DESCRIBE_BY_NAME (because this last takes the type contained in variable lv_status, but it's space here).

You may also use:

comp-type ?= cl_abap_elemdescr=>get_string( ).

4 REPLIES 4

Former Member
0 Kudos

Hi,

Refer to this link...

0 Kudos

HI Avinash,

Thanks for your prompt reply.

I am little bit confused as I am unable to get the appropriate information to my question.

Can you please give the information about the error which i am getting rather some links.

All the links talks about the ALV and its field catalog which does not suit the requirement.

Awaiting your precious reply.

Regards,

Shashikanth. D

Sandra_Rossi
Active Contributor
0 Kudos

In your case, you must use :

columntype ?= cl_abap_typedescr=>describe_by_DATA( lv_status ).

instead of DESCRIBE_BY_NAME (because this last takes the type contained in variable lv_status, but it's space here).

You may also use:

comp-type ?= cl_abap_elemdescr=>get_string( ).

uwe_schieferstein
Active Contributor
0 Kudos

Hello

You may have a look at my Wiki posting

[Creating Flat and Complex Internal Tables Dynamically using RTTI |https://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI]

Regards

Uwe