Search code examples
abapsap-data-dictionary

Number of fields in a structure


I'm looking for the Number of fields of a table or structure. Any suggestion please


Solution

  • For counting the components of a structure, better use RTTS as we don't want to access the database for result we already have in our environment.

    DATA(lwa_struct) = VALUE kna1( ). " your structure e.g. kna1
    
    DATA(lo_descr) = CAST cl_abap_structdescr( cl_abap_datadescr=>describe_by_data( lwa_struct ) ).
    
    DATA(lw_all_fields) = LINES( lo_descr->components ). " => 184