Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Total fields in a structure

former_member654348
Participant
0 Likes
1,038

Is there any way to find out the number of fields in a structure or an internal table?

5 REPLIES 5
Read only

Former Member
0 Likes
944

Check out the below related thread

Read only

prasanth_kasturi
Active Contributor
0 Likes
944

hi,

try using the FM 'GET_COMPONENT_LIST'.

TABLES zpcust.

DATA:

no_fields TYPE i,

BEGIN OF field OCCURS 0,

no LIKE rstrucinfo,

END OF field.

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = sy-repid

fieldname = 'ZPCUST'

TABLES

components = field.

DESCRIBE TABLE field LINES fields.

WRITE:/ fields.

for internal table pass the internal table name insted of structure name in above

You can also get the fields info from table DD03L. you can use it also for DDIC structures.

take a itab with a field of type FIELDNAME and in the where condition give the tabname.

and use describe statemnt on this table.

regards

prasanth

Edited by: Prasanth Kasturi on Jul 29, 2008 1:49 PM

Read only

Former Member
0 Likes
944

Try using the RTTI classes CL_ABAP_STRUCTDESCR, CL_ABAP_TABLEDESCR.

Sample code is as below

DATA LT_SFLIGHT TYPE TABLE OF SFLIGHT.

DATA LO_TABLEDESCR TYPE REF TO CL_ABAP_TABLEDESCR.

data lo_structdescr type ref to cl_abap_structdescr.

data lt_components type CL_ABAP_STRUCTDESCR=>component_table.

LO_TABLEDESCR ?= CL_ABAP_TABLEDESCR=>DESCRIBE_BY_DATA( P_DATA = LT_SFLIGHT ).

lo_structdescr ?= lo_tabledescr->GET_TABLE_LINE_TYPE( ).

lt_components = lo_structdescr->get_components( ).

Read only

Former Member
0 Likes
944

Pallavi, the FM 'GET_COMPONENT_LIST' will give you a list of fields of your internal table. No of lines in the COMPONENTS table returned to you will be = no of fields in your internal table.

Cheers,

Harsha Lakshminarayanan

Read only

Former Member
0 Likes
944

you can use this..

REPORT  YTEST_READ.

TYPE-POOLS : abap.
DATA : table_des TYPE REF TO cl_abap_structdescr..

DATA : ifields TYPE abap_compdescr_tab,
       wa_field LIKE LINE OF ifields.

data: v_line type i.


PARAMETERS: p_table(30) type c default 'MARA'.


"Table definiton using the table name
 table_des ?= cl_abap_typedescr=>describe_by_name( p_table ).
"Now Read all the fields to a table.
ifields = table_des->components.


describe table ifields lines v_line.
write v_line.