‎2008 Oct 28 10:04 PM
Hi,
I have got a problem. This may be very simple for you guys but just wanted to know how do I read internal table in reverse order.
eg. Internal table holds values 05,01,03 then I want to read them as 03,01,05.
Regards,
Murtuza Kharodawala
‎2008 Oct 28 10:24 PM
Like this?
REPORT ztest LINE-SIZE 80 MESSAGE-ID 00.
DATA: BEGIN OF itab OCCURS 0,
f1(02),
END OF itab.
DATA no_lines TYPE sy-tabix.
MOVE: '05' TO itab-f1.
APPEND itab.
MOVE: '01' TO itab-f1.
APPEND itab.
MOVE: '03' TO itab-f1.
APPEND itab.
DESCRIBE TABLE itab LINES no_lines.
DO.
READ TABLE itab INDEX no_lines.
WRITE: /001 itab-f1.
no_lines = no_lines - 1.
IF no_lines < 1.
EXIT.
ENDIF.
ENDDO.Rob
‎2008 Oct 28 10:24 PM
Read rows in reverse order? or columns in reverse?
find the total # of records in the table using describe
then use
do
read table itab index id1
id1 = id1 - 1.
if id1 = 0. exit. endif.
end do
‎2008 Oct 28 10:34 PM
Hi,
Consider the following code:
Data: v_cntr type i.
Data: v_lines type i.
* use describe to get the number of records in internal table
Describe table itab lines v_lines.
v_cntr = v_lines.
do v_lines times.
check v_cntr > 0. "not really needed
read table itab into wa index v_cntr.
* do the further operation here with wa...
* you must not delete any record from itab here.If you do, this code gives a dump
v_cntr = v_cntr - 1.
enddo.
Regards,
Prasad.
‎2008 Oct 28 10:35 PM