- CL_SALV_TABLE中提供了 GET_FUNCTIONS方法.GET_FUNCTIONS方法返回的是一个CL_SALV_FUNCTIONS_LIST类型的实例对象.
-
类CL_SALV_FUNCTIONS_LIST两个方法(SET_ALL、SET_DEFAULT)可以添加标准状态栏
-
实现步骤:
-
定义SET_STATUS私有方法.
PRIVATE SECTION. METHODS: set_status CHANGING co_alv TYPE REF TO cl_salv_table.
METHOD set_status. DATA(lo_functions) = co_alv->get_functions( ). "cl_salv_functions_list类型的实例对象的添加状态方法 lo_functions->set_all( abap_true ). "lo_functions->set_default( abap_true ). ENDMETHOD.
-
在生成SALV实例对象后调用SET_STATUS私有方法.
DATA: lx_msg TYPE REF TO cx_salv_msg. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = mo_salv CHANGING t_table = mt_data ). CATCH cx_salv_msg INTO lx_msg. ENDTRY. me->set_status( CHANGING co_alv = mo_salv ).
- 完整代码
CLASS lcl_model DEFINITION. PUBLIC SECTION. TYPES:BEGIN OF TY_dATA, vbeln TYPE vbak-vbeln, erdat TYPE erdat, erzet TYPE erzet, ernam TYPE ernam, auart TYPE auart. TYPES:END OF ty_data. DATA mt_data TYPE TABLE OF ty_data. DATA mo_salv TYPE REF TO cl_salv_table. "获取数据的方法 METHODS get_data. "展示SALV的方法 METHODS alv_show. PRIVATE SECTION. METHODS: set_status CHANGING co_alv TYPE REF TO cl_salv_table. ENDCLASS. CLASS lcl_model IMPLEMENTATION. METHOD get_data. SELECT vbeln erdat erzet ernam auart INTO TABLE mt_data FROM vbak UP TO 20 ROWS. ENDMETHOD. METHOD alv_show. DATA: lx_msg TYPE REF TO cx_salv_msg. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = mo_salv CHANGING t_table = mt_data ). CATCH cx_salv_msg INTO lx_msg. ENDTRY. me->set_status( CHANGING co_alv = mo_salv ). mo_salv->display( ). ENDMETHOD. METHOD set_status. DATA(lo_functions) = co_alv->get_functions( ). "cl_salv_functions_list类型的实例对象的添加状态方法 lo_functions->set_all( abap_true ). "lo_functions->set_default( abap_true ). ENDMETHOD. ENDCLASS. START-OF-SELECTION. DATA(lo_model) = NEW lcl_model( ). lo_model->get_data( ). lo_model->alv_show( ).
- 显示效果