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 tables

Former Member
0 Likes
751

Hi all,

i have 10 records in an internal table which i need to output in the reverse order.how to do it?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
725

Hi

Sort Itab descending.

loop at itab.

write 😕 itab.

endloop.

Regards,

Senthil

5 REPLIES 5
Read only

naimesh_patel
Active Contributor
0 Likes
725

Hello.

Option 1:

Take one field and put the index number in it and sort on that field

like:

itab-index = 1.

itab-index = 2.

.

.

sort itab by index decending.

then write.

option 2:

l_cnt = 10.

do.

read table itab index l_cnt.

write itab.

l_cnt = l_cnt - 1.

if l_cnt = 0.

exit.

endif.

enddo.

regards,

Naimesh

Read only

Former Member
0 Likes
725

describe table itab line v_lines.

loop at itab.
 if v_lines GE 1.
 read table itab index v_lines.
 write : /itab-field1.
 v_lines = v_lines - 1.
 endif.
endloop.

Read only

Former Member
0 Likes
726

Hi

Sort Itab descending.

loop at itab.

write 😕 itab.

endloop.

Regards,

Senthil

Read only

Former Member
0 Likes
725

There are many ways to resolve the issue ...either to sort all fields in descending order OR have a index field OR the below logic.

describe table itab lines lrec.

do lrec times.

lindx = lrec + 1 - sy-index.

read table itab index lindx.

write : / itab-fields.

enddo.

Read only

Former Member
0 Likes
725

Hi,

if the internal table needs to be sorted based on a particula field.

<b>sort itab by field-name descending.</b>

If the internal table needs to be sorted based on the way that it get populated,

data: begin of itab occurs 0,

index type i value 0,

text(10),

end of itab.

itab-index = itab-index + 1.

itab-text = 'c'.

append itab.

itab-index = itab-index + 1.

itab-text = 'a'.

append itab.

itab-index = itab-index + 1.

itab-text = 'b'.

append itab.

sort itab by index descending.

Thanks & Regards,