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

Read internal table in reverse order

Former Member
0 Likes
4,887

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

4 REPLIES 4
Read only

Former Member
0 Likes
1,935

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

Read only

Former Member
0 Likes
1,935

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

Read only

Former Member
0 Likes
1,935

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.

Read only

0 Likes
1,935

was your code different than the above 2?