ABAP系统变量SY-INDEX与SY-TABIX都是在循环中使用:
SY-INDEX在Do...EndDo和While...EndWhile中起作用;
SY-TABIX在Loop...EndLoop中有效。
详见如下实例:
REPORT ztest_index_tabix.DATA:lit_vbak TYPE STANDARD TABLE OF vbak,lwa_vbak TYPE vbak.
DATA:l_flag TYPE c.【Loop...Endloop】
SELECT *FROM vbakINTO TABLE lit_vbakUP TO 5 ROWS.
WRITE:/ 'Loop...Endloop'.
LOOP AT lit_vbak INTO lwa_vbak.WRITE:/ 'SY-INDEX:', sy-index, 'SY-TABIX', sy-tabix.
ENDLOOP.【Do...EndDo】
WRITE:/ 'Do...EndDo'.
DO 5 TIMES.WRITE:/ 'SY-INDEX:', sy-index, 'SY-TABIX', sy-tabix.
ENDDO.【WHILE...EndWhile】
WRITE:/ 'WHILE...EndWhile'.
WHILE l_flag < 5.WRITE:/ 'SY-INDEX:', sy-index, 'SY-TABIX', sy-tabix.l_flag = l_flag + 1.
ENDWHILE.
输出结果: