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: 

How to check first and last record of an internal table?

Former Member
0 Kudos
2,266

SAP Gurus,

How to check first and last record of an internal table?

Thanks for the help.

1 ACCEPTED SOLUTION

prasanth_kasturi
Active Contributor
0 Kudos
386

hi

use describe table statemnt and find the total number of lines.

and use this in read table statemnt to find last record

example

take internal table it_mara and two work areas wa_mara and wa_mara1 as work areas

READ TABLE it_mara INTO wa_mara INDEX 1 . ---> first record

data lines type i.

describe table it_mara lines lines.

READ TABLE it_mara INTO wa_mara1 INDEX lines -


> last record

in wa_mara you have first record and wa_mara1 you have last record

regards

prasanth

4 REPLIES 4

prasanth_kasturi
Active Contributor
0 Kudos
387

hi

use describe table statemnt and find the total number of lines.

and use this in read table statemnt to find last record

example

take internal table it_mara and two work areas wa_mara and wa_mara1 as work areas

READ TABLE it_mara INTO wa_mara INDEX 1 . ---> first record

data lines type i.

describe table it_mara lines lines.

READ TABLE it_mara INTO wa_mara1 INDEX lines -


> last record

in wa_mara you have first record and wa_mara1 you have last record

regards

prasanth

Former Member
0 Kudos
386

Hi,

U can do as follows:

After filling ur internal table, use describe lines to get the number of records.Then read table with the indexes.

Describe table it_itab lines lv_lines.

for first record...

read table it_itab index 1.

for the last record...

read table it_itab index lv_lines.

Thanks,

Shailaja

Former Member
0 Kudos
386

Hi,

You can do so as mentioned below :

for first record : read table itab index 1.

for last record :

data : w_lines type i.

Describe table itab lines w_lines.

read table itab index w_lines.

This way you can read the first and last record.

Hope this answers your question.

Regards,

Lalit

Former Member
0 Kudos
386

Hi,

data: tabix like sy-tabix.

Loop the internal table you can find the number of records in sy-tabix.

now use read table it_itab index tabix

now u can compare the first and last records...

+Vamshi+