‎2008 Jul 29 12:12 PM
Is there any way to find out the number of fields in a structure or an internal table?
‎2008 Jul 29 12:15 PM
‎2008 Jul 29 12:42 PM
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
‎2008 Jul 29 12:59 PM
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( ).
‎2008 Jul 29 5:16 PM
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
‎2008 Jul 29 5:38 PM
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.