‎2011 Jul 07 3:44 PM
Hi,
I create structure dynamically, but when I try to make an append (even the initial line), I get TSV_ILLEGAL_REFERENCE dump.
Here is my code:
data: lr_strucdesc TYPE REF TO CL_ABAP_STRUCTDESCR,
dref TYPE REF TO DATA,
lr_strucdesc ?= cl_abap_typedescr=>describe_by_name( 'ZAK_STAT_DEF' ).
CREATE DATA dref TYPE HANDLE lr_strucdesc.
FIELD-SYMBOLS: <fs_table> TYPE INDEX TABLE.
ASSIGN dref->* TO <fs_table> CASTING TYPE HANDLE lr_strucdesc.
APPEND INITIAL LINE TO <fs_table>. " << dump is here
Any help appreciated!
Best regards,
Anton.
‎2011 Jul 07 5:35 PM
> I create structure dynamically, but when I try to make an append (even the initial line), I get TSV_ILLEGAL_REFERENCE dump.
.
Here lies the issue, you are trying to append a record(initial) to a structure! the 'CASTING' addition doesn't help you to create a table out of a structure, extract from F1 help of 'CASTING' addition of 'ASSIGN' statement says:
"The specified data type must match the generic typing of the field symbol, which means that the casting may specialize the generic typing, but not generalize it"
Solution : create a dynamic table from the dynamic structure and append(initial) record to the dynamic table instead... how to create dynamic table? check the documentation of the method 'CREATE' of the class 'CL_ABAP_TABLEDESCR' or search the forum with the keyword "CL_ABAP_TABLEDESCR=>CREATE"
-Rajesh.
‎2011 Jul 07 5:35 PM
> I create structure dynamically, but when I try to make an append (even the initial line), I get TSV_ILLEGAL_REFERENCE dump.
.
Here lies the issue, you are trying to append a record(initial) to a structure! the 'CASTING' addition doesn't help you to create a table out of a structure, extract from F1 help of 'CASTING' addition of 'ASSIGN' statement says:
"The specified data type must match the generic typing of the field symbol, which means that the casting may specialize the generic typing, but not generalize it"
Solution : create a dynamic table from the dynamic structure and append(initial) record to the dynamic table instead... how to create dynamic table? check the documentation of the method 'CREATE' of the class 'CL_ABAP_TABLEDESCR' or search the forum with the keyword "CL_ABAP_TABLEDESCR=>CREATE"
-Rajesh.
‎2011 Jul 08 9:02 AM
Hello, Rajesh.
I suspected that problem was somewhere in my understanding of principles. Thank you for your answer, problem is solved now.
Here is the solution code:
data: lr_strucdesc TYPE REF TO CL_ABAP_STRUCTDESCR,
lr_tableref TYPE REF TO CL_ABAP_TABLEDESCR,
dref TYPE REF TO DATA,
linetype TYPE REF TO CL_ABAP_STRUCTDESCR,
comp_tab TYPE cl_abap_structdescr=>component_table.
FIELD-SYMBOLS: <fs_table> TYPE INDEX TABLE.
lr_strucdesc ?= cl_abap_typedescr=>describe_by_name( 'ZAK_STAT_DEF' ).
comp_tab = lr_strucdesc->get_components( ).
linetype = cl_abap_structdescr=>create( comp_tab ).
lr_tableref = cl_abap_tabledescr=>create(
p_line_type = linetype
p_table_kind = cl_abap_tabledescr=>tablekind_std
).
CREATE DATA dref TYPE HANDLE lr_tableref.
ASSIGN dref->* TO <fs_table>.
APPEND INITIAL LINE TO <fs_table>.