DATA: BEGIN OF ITAB OCCURS 0,
F1(10),
F2(10),
END OF ITAB.
DATA: BEGIN OF STAB OCCURS 0 ,
SF(10),
END OF STAB.
DATA: BEGIN OF STAB2 ,
SF1(10),
SF2(10),
SF3(10),
SF4(10),
SF5(10),
END OF STAB2.
DATA: TMPSF(10).
DATA: ITAB2 LIKE ITAB[] WITH HEADER LINE.
STAB-SF = 'B'.
APPEND STAB.
STAB-SF = 'A'.
APPEND STAB.
STAB-SF = 'I'.
APPEND STAB.
STAB-SF = 'T'.
APPEND STAB.
STAB-SF = 'Z'.
APPEND STAB.
stab2-sf1 = 'T'.
stab2-sf2 = 'Z'.
stab2-sf3 = 'B'.
stab2-sf4 = 'A'.
stab2-sf5 = 'I'.
ITAB-F1 = 1.
ITAB-F2 = 'I'.
APPEND ITAB.
ITAB-F1 = 2.
ITAB-F2 = 'Z'.
APPEND ITAB.
ITAB-F1 = 3.
ITAB-F2 = 'E'.
APPEND ITAB.
ITAB-F1 = 4.
ITAB-F2 = 'T'.
APPEND ITAB.
ITAB-F1 = 5.
ITAB-F2 = 'T'.
APPEND ITAB.
ITAB-F1 = 6.
ITAB-F2 = 'B'.
APPEND ITAB.
ITAB-F1 = 7.
ITAB-F2 = 'F'.
APPEND ITAB.
ITAB-F1 = 8.
ITAB-F2 = 'A'.
APPEND ITAB.
ITAB-F1 = 9.
ITAB-F2 = 'B'.
APPEND ITAB.
**内表方式的序列
CLEAR ITAB2[].
LOOP AT STAB.
LOOP AT ITAB INTO ITAB2 WHERE F2 = STAB-SF.
APPEND ITAB2.
DELETE ITAB.
ENDLOOP.
ENDLOOP.
APPEND LINES OF ITAB TO ITAB2.
ITAB[] = ITAB2[].
LOOP AT ITAB.
WRITE / ITAB.
ENDLOOP.
**结构方式的序列
CLEAR ITAB2[].
DO 5 TIMES VARYING TMPSF FROM STAB2-SF1 NEXT STAB2-SF2.
LOOP AT ITAB INTO ITAB2 WHERE F2 = tmpsf.
APPEND ITAB2.
DELETE ITAB.
ENDLOOP.
ENDDO.
APPEND LINES OF ITAB TO ITAB2.
ITAB[] = ITAB2[].
SKIP 2 .
LOOP AT ITAB.
WRITE / ITAB.
ENDLOOP.
注1:这个方法只是完成了排序,但是算法效率很差,如果有大数据量,不建议使用这个方法
注2:按照指定序列对内表排序后,如果还要按照更高级别的字段排序,请使用稳定排序法,ABAP中为:SORT ITAB STABLE BY...
阅读(4746) | 评论(0) | 转发(0) |