01-24-2009 4:54 AM
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
01-25-2009 10:48 PM
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( ).
01-24-2009 5:01 AM
01-24-2009 5:16 AM
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
01-25-2009 10:48 PM
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( ).
01-26-2009 4:59 AM
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