ALV demo 02:cl_salv_table 添加排序和汇总
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ALV demo 02:cl_salv_table 添加排序和汇总相关的知识,希望对你有一定的参考价值。
接着上篇文章,这次添加排序。
DATA: GT_DATA TYPE TABLE OF SFLIGHT.
DATA: GR_TABLE TYPE REF TO CL_SALV_TABLE.
"tool bar
DATA: GR_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS
.
"Columns – CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN_TABLE
DATA: GR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE.
DATA: GR_COLUMN TYPE REF TO CL_SALV_COLUMN_TABLE.
DATA: COLOR TYPE LVC_S_COLO.
*Sorts – CL_SALV_SORTS
DATA: GR_SORTS TYPE REF TO CL_SALV_SORTS.
START-OF-SELECTION.
SELECT * INTO TABLE GT_DATA FROM SFLIGHT.
CL_SALV_TABLE=>FACTORY( IMPORTING R_SALV_TABLE = GR_TABLE CHANGING T_TABLE = GT_DATA ).
*tool bar
GR_FUNCTIONS = GR_TABLE->GET_FUNCTIONS( ).
GR_FUNCTIONS->SET_ALL( ABAP_TRUE ).
GR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN( MANDT ).
CALL METHOD GR_COLUMN->SET_VISIBLE
EXPORTING
VALUE = IF_SALV_C_BOOL_SAP=>FALSE.
*Sorts – CL_SALV_SORTS
GR_SORTS = GR_TABLE->GET_SORTS( ).
GR_SORTS->ADD_SORT( COLUMNNAME = CARRID ).
GR_TABLE->DISPLAY( ).
再加个汇总吧
根据币种分别汇总了。
DATA: GT_DATA TYPE TABLE OF SFLIGHT.
DATA: GR_TABLE TYPE REF TO CL_SALV_TABLE.
"tool bar
DATA: GR_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS
.
"Columns – CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN_TABLE
DATA: GR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE.
DATA: GR_COLUMN TYPE REF TO CL_SALV_COLUMN_TABLE.
DATA: COLOR TYPE LVC_S_COLO.
*Sorts – CL_SALV_SORTS
DATA: GR_SORTS TYPE REF TO CL_SALV_SORTS.
*Aggregations – CL_SALV_AGGREGATIONS
DATA: GR_AGG TYPE REF TO CL_SALV_AGGREGATIONS.
START-OF-SELECTION.
SELECT * INTO TABLE GT_DATA FROM SFLIGHT.
CL_SALV_TABLE=>FACTORY( IMPORTING R_SALV_TABLE = GR_TABLE CHANGING T_TABLE = GT_DATA ).
*tool bar
GR_FUNCTIONS = GR_TABLE->GET_FUNCTIONS( ).
GR_FUNCTIONS->SET_ALL( ABAP_TRUE ).
GR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN( MANDT ).
CALL METHOD GR_COLUMN->SET_VISIBLE
EXPORTING
VALUE = IF_SALV_C_BOOL_SAP=>FALSE.
*Sorts – CL_SALV_SORTS
GR_SORTS = GR_TABLE->GET_SORTS( ).
GR_SORTS->ADD_SORT( COLUMNNAME = CARRID ).
* Aggregations – CL_SALV_AGGREGATIONS
GR_AGG = GR_TABLE->GET_AGGREGATIONS( ).
GR_AGG->ADD_AGGREGATION( PRICE ).
GR_TABLE->DISPLAY( ).
再换个效果:
根据币种排序,汇总。
参考代码:
REPORT ZLM_ALV001.
DATA: GT_DATA TYPE TABLE OF SFLIGHT.
DATA: GR_TABLE TYPE REF TO CL_SALV_TABLE.
"tool bar
DATA: GR_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS
.
"Columns – CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN_TABLE
DATA: GR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE.
DATA: GR_COLUMN TYPE REF TO CL_SALV_COLUMN_TABLE.
DATA: COLOR TYPE LVC_S_COLO.
*Sorts – CL_SALV_SORTS
DATA: GR_SORTS TYPE REF TO CL_SALV_SORTS.
*Aggregations – CL_SALV_AGGREGATIONS
DATA: GR_AGG TYPE REF TO CL_SALV_AGGREGATIONS.
START-OF-SELECTION.
SELECT * INTO TABLE GT_DATA FROM SFLIGHT.
CL_SALV_TABLE=>FACTORY( IMPORTING R_SALV_TABLE = GR_TABLE CHANGING T_TABLE = GT_DATA ).
*tool bar
GR_FUNCTIONS = GR_TABLE->GET_FUNCTIONS( ).
GR_FUNCTIONS->SET_ALL( ABAP_TRUE ).
GR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
GR_COLUMN ?= GR_COLUMNS->GET_COLUMN( MANDT ).
CALL METHOD GR_COLUMN->SET_VISIBLE
EXPORTING
VALUE = IF_SALV_C_BOOL_SAP=>FALSE.
*Sorts – CL_SALV_SORTS
GR_SORTS = GR_TABLE->GET_SORTS( ).
* "Aggregations – CL_SALV_AGGREGATIONS
GR_SORTS->ADD_SORT( COLUMNNAME = CURRENCY SUBTOTAL = ABAP_TRUE ).
GR_AGG = GR_TABLE->GET_AGGREGATIONS( ).
GR_AGG->ADD_AGGREGATION( PRICE ).
GR_TABLE->DISPLAY( ).
以上是关于ALV demo 02:cl_salv_table 添加排序和汇总的主要内容,如果未能解决你的问题,请参考以下文章
ALV Tree demo(WBS元素分层显示)[引用别人的]