‎2007 Dec 06 11:12 AM
Hey,
I made a dynamic table and now I want to loop this table.
But I can't seem to make a structure to use in the loop.
I get the error 'data object has no structure'.
This is what I already have.
data: linetype type ref to cl_abap_structdescr,
tabletype type ref to cl_abap_tabledescr,
lt_comp type cl_abap_structdescr=>component_table,
lr_table type ref to data,
lr_line type ref to data.
field-symbols: <lt_data> type table,
<ls_data> type any.
...first I fill lt_comp ...
linetype = cl_abap_structdescr=>create( lt_comp ).
tabletype = cl_abap_tabledescr=>create( p_line_type = linetype p_table_kind = 'S' ).
create data lr_table type handle tabletype.
assign lr_table->* to <lt_data> casting type handle tabletype.
create data lr_line like line of <lt_data>.
assign lr_line->* to <ls_data> casting type handle linetype.
... filling the table <lt_data> ....
loop at lt_data assigning <ls_data>.
... when I try to access a field of <ls_data>, I get the error '<ls_data> is no structure'.
endloop.
‎2007 Dec 06 7:53 PM
Hello Steven
If you are going for dynamic programming then you have to use "the full monty" meaning field-symbols for:
- itab
- structure AND
- fields
FIELD-SYMBOLS:
<ld_fld> TYPE any.
LOOP AT <lt_data> ASSIGNING <ls_data>.
UNASSIGN <ld_fld>.
ASSIGN COMPONENT '<name of field OR sy-index>' OF STRUCTURE <ls_data>
TO <ld_fld>.
IF ( <ld_fld> IS ASSIGNED ).
" do something...
ENDIF.
ENDLOOP.
...Regards,
Uwe
‎2007 Dec 06 7:53 PM
Hello Steven
If you are going for dynamic programming then you have to use "the full monty" meaning field-symbols for:
- itab
- structure AND
- fields
FIELD-SYMBOLS:
<ld_fld> TYPE any.
LOOP AT <lt_data> ASSIGNING <ls_data>.
UNASSIGN <ld_fld>.
ASSIGN COMPONENT '<name of field OR sy-index>' OF STRUCTURE <ls_data>
TO <ld_fld>.
IF ( <ld_fld> IS ASSIGNED ).
" do something...
ENDIF.
ENDLOOP.
...Regards,
Uwe
‎2007 Dec 07 9:08 AM