ABAP dynamic in the table

Several ways to create a dynamic within the table

The principle

  1. RTTS obtained by function or structure to components of the information, and implement the use of cl_alv_table_create
  2. OO RTTS obtained by the described configuration of the object, obtained by the table reference reflection
  3. 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> ).
  1. 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> ).

Guess you like

Origin blog.csdn.net/u012232542/article/details/92799641