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: 

difference b/w sy-index and sy-tabix

Former Member
0 Kudos

hai all,

Could u explain the difference b/w sy-index and sy-tabix?

regards,

Selva

12 REPLIES 12

Former Member
0 Kudos

HI,

SY-TABIX : used for record count of internal tables.

SY-INDEX : used for loop counter.(like do...enddo,while...endwhile,etc..)

sy-tabix is the tab index - the index of the record in the internal table you are accessing, and sy-index is the loop counter.

If you use a condition in LOOP the sy-index will go from 1 to n, but sy-tabix will refer to the line in the internal table. Also, in the case of hash tables, sy-tabix will always be 0.

rgds,

bharat.

Former Member
0 Kudos

HI

sy-index will give Loop Index

sy-tabix will give Index of Internal Tables

SY-TABIX - Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.

  • APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.

  • COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.

  • LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.

  • READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.

  • SEARCH FOR sets SY-TABIX to the index of the table line in which the search string is found.

SY_INDEX - In a DO or WHILE loop, SY-INDEX contains the number of loop passes including the current pass.

Former Member
0 Kudos

hi

sy-index is the index no of the record in an internal table .

and sy-tabix is loop pass counter for an internal table.

Former Member
0 Kudos

Hi,

sy-index - For Loops, Current Loop Pass.

sy-tabix - For Internal Table, Current Line Index in internal table.

sy-tabix is used at internal table operations (READ TABLE ... LOOP AT ...), sy-index is used at cycles (DO...n TIMES).

SY-TABIX:

Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.

it can be set by using the following:

1.append

2.collect

3.loop at

4. read

5.search

APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.

COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.

LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.

READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.

SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.

SY-INDEX:

SY-INDEX is used to describe the number of iteration with in the DO..ENDDO, WHILE ...ENDWHILE....

for example,

DO.

WRITE SY-INDEX.

IF SY-INDEX = 3.

EXIT.

ENDIF.

ENDDO.

it gives output as:

1 2 3

Regards,

Raj.

Former Member
0 Kudos

Hi,

SY-TABIX:

Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.

it can be set by using the following:

1.append

2.collect

3.loop at

4. read

5.search

APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.

COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.

LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.

READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.

SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.

SY-INDEX:

SY-INDEX is used to describe the number of iteration with in the DO..ENDDO, WHILE ...ENDWHILE....

for example,

DO.

WRITE SY-INDEX.

IF SY-INDEX = 3.

EXIT.

ENDIF.

ENDDO.

it gives output as:

1 2 3

rewards points if useful.

regards,

Yogesh

Former Member
0 Kudos

Hi,

SY-TABIX means Table Index. This signifies the number of table index. Each row of a table has certain index or counter. The value of sy-tabix for the last entry would be equivalent to number of table entries.

SY-INDEX means the number of Iterations for a loop. bascially DO - ENDO .

SY-INDEX is not equal to SY-TABIX.

Check the belwo program

report tabix_index.

DO 100 times.

wa_tab-index = sy-index.

append wa_tab to itab.

clear wa_tab.

enddo.

loop at itab into wa_tab.

write:/1 sy-tabix.

endloop.

Refer

https://forums.sdn.sap.com/click.jspa?searchID=12200133&messageID=5069130

Regards

Kiran Sure

Former Member
0 Kudos

Hi,

SY-TABIX:

Current line of an internal table. SY-TABIX is set by the statements below, but only for index tables. The field is either not set or is set to 0 for hashed tables.

it can be set by using the following:

1.append

2.collect

3.loop at

4. read

5.search

APPEND sets SY-TABIX to the index of the last line of the table, that is, it contains the overall number of entries in the table.

COLLECT sets SY-TABIX to the index of the existing or inserted line in the table. If the table has the type HASHED TABLE, SY-TABIX is set to 0.

LOOP AT sets SY-TABIX to the index of the current line at the beginning of each loop lass. At the end of the loop, SY-TABIX is reset to the value that it had before entering the loop. It is set to 0 if the table has the type HASHED TABLE.

READ TABLE sets SY-TABIX to the index of the table line read. If you use a binary search, and the system does not find a line, SY-TABIX contains the total number of lines, or one more than the total number of lines. SY-INDEX is undefined if a linear search fails to return an entry.

SEARCH <itab> FOR sets SY-TABIX to the index of the table line in which the search string is found.

SY-INDEX:

SY-INDEX is used to describe the number of iteration with in the DO..ENDDO, WHILE ...ENDWHILE....

for example,

DO.

WRITE SY-INDEX.

IF SY-INDEX = 3.

EXIT.

ENDIF.

ENDDO.

it gives output as:

1 2 3

hope this is helpful

Regards,

Sravanthi

Former Member
0 Kudos

hi

sy-index- wil increase with repect to no. of loop pass.

sy-tabix - wil increase with respect to no. of table pass.

Former Member
0 Kudos

Sy-index is the counter for loops like DO, WHILE .

But sy-tabix is the counter for LOOP AT itab (internal table).

Former Member
0 Kudos

hi

sy-index- wil increase with repect to no. of loop pass.

each time the loop gets exectuted the value of sy-index wil increase by 1.

sy-tabix - wil increase with respect to no. of table pass.

if the internal table has n rows . each row read or write will increase tabix by one.

note : initial vale of sy-index is 0.

initial vale of sy-tabix is 1.

reward if helpful

regards

mano

Former Member
0 Kudos

Sy-index is for loop index and sy-tabix is used inside the internal table loop or u can say loop index .

Former Member
0 Kudos

Hi,

hope it helps..

SY-INDEX contains the number of loop passes in DO and WHILE loops, including the current loop pass.

SY-TABIX

Current line in an internal table. With the following statements SY-TABIX is set for index tables. With hashed tables, SY-TABIX is not filled or it is set to 0.

APPEND sets SY-TABIX to the index of the last table row, that is the total number of entries in the target table.

*COLLECT *sets SY-TABIX to the index of the existing or appended table row. With hashed tables, SY-TABIX is set to 0.

LOOP AT sets SY-TABIX to the index of the current table row at the beginning of every loop pass. After leaving a loop, SY-TABIX is set to the value it had before entering the loop. With hashed tables, SY-TABIX is set to 0.

READ TABLE sets SY-TABIX to the index of the table row read. If no row is found with binary search while reading, SY-TABIX contains the index of the next-highest row or the total number of rows +1. If no row is found with linear search while reading, SY-TABIX is undefined.

SEARCH itab FOR sets SY-TABIX to the index of the table row, in which the search string was found.

Please reward if helpful.

regards,

Srishti.