ABAP - SALV教程12 显示图标和提示信息

  • ALV要求字段的值为图标的需求并不多见,一般都用于红黄绿灯,来表示单据的执行状态,添加图标的方式也可以实现红黄绿灯的功能,也可以参考SALV实现红黄绿灯这篇文章:http://t.csdnimg.cn/Dzx7x
  • 效果图
  • SAVL列设置为图标图标显示实现步骤:
  1. 输出内表增加一个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.
    
  2. 将该字段设置为图标显示列

        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' ).
            " 将列设置为显示ICON
            lo_column->set_icon( if_salv_c_bool_sap=>true ).
            " 设置列标签 label
            lo_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 Processed
            lv_value = icon_checked.
            lo_tooltips->add_tooltip(
              type    = cl_salv_tooltip=>c_type_icon
              value   = lv_value
              tooltip = '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 auart
          INTO CORRESPONDING FIELDS OF TABLE mt_data
          FROM vbak
          UP 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(
              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 ).
        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' ).
            " 将列设置为显示ICON
            lo_column->set_icon( if_salv_c_bool_sap=>true ).
            " 设置列标签 label
            lo_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 Processed
            lv_value = icon_checked.
            lo_tooltips->add_tooltip(
              type    = cl_salv_tooltip=>c_type_icon
              value   = lv_value
              tooltip = '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( ).
    
相关推荐
冰魄禾6 天前
SAP ABAP开发学习——BAPI
运维·开发语言·笔记·运维开发·sap·abap
Lisson 316 天前
The ABAP program lines are wider than the internal table.
abap
1314lay_10072 个月前
FUNCTION_ALV 下拉框的实现
abap
Fireworks_me2 个月前
SAP 有趣的‘bug‘ 选择屏幕输入框没了
abap
李安迪是大神3 个月前
上传PDF、DOC文件到SAP HCM系统中案例
pdf·word·sap·abap·sap erp
荀彧原名苟或3 个月前
SAP MIGO屏幕增强的具体实施步骤介绍(SE19:MB_MIGO_BADI) <转载>
java·数据库·缓存·sap·abap
LilySesy3 个月前
ABAP小白开发操作手册+(九)ABAP调用http
开发语言·网络·网络协议·http·sap·abap
LilySesy3 个月前
ABAP+从SAP发出去的PDF文件在第三方系统出现乱码
开发语言·程序人生·pdf·sap·abap
酔墨诗欣4 个月前
第一弹:基于ABAP OLE技术实现对服务器文件进行读写操作
sap·abap·bw/4hana·ole
Fireworks_me4 个月前
ABAP 生成word文档
word·abap