If you need to identify the fields and number of fields in a structure, then you should use runtime type services. Using runtime type services makes more sense in this case as if we have some data in our environment, then it’s not ideal to call database for fetching the same.
DATA(structure) = VALUE <your structure>( ) DATA(Descriptor) = CAST cl_abap_structdescr( cl_abap_datadescr=>describe_by_data (structure) ) DATA(Fields = LINES(Descriptor ->components )
This will give you the count of the components of the table or structure.
You can also try another option if you do not want to use runtime type services. Below query can get you’re the count
SELECT COUNT(*) INTO @data(count) FROM DD03l (// this table stores the fields information of SAP tables) WHERE tabname = <Structure name> AND AS4LOCAL = 'A'