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

TSV_ILLEGAL_REFERENCE while trying to append to dynamic structure

Former Member
0 Likes
742

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.

1 ACCEPTED SOLUTION
Read only

rajesh_paruchuru
Active Participant
0 Likes
598

> 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.

2 REPLIES 2
Read only

rajesh_paruchuru
Active Participant
0 Likes
599

> 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.

Read only

0 Likes
598

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>.