ABAP - SALV教程12 显示图标和提示信息
- ALV要求字段的值为图标的需求并不多见,一般都用于红黄绿灯,来表示单据的执行状态,添加图标的方式也可以实现红黄绿灯的功能,也可以参考SALV实现红黄绿灯这篇文章:http://t.csdnimg.cn/Dzx7x
- 效果图
- SAVL列设置为图标图标显示实现步骤:
- 输出内表增加一个char30的字段类型,然后赋值。图标的值:SE38执行showicon程序
TYPES:BEGIN OF TY_dATA,icon TYPE char30,TYPES:END OF ty_data.DATA mt_data TYPE TABLE OF ty_data.INCLUDE: <icon>.LOOP AT mt_data ASSIGNING FIELD-SYMBOL(<fs_data>).<fs_data>-icon = icon_checked.ENDLOOP.
- 将该字段设置为图标显示列
DATA: lo_functional_settings TYPE REF TO cl_salv_functional_settings.DATA: lo_tooltips TYPE REF TO cl_salv_tooltips,lv_value TYPE lvc_value.DATA: lo_columns TYPE REF TO cl_salv_columns.DATA: lo_column TYPE REF TO cl_salv_column_table.INCLUDE: <icon>.lo_columns = co_alv->get_columns( ).TRY.lo_column ?= lo_columns->get_column( 'ICON' )." 将列设置为显示ICONlo_column->set_icon( if_salv_c_bool_sap=>true )." 设置列标签 labello_column->set_long_text( '图标' )." 图标对齐方式lo_column->set_alignment( if_salv_c_alignment=>centered )." 字段长度lo_column->set_output_length( 6 ).CATCH cx_salv_not_found.ENDTRY."这里做鼠标悬停时的提示信息lo_functional_settings = co_alv->get_functional_settings( ).lo_tooltips = lo_functional_settings->get_tooltips( ).TRY."当图标代码值为icon_checked,提示 Everything is Processedlv_value = icon_checked.lo_tooltips->add_tooltip(type = cl_salv_tooltip=>c_type_iconvalue = lv_valuetooltip = 'Everything is Processed' ).CATCH cx_salv_existing.ENDTRY.ENDMETHOD.
- 完整代码
CLASS lcl_model DEFINITION.PUBLIC SECTION.TYPES:BEGIN OF TY_dATA,icon TYPE char30,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_icon CHANGING co_alv TYPE REF TO cl_salv_table.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 auartINTO CORRESPONDING FIELDS OF TABLE mt_dataFROM vbakUP TO 20 ROWS.INCLUDE: <icon>.LOOP AT mt_data ASSIGNING FIELD-SYMBOL(<fs_data>).<fs_data>-icon = icon_checked.ENDLOOP.ENDMETHOD.METHOD alv_show.DATA: lx_msg TYPE REF TO cx_salv_msg.TRY.cl_salv_table=>factory(IMPORTINGr_salv_table = mo_salvCHANGINGt_table = mt_data ).CATCH cx_salv_msg INTO lx_msg.ENDTRY.me->set_status( CHANGING co_alv = mo_salv ).me->set_icon( 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.METHOD set_icon.DATA: lo_functional_settings TYPE REF TO cl_salv_functional_settings.DATA: lo_tooltips TYPE REF TO cl_salv_tooltips,lv_value TYPE lvc_value.DATA: lo_columns TYPE REF TO cl_salv_columns.DATA: lo_column TYPE REF TO cl_salv_column_table.INCLUDE: <icon>.lo_columns = co_alv->get_columns( ).TRY.lo_column ?= lo_columns->get_column( 'ICON' )." 将列设置为显示ICONlo_column->set_icon( if_salv_c_bool_sap=>true )." 设置列标签 labello_column->set_long_text( '图标' )." 图标对齐方式lo_column->set_alignment( if_salv_c_alignment=>centered )." 字段长度lo_column->set_output_length( 6 ).CATCH cx_salv_not_found.ENDTRY."这里做鼠标悬停时的提示信息lo_functional_settings = co_alv->get_functional_settings( ).lo_tooltips = lo_functional_settings->get_tooltips( ).TRY."当图标代码值为icon_checked,提示 Everything is Processedlv_value = icon_checked.lo_tooltips->add_tooltip(type = cl_salv_tooltip=>c_type_iconvalue = lv_valuetooltip = 'Everything is Processed' ).CATCH cx_salv_existing.ENDTRY.ENDMETHOD.ENDCLASS.START-OF-SELECTION.DATA(lo_model) = NEW lcl_model( ).lo_model->get_data( ).lo_model->alv_show( ).
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/271357.html
如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!