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

internal table

Former Member
0 Likes
710

Hi,

Anybody can tell me, "How do we get the number of lines in an internal table?"

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
688

Hi,

Use describe statement

describe table itab lines w_int.

in w_int will contain no. of lines.

Plzz reward points if it helps.

9 REPLIES 9
Read only

gopi_narendra
Active Contributor
0 Likes
688
data : N type I.
describe table ITAB lines N. " N gives the no of records of itab

Regards

Gopi

Read only

Former Member
0 Likes
689

Hi,

Use describe statement

describe table itab lines w_int.

in w_int will contain no. of lines.

Plzz reward points if it helps.

Read only

Former Member
0 Likes
688

Hi,

This can be done in several ways. But the latest and simple way is as follows.

DATA : BEGIN OF str_test,

n1 TYPE i,

n2 TYPE i,

END OF str_test.

DATA : itab LIKE STANDARD TABLE OF str_test WITH HEADER LINE.

DO 10 TIMES.

CLEAR str_test.

str_test-n1 = sy-index.

str_test-n2 = sy-index * 2.

APPEND str_test TO itab.

ENDDO.

IF LINES( itab ) ne 0.

LOOP AT itab.

WRITE 😕 itab-n1, itab-n2.

ENDLOOP.

ENDIF.

Simple code is : Lines(<table name>) gives number of lines in internal table.

All the very best to you.

Read only

Former Member
0 Likes
688

Hi Ravi,

Just include the field SY-TABIX in your Write statement for the internal table. This should help you in achieving the no. of records.

Reward points if useful,

Regards,

Bhavin P Shah

Read only

Former Member
0 Likes
688

by using sy-dbcnt we can find the total number of records in the internal table.

Read only

Former Member
0 Likes
688

hi,

report zsample.

tables:mara.

data:itab like mara occurs 0 with header line.

data:v_lines type i.

select-options :s_matnr for mara-matnr.

start-of-selection.

select * from mara into table itab where matnr in s_matnr.

clear v_lines.

if sy-subrc = 0.

describe table itab lines v_lines.

write: v_lines , 'No of records in internal table for the given range'.

endif.

Regds

Sivaparvathi

Please reward points if helpful..

Read only

Former Member
0 Likes
688

Hi ,

Internal table in ABAP

*An internal table is a run time instance. It get created when program starts execution.

*It get destroyed when program terminates. it has two different parts. HeaderLine(optional) & Body(Compulsory).

*Any value that comes to or goes from interanal table , that travels through headerline.\

*A related program is .

*declaration.

data: begin of inernaltable occurs 0,

x type c,

y type i,

end of itab.

*initializing headerline

internaltable-x = 'd'.

internaltable-y = 34.

*storing value into internal table

appene internaltable .

appene internaltable .

appene internaltable .

*reading internal table

loop at itab .

write: / internaltable-x, internaltable-y. "writes to output list

endloop.

Fields of Internal Tables

SY-TABIX

Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.

APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.

COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.

LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.

READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.

SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.

SY-TFILL

After the statements DESCRIBE TABLE, LOOP AT, and READ TABLE, SY-TFILL contains the number of lines in the relevant internal table.

SY-TLENG

After the statements DESCRIBE TABLE, LOOP AT, and READ TABLE, SY-TLENG contains the length of the lines in the relevant internal table.

SY-TOCCU

After the statements DESCRIBE TABLE, LOOP AT, and READ TABLE, SY-TLENG contains the initial amount of memory allocated to the relevant internal table.

Reward Points if it is usefull ...

Girish

Read only

Former Member
0 Likes
688

u can use a system field sy-tabix

the value of which which will give u the no of lines in the internal table

Read only

Former Member
0 Likes
688

U can use the describe statement as said above

or u can run the loop and after the execution of the loop

SY-DBCNT will give the no. of times theloop is executed or the No. of lines.

Reward points if found usefull.