Application Development 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: 

CL_ABAP_TABLEDESCR

Former Member
0 Kudos

How can I use this class to retrieve the number of

records an internal table contains?

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

I think finding number of records in a itab using this class is not possible.

If you want find the number of fields in an itab then


g_tabledescr type ref to cl_abap_tabledescr,
g_tabledescr ?= cl_abap_tabledescr=>describe_by_data( itab ).

But you can try this way


v_lines = lines( ltab ).

5 REPLIES 5

Former Member
0 Kudos

Hello,

I don't know if it's possible to recover the number of records of an internal table using this class, but I suggest you to use the function LINES( itab ) to do this.

Regards.

Former Member
0 Kudos

hi,

You can do this way ..


data : v_lines type i.

 describe itab lines v_lines.
 write v_lines.

former_member194669
Active Contributor
0 Kudos

I think finding number of records in a itab using this class is not possible.

If you want find the number of fields in an itab then


g_tabledescr type ref to cl_abap_tabledescr,
g_tabledescr ?= cl_abap_tabledescr=>describe_by_data( itab ).

But you can try this way


v_lines = lines( ltab ).

0 Kudos

A small correction to this..

If itab is a table with header line,

g_tabledescr type ref to cl_abap_tabledescr,
g_tabledescr ?= cl_abap_tabledescr=>describe_by_data( itab ).

will raise cx_sy_move_cast_error because it returns cl_abap_structdescr instance.

It should be

g_tabledescr type ref to cl_abap_tabledescr,
g_tabledescr ?= cl_abap_tabledescr=>describe_by_data( itab[] ).

G@urav.

0 Kudos

Gaurav,

Thanks for pointing out the correction