关闭

Sorting Internal Tables(内表排序)

179人阅读 评论(0) 收藏 举报

DATA: BEGIN OF LINE,
        LAND(3)  TYPE C,
        NAME(10) TYPE C,
        AGE      TYPE I,
        WEIGHT   TYPE P DECIMALS 2,
      END OF LINE.

DATA ITAB LIKE STANDARD TABLE OF LINE WITH NON-UNIQUE KEY LAND.

LINE-LAND = 'G'.   LINE-NAME   = 'Hans'.
LINE-AGE  = 20.    LINE-WEIGHT = '80.00'.
APPEND LINE TO ITAB.

LINE-LAND = 'USA'. LINE-NAME   = 'Nancy'.
LINE-AGE  = 35.    LINE-WEIGHT = '45.00'.
APPEND LINE TO ITAB.

LINE-LAND = 'USA'. LINE-NAME   = 'Howard'.
LINE-AGE  = 40.    LINE-WEIGHT = '95.00'.
APPEND LINE TO ITAB.

LINE-LAND = 'GB'.  LINE-NAME   = 'Jenny'.
LINE-AGE  = 18.    LINE-WEIGHT = '50.00'.
APPEND LINE TO ITAB.

LINE-LAND = 'F'.   LINE-NAME   = 'Michele'.
LINE-AGE  = 30.    LINE-WEIGHT = '60.00'.
APPEND LINE TO ITAB.

LINE-LAND = 'G'.   LINE-NAME   = 'Karl'.
LINE-AGE  = 60.    LINE-WEIGHT = '75.00'.
APPEND LINE TO ITAB.

PERFORM LOOP_AT_ITAB.

SORT ITAB.
PERFORM LOOP_AT_ITAB.

SORT ITAB.
PERFORM LOOP_AT_ITAB.

SORT ITAB STABLE.
PERFORM LOOP_AT_ITAB.

SORT ITAB DESCENDING BY LAND WEIGHT ASCENDING.
PERFORM LOOP_AT_ITAB.

FORM LOOP_AT_ITAB.
  LOOP AT ITAB INTO LINE.
    WRITE: / LINE-LAND, LINE-NAME, LINE-AGE, LINE-WEIGHT.
  ENDLOOP.
  SKIP.
ENDFORM.

 

 

 



 

 

 

 

DATA: BEGIN OF LINE,
        TEXT(6),
        XTEXT(160) TYPE X,
      END OF LINE.

DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY TEXT.

LINE-TEXT = 'Muller'.
CONVERT TEXT LINE-TEXT INTO SORTABLE CODE LINE-XTEXT.
INSERT LINE INTO TABLE ITAB.

LINE-TEXT = 'Möller'.
CONVERT TEXT LINE-TEXT INTO SORTABLE CODE LINE-XTEXT.
INSERT LINE INTO TABLE ITAB.

LINE-TEXT = 'Moller'.
CONVERT TEXT LINE-TEXT INTO SORTABLE CODE LINE-XTEXT.
INSERT LINE INTO TABLE ITAB.

LINE-TEXT = 'Miller'.
CONVERT TEXT LINE-TEXT INTO SORTABLE CODE LINE-XTEXT.
INSERT LINE INTO TABLE ITAB.

SORT ITAB.
PERFORM LOOP_AT_ITAB.

SORT ITAB BY XTEXT.
PERFORM LOOP_AT_ITAB.

SORT ITAB AS TEXT.
PERFORM LOOP_AT_ITAB.

FORM LOOP_AT_ITAB.
  LOOP AT ITAB INTO LINE.
    WRITE: / LINE-TEXT, line-.
  ENDLOOP.
  SKIP.
ENDFORM.

 

代码摘自:http://help.sap.com/saphelp_NW04/helpdata/en/fc/eb3800358411d1829f0000e829fbfe/content.htm

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:12487次
    • 积分:267
    • 等级:
    • 排名:千里之外
    • 原创:14篇
    • 转载:3篇
    • 译文:0篇
    • 评论:2条
    文章分类
    文章存档
    最新评论
    SAP BLOGER