Sorting Internal Tables(内表排序)

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

阅读更多
文章标签: sorting table c
个人分类: SAP-ABAP
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭