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

loop counter

Former Member
30,102

in which system variable loop counter store

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
10,372

Hi Swathi..

incase of DO loop or WHILE loop. the loop counter is stored in SY-INDEX.

incase of internal table Loop. EndLoop the counter is stored in SY-TABIX.

<b>REWARD IF HELPFUL</b>

6 REPLIES 6
Read only

Former Member
0 Likes
10,372

use sy-tabix, or u can use sy-loopc.

Read only

Former Member
0 Likes
10,372

Hi,

In LOOP AT IT_TABLE into wa_table, loop counter store in SY-TABIX.

But in Do n Times loop, it strore in SY-INDEX.

Regards,

Read only

varma_narayana
Active Contributor
10,373

Hi Swathi..

incase of DO loop or WHILE loop. the loop counter is stored in SY-INDEX.

incase of internal table Loop. EndLoop the counter is stored in SY-TABIX.

<b>REWARD IF HELPFUL</b>

Read only

10,372

This is not working if there is a condition in your loop!

SY-TABIX is the index of the internal table

So it will show you in which line you are but this is definietly not a counter.

In this case you will have to create a counter manually.

Regards,

Read only

Former Member
10,372

Hi Swathi,

The system structure have two variables sy-tabix and sy-index.

The variable sy-tabix, for the internal tables operations. This variable holds the number of the record currently being read in an internal table loop.

When a loop statement is executed, the system assigns value 1 for the first iteration and increases it for each new record. If we use any READ statement inside the LOOP, then the successfull READ operation changes the value of sy-tabix to the position of the required record in the read table..

The variable sy-index is used for the iterative operations.

This variable holds the current iteration number in a WHILE or DO loop.

Thanks and Best Regards,

Vikas Bittera.

***Points for usefull answers ***

Read only

0 Likes
6,153

This is wrong!!!

If you have a loop with a where condition  -> Your first hit in sy-tabix can by anything

lets asume you habe an internal table:

row 1 = value A
row 2 = value B
row 3 = value C

If your code is:
loop at internal_table
where value = 'B'

--> sy-tabix will be 2!!!!!

so you cannot use this as an loop count