‎2006 Aug 29 8:06 AM
Hi all,
i have 10 records in an internal table which i need to output in the reverse order.how to do it?
‎2006 Aug 29 8:13 AM
Hi
Sort Itab descending.
loop at itab.
write 😕 itab.
endloop.
Regards,
Senthil
‎2006 Aug 29 8:10 AM
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
‎2006 Aug 29 8:11 AM
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.
‎2006 Aug 29 8:13 AM
Hi
Sort Itab descending.
loop at itab.
write 😕 itab.
endloop.
Regards,
Senthil
‎2006 Aug 29 8:44 AM
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.
‎2006 Aug 29 10:33 AM
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,