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

Doubt in internal table

Former Member
0 Likes
1,093

Hi,

I have internal table with 5 records. I want to separate out the last record in the internal table.

For ex : itab contains,

12,

10,

15,

09,

13 . i need the last record '13' only. how to fetch the last record from the internal table, i no need the other records.

point will be sure.

Gowri

10 REPLIES 10
Read only

Former Member
0 Likes
1,073

DESCRIBE ITAB LINES w_lines.

READ TABLE ITAB index w_lines.

It will give you the last record of internal table ITAB.

Read only

Former Member
0 Likes
1,073

can any one plz give soln.

point will be sure.

Gowri

Read only

Former Member
0 Likes
1,073

Hi Gowri,

once the full data is in itab.

 describe table itab lines gv_lines.

 read table itab into wa index gv_lines.

 if sy-subrc = 0.
  delete itab.
 endif.

 append wa to itab.

<b>Reward points for helpful answers</b>.

Satish

Read only

former_member386202
Active Contributor
0 Likes
1,073

Hi,

Use describe statement to count the records from internal table, store that value into one variable and read the data from internal table using index.

Give index as a variable.

Regards,

Prashant

Read only

Former Member
0 Likes
1,073

hi gowri,

when u use the describe statement the index is at the last line of the internal table.

describe table itab lines l.

read table itab into wa index l.

append wa to itab.

now the itab will have only 1 row that is the last row of the contents it previously had...

hope this will help you.

regards,

sohi

Read only

Former Member
0 Likes
1,073

hi gowri

do it:

read table itab.

read table itab index SY-TFILL.

Regards

Allan Cristian

Read only

Former Member
0 Likes
1,073

Hi Gowri,

for your query use the following code:

data: count type i value 0.

Describe itab lines n.

Do.

if ( count < n ).

delete itab index count.

else.

exit.

endif.

endo.

Reward if useful.

Regards,

Shilpi

Read only

Former Member
0 Likes
1,073

Hi,

try this simle code:

DATA: BEGIN OF ITAB OCCURS 0,

N2(2) TYPE N,

END OF ITAB.

*

DATA: LINE_ITAB LIKE SY-TABIX.

*

START-OF-SELECTION.

*

ITAB-N2 = '12'. APPEND ITAB.

ITAB-N2 = '10'. APPEND ITAB.

ITAB-N2 = '15'. APPEND ITAB.

ITAB-N2 = '09'. APPEND ITAB.

ITAB-N2 = '13'. APPEND ITAB.

*

CLEAR: ITAB.

DESCRIBE TABLE ITAB LINES LINE_ITAB.

*

READ TABLE ITAB INDEX LINE_ITAB.

*

WRITE: / ITAB-N2.

*

Regards, Dieter

Read only

Former Member
0 Likes
1,073

<b>data v_lin type i.

describe table itab lines v_lin.

read table itab index v_lin.

loop at itab.

if not sy-tabix eq v_lin.

DELETE ITAB INDEX SY-TABIX.

endif.

endloop.</b>

Read only

rodrigo_paisante3
Active Contributor
0 Likes
1,073

Hi,

Create another table like that you are using -> itab2.

sort itab1 descending by field.

read table itab1 index 1 into wa.

append wa into itab2.

You will sort the table descending, then the first record was the last. Just read the table and append to the other table. Then you will have only the last record from the first table.

Regards.