ABAP系统变量SY-INDEX与SY-TABIX都是用来记录循环的次数。但是SY-INDEX在do...endo和while...endwhile中起作用,而SY-TABIX在loop...endloop中有效。
测试代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
REPORT ztest_index_tabix. DATA:lit_vbak TYPE STANDARD TABLE OF vbak, lwa_vbak TYPE vbak. DATA:l_flag TYPE c. SELECT * FROM vbak INTO TABLE lit_vbak UP TO 5 ROWS. WRITE:/ 'Loop...Endloop'. LOOP AT lit_vbak INTO lwa_vbak. WRITE:/ 'SY-INDEX:', sy-index, 'SY-TABIX', sy-tabix. ENDLOOP. WRITE:/ 'Do...EndDo'. DO 5 TIMES. WRITE:/ 'SY-INDEX:', sy-index, 'SY-TABIX', sy-tabix. ENDDO. WRITE:/ 'WHILE...EndWhile'. WHILE l_flag < 5. WRITE:/ 'SY-INDEX:', sy-index, 'SY-TABIX', sy-tabix. l_flag = l_flag + 1. ENDWHILE. |
运行结果:
以上。
发表评论