SY-TABIX, SY-INDEX :
Let’s begin with a test program.
Sample Program:
REPORT ztest_index_tabix.
TYPES: BEGIN OF ty_tab,
id TYPE i,
END OF ty_tab.
DATA: i_tab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
k_tab TYPE ty_tab,
v_indx TYPE i.
k_tab-id = 1.
APPEND k_tab TO i_tab.
k_tab-id = 2.
APPEND k_tab TO i_tab.
k_tab-id = 3.
APPEND k_tab TO i_tab.
LOOP AT i_tab INTO k_tab.
WRITE:/ 'Before Read statement'.
WRITE:/ 'sy-tabix', sy-tabix,
'sy-index', sy-index.
READ TABLE i_tab INTO k_tab INDEX 2.
WRITE:/ 'After Read statement'.
WRITE:/ 'sy-tabix', sy-tabix,
'sy-index', sy-index.
WRITE:/ '+++++++++++++++++++++++++++++++++++'.
ENDLOOP.
DO 3 TIMES.
WRITE:/ 'Before Read statement'.
WRITE:/ 'sy-tabix', sy-tabix,
'sy-index', sy-index.
READ TABLE i_tab INTO k_tab INDEX 2.
WRITE:/ 'After Read statement'.
WRITE:/ 'sy-tabix', sy-tabix,
'sy-index', sy-index.
WRITE:/ '+++++++++++++++++++++++++++++++++++'.
ENDDO.
TYPES: BEGIN OF ty_tab,
id TYPE i,
END OF ty_tab.
DATA: i_tab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
k_tab TYPE ty_tab,
v_indx TYPE i.
k_tab-id = 1.
APPEND k_tab TO i_tab.
k_tab-id = 2.
APPEND k_tab TO i_tab.
k_tab-id = 3.
APPEND k_tab TO i_tab.
LOOP AT i_tab INTO k_tab.
WRITE:/ 'Before Read statement'.
WRITE:/ 'sy-tabix', sy-tabix,
'sy-index', sy-index.
READ TABLE i_tab INTO k_tab INDEX 2.
WRITE:/ 'After Read statement'.
WRITE:/ 'sy-tabix', sy-tabix,
'sy-index', sy-index.
WRITE:/ '+++++++++++++++++++++++++++++++++++'.
ENDLOOP.
DO 3 TIMES.
WRITE:/ 'Before Read statement'.
WRITE:/ 'sy-tabix', sy-tabix,
'sy-index', sy-index.
READ TABLE i_tab INTO k_tab INDEX 2.
WRITE:/ 'After Read statement'.
WRITE:/ 'sy-tabix', sy-tabix,
'sy-index', sy-index.
WRITE:/ '+++++++++++++++++++++++++++++++++++'.
ENDDO.
Output:
Conclusion:
In LOOP / ENDLOOP -
SY-INDEX will never work.
SY-TABIX always holds the current executing record’s index for both the LOOP
and READ statement.
Conclusion:
In DO / ENDDO –
SY-INDEX holds the current executing record’s index only for the DO / WHILE loop and NOT for the READ statement.
This comment has been removed by the author.
ReplyDeletesuper explanation really its good
DeleteThanks Aravind for visiting the blog..
DeleteHi, This works only in use of standard internal table but for hashed internal table "SY-TABIX" will not work.
ReplyDeleteVery good explanation, this is really helpful!!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteCool and I have a nifty offer you: How Long Do House Renovations Take home renovators
ReplyDelete