ABAP dynamically obtains the field list of the inner table

This example is to obtain the field list of the internal table ct_bp_basic. The basic type is the table type. The structure contains include, so it needs to be expanded; if there is no inlcude structure, the second part can be ignored

  data(lo_table_basic) = cast cl_abap_tabledescr( cl_abap_tabledescr=>describe_by_data( ct_bp_basic ) ).
  data(lo_struct_basic) = cast cl_abap_structdescr( lo_table_basic->get_table_line_type( ) ).
  data(lt_component_basic_all) = lo_struct_basic->get_components( ).

  data(lt_component_include) = lt_component_basic_all.
  delete lt_component_include where as_include ne abap_true.
  delete lt_component_basic_all where as_include eq abap_true.

  "展开include结构中
  loop at lt_component_include assigning field-symbol(<fs_component>).
    lo_struct_basic = cast cl_abap_structdescr( <fs_component>-type ).
    data(lt_components) = lo_struct_basic->get_components( ).
    append lines of lt_components to lt_component_basic_all.
  endloop.

Bundled with the method
Insert picture description hereInsert picture description herecode reference for obtaining ABAP dynamic obtaining variable name/text description

METHOD field_get_name.
    DATA:ls_field_descr TYPE sydes_desc,
         lv_name_string TYPE string.

    DESCRIBE FIELD 	i_value INTO ls_field_descr.

    READ TABLE ls_field_descr-names TRANSPORTING NO FIELDS WITH KEY continue = '*'.
    DATA(lv_index) = sy-tabix.

    LOOP AT ls_field_descr-names INTO DATA(ls_name) FROM lv_index.
      lv_name_string = lv_name_string && ls_name-name.
    ENDLOOP.

    SPLIT lv_name_string AT'-' INTO e_structure e_field.
  ENDMETHOD.
method field_get_text.
  data(lo_element_descr) = cast cl_abap_elemdescr( cl_abap_elemdescr=>describe_by_data( I_VALUE ) ).
  data(ls_element) = lo_element_descr->get_ddic_field( p_langu = '1' ).

  e_text = ls_element-fieldtext.
endmethod.

Guess you like

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