有时候会有用户要求显示出来的ALV立即就是升序或者降序,或者是上下同一个字段值一样的情况显示一次,如
变为
这个时候内表用SORT有时候会不好用,可以使用函数
REUSE_ALV_GRID_DISPLAY
自带的排序属性参数---》it_sort. 布局也是需要调用相关的参数i_save。
DATA:IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV, WA_LAYOUT TYPE SLIS_LAYOUT_ALV, IT_SORT TYPE SLIS_T_SORTINFO_ALV, WA_SORT TYPE SLIS_SORTINFO_ALV. SELECT * FROM EKPO INTO TABLE @DATA(IT_EKPO) UP TO 50 ROWS. *SORT IT_EKPO BY EBELN. *CL_DEMO_OUTPUT=>DISPLAY_DATA( IT_EKPO ). WA_SORT-FIELDNAME = 'EBELN'. "对需要排序的字段进行赋值 WA_SORT-UP = 'X'."up是升序,down是降序 APPEND WA_SORT TO IT_SORT. CLEAR WA_SORT. DATA:POS TYPE I. POS = 1. WA_FIELDCAT-COL_POS = POS. WA_FIELDCAT-FIELDNAME = 'EBELN'. WA_FIELDCAT-TABNAME = 'IT_EKPO'. WA_FIELDCAT-SELTEXT_M = '采购订单号'. APPEND WA_FIELDCAT TO IT_FIELDCAT. CLEAR WA_FIELDCAT. POS = POS + 1. WA_FIELDCAT-COL_POS = POS. WA_FIELDCAT-FIELDNAME = 'BUKRS'. WA_FIELDCAT-TABNAME = 'IT_EKPO'. WA_FIELDCAT-SELTEXT_M = '公司代码'. APPEND WA_FIELDCAT TO IT_FIELDCAT. CLEAR WA_FIELDCAT. POS = POS + 1. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = SY-REPID IS_LAYOUT = WA_LAYOUT IT_FIELDCAT = IT_FIELDCAT IT_SORT = IT_SORT[] "这里不能忘记调用参数 I_SAVE = 'A'"这个是生成布局的参数 TABLES T_OUTTAB = IT_EKPO.
界面如下: