Several ways to create a dynamic within the table
The principle
- RTTS obtained by function or structure to components of the information, and implement the use of cl_alv_table_create
- OO RTTS obtained by the described configuration of the object, obtained by the table reference reflection
- Table name or a known structure, defined by a variable reference direct
NOTE :
an RTTS assembly can acquire corresponding information through an existing variable names or structures
can save a lot of code embedded by declaration (inline declaration)
custom dynamic table assembly can be achieved by deletions
For two chestnuts
1, reflection
data:lr_struct type ref to data,
lr_table type REF TO data.
field-symbols:<fs_table> type any table,
<fs_struct> type any.
"RTTS
data(lo_struct) = cast cl_abap_structdescr( cl_abap_structdescr=>describe_by_name( p_tab ) ).
data(lo_table) = cl_abap_tabledescr=>create( lo_struct ).
"反射机制
create data lr_struct type handle lo_struct.
create data lr_table type handle lo_table.
"引用访问
assign lr_struct->* to <fs_struct>.
assign lr_table->* to <fs_table>.
data(lv_where) = 'SPRAS EQ 1'.
select *
from (p_tab)
into table @<fs_table>
up to 10 rows
where (lv_where) .
cl_demo_output=>display_data( <fs_table> ).
- Simple way
data:ref_table type ref to data.
data:lv_where type string.
field-symbols:<fs_table> type any table.
parameters:p_tab type dd02l-tabname obligatory default 'TJ02T'.
"创建表
create data ref_table type table of (p_tab).
assign ref_table->* to <fs_table>.
lv_where = 'SPRAS EQ 1'.
select *
from (p_tab)
into table @<fs_table>
UP TO 10 ROWS
where (lv_where) .
cl_demo_output=>display_data( <fs_table> ).