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: 

want last record in internal table

Former Member

Hi All,

I have two internal table. in one internal table all data are available. now i want last record on first internal table and store in second internal table.... so give me some logic or sample code......

Thanks

zeni

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Zeni,

Try the following:

First find the number of records in the first internal table itab1 using

DESCRIBE TABLE itab1 LINES w_lines.

Now read the first internal table :

read table itab1 index w_lines.

Now append the record from itab1 to itab2.

append fs_itab1 to itab2.

Hope this helps you.

Regards,

Chandra Sekhar

Edited by: Chandrasekhar Gandla on Jul 14, 2008 7:48 PM

11 REPLIES 11

Former Member
0 Kudos

Hi,

describe table itab1 lines ws_lines.

read table itab1 into ws_itab1 index ws_lines.

ws_itab2 = ws_itab1.

append ws_itab2 to itab2.

Regards,

Subramanian

Former Member

lets have itab1 as the internal table


DATA: N    TYPE I.


DESCRIBE TABLE ITAB1 LINES N. 

read table itab1 index N.

this will read the last row of itab1...

Hope this helps

Cheers

Kothand

Former Member
0 Kudos

Use DESCRIBE TABLE itab LINES n statment, which is return no of lines 'n' in internal table.

Use 'READ' statment with index 'n'. will get the last record in first internal table and append that record to second internal table.

Regards,

Soujanya

Former Member
0 Kudos

Hi Zeni,

Try the following:

First find the number of records in the first internal table itab1 using

DESCRIBE TABLE itab1 LINES w_lines.

Now read the first internal table :

read table itab1 index w_lines.

Now append the record from itab1 to itab2.

append fs_itab1 to itab2.

Hope this helps you.

Regards,

Chandra Sekhar

Edited by: Chandrasekhar Gandla on Jul 14, 2008 7:48 PM

0 Kudos

Hi All,

Thanks i solved my problem.........

i assign point also......

Thanks

zeni

Former Member
0 Kudos

get the latest record from an internal table.

if you are using function module RH_READ_INFTY_1001 then <itab

> will always contain all the records betweebn specified period (taken from selection screen), but to retrieve the latest, sort the records by ENDDA and you will get it on top, then use INDEX 1 for that record only, and store the record in a <work_area>, finally get that record from <work_area> to <itab> it self. thats way your <itab> will hold only latest record.

(you can store <work_area> in <work_area_2> and then pass the record in to <itab>

or, you can store the <work_area> to a different <itab_2>).

 

   call function RH_READ_INFTY_1001

   tables
      i1001         = it_hrp1001

  sort  it_hrp1001 by endda descending.
  read table it_hrp1001 into wa_hrp1001 INDEX 1.
  refresh it_hrp1001.
  append wa_hrp1001 to it_hrp1001.

Former Member
0 Kudos

Hi Zenithi,

Please refer the below code.

DATA : lv_line TYPE i.

DESCRIBE TABLE itab1 INTO lv_line.

READ TABLE itab1 ASSIGNING <fs_itab1> INDEX lv_line.

APPEND <fs_itab1> TO itab2.

Hope this will work..

Thanks,

Supratik

Former Member
0 Kudos

Thanks to all...even i was having same requirement.

its working perfactly..

MattHarding
Active Contributor

BTW - In more recent ABAP versions, you can do this to get the last record:


read table itab1 index lines( itab1 ).

Hi Matt,

How about this : wa = itab[ lines( itab ) ].

I have not checked the above yet, but for ex: wa = itab[ 4 ] works.

🙂

Kesav

Indeed this works on modern ABAP 7.4 or greater.

DATA(wa) = itab[ lines( itab ) ].