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: 

sort internal table in descending order

Former Member
0 Kudos
7,311

hi!

i have an internal table and i want to get the last record as te first record.

how can i do it and not use the sort command since i cant sort the table i nay way that can give me the last record.

regards

yifat

5 REPLIES 5

Former Member
0 Kudos
1,150

Hi Yifat

It's very strange questions?

If you can't sort the table you can't do it, why can't you sort the table?

Max

Former Member
0 Kudos
1,150

hi!

i am using enhancment IQSM0004.

there is an internal table in the component that keeps the serial numbers. every time i add serial number it becomes the last record of the table.

the table is type RIEQUI, but i cant sort it by any field in order to get the last record.

yifat

0 Kudos
1,150

Hi

Use an new internal table with the same structure and sort it.

DATA: MY_RIEQUI LIKE STANDARD TABLE OF RIEQUI WITH HEADER LINE.

MY_REQUI[] = S4_IEQUI[].

SORT MY_REQUI BY <FIELD> DESCENDING.

Max

Former Member
0 Kudos
1,150

Hi Yifat,

Try this logic.. this reverses the table without sorting..

data : itab1 like table of <TABLE>,

itab2 like table of <TABLE>,

lin type i.

......

describe table itab1 lines lin.

if lin ne 0.

read table itab1 index lin.

move itab1 to itab2.

lin = lin - 1.

endif.

regards

satesh

Former Member
0 Kudos
1,150

If you just want the last record, simply get the number of records in the internal table using

<i>"DESCRIBE TABLE itab LINES v_number_of_recs."</i>

and then read the last record using index

<i>READ TABLE itab INDEX v_number_of_lines.</i>