系统变量SY-INDEX与SY-TABIX是用来记录循环的次数或者索引的,不同的是SY-INDEX在DO....ENDDO中是有效的,而SY-TABIX在LOOP....ENDLOOP中及READ内表时获取相应的索引。
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
REPORT ztest_index. DATA:BEGIN OF git_student OCCURS 0, name(10) TYPE c, age TYPE i, END OF git_student. DATA:dent LIKE LINE OF git_student. git_student-name = 'JACK'. git_student-age = 20. APPEND git_student. git_student-name = 'JIM'. git_student-age = 25. APPEND git_student. git_student-name = 'TOMMY'. git_student-age = 28. APPEND git_student. git_student-name = 'BUSHI'. git_student-age = 20. APPEND git_student. git_student-name = 'LILY'. git_student-age = 26. APPEND git_student. git_student-name = 'ALEX'. git_student-age = 28. APPEND git_student. WRITE: '1.LOOP循环'. WRITE: / '-----------------------------------------------'. LOOP AT git_student. WRITE: / 'SY-INDEX=',sy-index LEFT-JUSTIFIED, "LEFT-JUSTIFIED 输出向左对齐 'SY-TABIX=',sy-tabix LEFT-JUSTIFIED, 'NAME=',git_student-name LEFT-JUSTIFIED, 'AGE=',git_student-age LEFT-JUSTIFIED. ENDLOOP. WRITE: / '-----------------------------------------------'. WRITE: / '2.READ INTERNAL TABLE'. WRITE: / '-----------------------------------------------'. READ TABLE git_student INTO dent WITH KEY name = 'ALEX'. "按具体字段值读取内表 WRITE: / 'SY-INDEX=',sy-index LEFT-JUSTIFIED, 'SY-TABIX=',sy-tabix LEFT-JUSTIFIED, "读取内表时,返回相应数据在内表中的索引 'NAME=',dent-name LEFT-JUSTIFIED, 'AGE=',dent-age LEFT-JUSTIFIED. READ TABLE git_student INTO dent WITH KEY name = 'BUSHI'. "按具体字段值读取内表 WRITE: / 'SY-INDEX=',sy-index LEFT-JUSTIFIED, 'SY-TABIX=',sy-tabix LEFT-JUSTIFIED, 'NAME=',dent-name LEFT-JUSTIFIED, 'AGE=',dent-age LEFT-JUSTIFIED. CLEAR sy-tabix. WRITE: / '-----------------------------------------------'. WRITE: / '3.DO...ENDDO'. WRITE: / '-----------------------------------------------'. DO 5 TIMES. WRITE:/ 'SY-INDEX=',sy-index LEFT-JUSTIFIED, 'SY-TABIX=',sy-tabix LEFT-JUSTIFIED. ENDDO. WRITE:/ '-----------------------------------------------'. |
运行后:
发表评论