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: 

regarding looping of a table

Former Member
0 Kudos

how can we loop a table with respect to the index values of the table i want to loop the table upto an index 5 how can i do it.

thanks in advance

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi



Loop at table into fieldstring.

   your code

if sy-index eq 5.
  exit.
endif.

endloop.

7 REPLIES 7

Former Member
0 Kudos

Hi



Loop at table into fieldstring.

   your code

if sy-index eq 5.
  exit.
endif.

endloop.

Former Member
0 Kudos

loop at git_itab from 1 to 5.

endloop

or

loop at git_itab to 5.

endloop

Edited by: Amit Gupta on Oct 8, 2008 11:40 AM

Former Member
0 Kudos
.. LOOP AT inttab 
INTO wa_inttab 
WHERE table_line <  5 . 
 {... }
ENDLOOP. .

0 Kudos

>

>

.. LOOP AT inttab 
> INTO wa_inttab 
> WHERE table_line <  5 . 
>  {... }
> ENDLOOP. .

Are you sure this is going to work?

Former Member
0 Kudos

hi abhinay,

LOOP AT <itab> [INTO <wa>]

[FROM <n1>] [TO <n2>]

[WHERE <condition>].

where n1 and n2 are index.

hope it may help u.

thanks

Sachin

satsrockford
Active Participant
0 Kudos

hi

Sample Code:

READ TABLE T_MARC1 INTO WA_MARC WITH KEY WERKS = P_WERKS.

IF SY-SUBRC EQ 0.

L_TABIX = SY-TABIX + 1.

ADD 1 TO COUNT.

LOOP AT T_MARC1 INTO WA_MARC FROM L_TABIX.

IF WA_MARC-WERKS NE P_WERKS.

EXIT.

ENDIF.

ADD 1 TO COUNT.

ENDLOOP.

ENDIF.

If you look at the above code, first we read the record which appears first in the list of records, hence the index of that entry is stored in a local variable, further records can be read using index from loop which is very fast in access.

regards

Satish

Former Member
0 Kudos

Hi Abhinay,

Try this code :

Loop at itab into wa.

     if sy-tabix eq 5.

          exit.

     else.

           <paste your code here>
     endif.

endloop.

This will solve.

Regards,

Swapna.