# Fetch fields from table or structure in ABAP SAP

SAP HANASAPSAP Basis

#### SAP ALE IDoc

15 Lectures 1.5 hours

#### SAP MM (Materials Management) Certification Training

Best Seller

43 Lectures 33.5 hours

#### Learn SAP ABAP A to Z - Practical Training

42 Lectures 5.5 hours

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'
Updated on 14-Feb-2020 10:07:18