zoukankan      html  css  js  c++  java
  • abap关于在REUSE_ALV_GRID_DISPLAY将单元或行标识不同的颜色的处理收集

    一、指定行显示不同颜色
    参见:http://blog.csdn.net/CompassButton/archive/2006/09/08/1195672.aspx 

    二、不同列显示不同颜色
    1)对于非key字段则可以通过设置字段格式(slis_fieldcat_alv)的emphasize指定,代码如下:
      data: wa_fieldcat type slis_fieldcat_alv.
      clear wa_fieldcat.
      wa_fieldcat-ref_fieldname = im_ref_field.
      wa_fieldcat-ref_tabname = im_ref_table.
      wa_fieldcat-fieldname = im_fieldname.
      wa_fieldcat-tabname   = im_tabname.
      wa_fieldcat-key       = ‘’.
      wa_fieldcat-fix_column = IM_fix.
      wa_fieldcat-checkbox  = im_checkbox.
      wa_fieldcat-do_sum     = im_dosum.
      wa_fieldcat-no_zero     = im_zero.
      wa_fieldcat-no_out     = im_out.
      wa_fieldcat-seltext_l = im_seltex_l.
      wa_fieldcat-seltext_m = im_seltex_l.
      wa_fieldcat-seltext_s = im_seltex_l.
      wa_fieldcat-outputlen = im_outputlen.
      wa_fieldcat-decimals_out = im_dec.
      wa_fieldcat--emphasize = 'C500'.
    *  wa_fieldcat-col_pos   = IM_colpos.
      append wa_fieldcat to re_field.
    2)对于key字段的设置参见单元颜色设置一个特例(整列的所有单元)

    三、指定单元格显示不同颜色(参见红色代码)
    代码
    report  Ztest_fullscreencolor.
    type-pools: slis.
    class cl_gui_resources definition load.
    types: begin of g_ty_s_test,
             select_amount            type i,
             color_rows               type i occurs 0,
             color_fields_column      type lvc_fname occurs 0,
             color_fields_cell        type lvc_fname occurs 0,
           end of   g_ty_s_test,

           begin of g_ty_s_outtab_slis.
    include type alv_t_t2.
     *定义颜色设置字段
    types:   color(4)  type c,
             tabcolor  type slis_t_specialcol_alv,

           end   of g_ty_s_outtab_slis,
           g_ty_t_outtab_slis type table of g_ty_s_outtab_slis.

    constants: con_true         type char1 value 'X'.

    field-symbols: <gt_outtab> type standard table.

    data: gs_test   type g_ty_s_test,
          gt_outtab_slis  type g_ty_t_outtab_slis,
          g_repid type sy-repid.

    data: g_field     type lvc_s_fcat-fieldname,
          g_int_field type i.
    *----------------------------------------------------------------------*
    * SELECTION-SCREEN                                                     *
    *----------------------------------------------------------------------
    selection-screen begin of block col with frame title text-col.
    parameters:
    p_col01 as checkbox.
    select-options:
    p_colf01 for g_int_field no intervals default 1.
    parameters:
    p_col02 as checkbox  default 'X'.
    select-options:
    p_colf02 for g_field no intervals default 'CARRID'.
    parameters:
    p_col03 as checkbox .
    select-options:
    p_colf03 for g_field no intervals default 'CONNID'.
    selection-screen end of block col.

    *----------------------------------------------------------------------*
    * AT SELECTION-SCREEN ON VALUE-REQUEST                                 *
    *----------------------------------------------------------------------*
    at selection-screen on value-request for p_colf02-low.
      perform f01_f4_fcode changing p_colf02-low.

    at selection-screen on value-request for p_colf03-low.
      perform f01_f4_fcode changing p_colf03-low.

    *----------------------------------------------------------------------*
    * START-OF-SELECTION                                                   *
    *----------------------------------------------------------------------*
    start-of-selection.
      g_repid               = sy-repid.

      gs_test-select_amount = 30.

      if p_col01 eq con_true.
        loop at p_colf01.
          if not p_colf01-low is initial.
            append p_colf01-low to gs_test-color_rows.
          endif.
        endloop.
      endif.
      if p_col02 eq con_true.
        loop at p_colf02.
          if not p_colf02-low is initial.
            append p_colf02-low to gs_test-color_fields_column.
          endif.
        endloop.
      endif.
      if p_col03 eq con_true.
        loop at p_colf03.
          if not p_colf03-low is initial.
            append p_colf03-low to gs_test-color_fields_cell.
          endif.
        endloop.
      endif.
    *----------------------------------------------------------------------*
    * END-OF-SELECTION                                                     *
    *----------------------------------------------------------------------*
    end-of-selection.
      perform f01_call_fullscreen.

    *&---------------------------------------------------------------------*
    *&      Form  f01_call_fullscreen
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    form f01_call_fullscreen .
      data: ls_layo   type slis_layout_alv,
            lt_fcat   type slis_t_fieldcat_alv.
      perform f01_get_outtab.
      perform f01_set_layo changing ls_layo.
      perform f01_set_fcat changing lt_fcat.
      perform f01_set_color changing lt_fcat  ls_layo.
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program                = g_repid
    *传入控制信息
          is_layout                         = ls_layo
          it_fieldcat                       = lt_fcat

        tables
          t_outtab                          = <gt_outtab>
       exceptions
         program_error                     = 1
         others                            = 2.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.

    endform.                    " f01_call_fullscreen
    *&---------------------------------------------------------------------*
    *&      Form  f01_get_outtab
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    form f01_get_outtab.
          select * from alv_t_t2
                   into corresponding fields of table gt_outtab_slis
                   up to gs_test-select_amount rows
                   order by primary key.

          assign gt_outtab_slis to <gt_outtab>.
    endform.                    " f01_get_outtab
    *&---------------------------------------------------------------------*
    *&      Form  f01_set_layo
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    form f01_set_layo changing cs_layo type slis_layout_alv.

      data: l_text00 type sy-title,
            l_text01 type sy-title,
            l_text02 type sy-title,
            l_text03 type sy-title.
    *... Display options
      cs_layo-colwidth_optimize      = space.
      cs_layo-no_colhead             = space.
      cs_layo-no_hotspot             = space.
      cs_layo-zebra                  = space.
      cs_layo-no_vline               = space.
      cs_layo-no_hline               = space.
      cs_layo-cell_merge             = space.
      cs_layo-no_min_linesize        = space.
      cs_layo-min_linesize           = space.
      cs_layo-max_linesize           = space.
      sy-title = 'Test'.
      set titlebar 'D0100' with cs_layo-window_titlebar.
      cs_layo-no_uline_hs            = space.
      cs_layo-countfname             = space.
    *... Exceptions
      cs_layo-lights_fieldname       = space.
      cs_layo-lights_tabname         = space.
      cs_layo-lights_rollname        = space.
      cs_layo-lights_condense        = space.
    *... Sums
      cs_layo-no_sumchoice           = space.
      cs_layo-no_totalline           = space.
      cs_layo-totals_before_items    = space.
      cs_layo-totals_only            = space.
      cs_layo-totals_text            = space.
      cs_layo-no_subchoice           = space.
      cs_layo-no_subtotals           = space.
      cs_layo-subtotals_text         = space.
      cs_layo-numc_sum               = space.
      cs_layo-no_unit_splitting      = space.
    *... Interaction
      cs_layo-box_fieldname          = space.
      cs_layo-box_tabname            = space.
      cs_layo-box_rollname           = space.
      cs_layo-expand_fieldname       = space.
      cs_layo-hotspot_fieldname      = space.
      cs_layo-no_input               = space.
      cs_layo-f2code                 = space.
      cs_layo-confirmation_prompt    = space.
      cs_layo-key_hotspot            = space.
      cs_layo-flexible_key           = space.
      cs_layo-reprep                 = space.
      cs_layo-group_buttons          = space.
      cs_layo-no_keyfix              = space.
      cs_layo-get_selinfos           = space.
      cs_layo-group_change_edit      = space.
      cs_layo-no_scrolling           = space.
      cs_layo-expand_all             = space.
      cs_layo-no_author              = space.
    *... Detailed screen
      cs_layo-detail_popup           = space.
      cs_layo-detail_initial_lines   = space.
      cs_layo-detail_titlebar        = space.
    *... PF-status
      cs_layo-def_status             = space.
    *... Display variants
      cs_layo-header_text            = space.
      cs_layo-item_text              = space.
      cs_layo-default_item           = space.
    *... colour
      cs_layo-info_fieldname         = space.
      cs_layo-coltab_fieldname       = space.
    *... others
      cs_layo-list_append            = space.
    endform.                    " f01_set_layo

    *&---------------------------------------------------------------------*
    *&      Form  f01_set_fcat
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    form f01_set_fcat changing ct_fcat type slis_t_fieldcat_alv.
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
        exporting
          i_structure_name             = 'ALV_T_T2'
        changing
          ct_fieldcat                  = ct_fcat
        exceptions
          inconsistent_interface       = 1
          program_error                = 2
          others                       = 3.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    endform.                    " f01_set_fcat

    *&---------------------------------------------------------------------*
    *&      Form  f01_set_color
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    form f01_set_color changing ct_fcat type slis_t_fieldcat_alv
                                cs_layo type slis_layout_alv.
      field-symbols: <ls_outtab> type any,
                     <ls_fcat>   type slis_fieldcat_alv,
                     <l_any>     type any,
                     <lt_table>  type standard table.
      data: l_row         type i,
            l_field       type lvc_fname,
            l_color_index type i,
            lt_fcat       type slis_t_fieldcat_alv,
            lt_color_lvc  type lvc_t_scol,
            ls_color_lvc  type lvc_s_scol,
            lt_color_slis type slis_t_specialcol_alv,
            ls_color_slis type slis_specialcol_alv.
    *Set Row Color through info_fieldname
    *对不同行对Color字段填写不同颜色值

      cs_layo-info_fieldname = 'COLOR'.

      loop at gs_test-color_rows into l_row.
        read table <gt_outtab> assigning <ls_outtab> index l_row.
        if sy-subrc eq 0.
          assign component 'COLOR' of structure <ls_outtab> to <l_any>.
          if sy-subrc eq 0.
            <l_any> = 'C610'.
          endif.
        endif.
      endloop.
      lt_fcat = ct_fcat.
      delete lt_fcat where tech ne space or no_out ne space.
    *对于非关键字段可以通过emphasize设置颜色
      loop at gs_test-color_fields_column into l_field.
        read table lt_fcat assigning <ls_fcat>
                   with key fieldname = l_field.
        if sy-subrc eq 0 and <ls_fcat>-key eq space.
          read table ct_fcat assigning <ls_fcat>
                     with key fieldname = <ls_fcat>-fieldname.
          if sy-subrc eq 0.
            <ls_fcat>-emphasize = 'C500'.
          endif.
        else.
    *对于关键字段可以通过则通过cs_layo-coltab_fieldname = 'TABCOLOR'来设置颜色
          ls_color_slis-fieldname = <ls_fcat>-fieldname.
          ls_color_slis-color-col = cl_gui_resources=>list_col_positive.
          ls_color_slis-color-int = cl_gui_resources=>list_intensified.
          ls_color_slis-color-inv = 0.
          ls_color_slis-nokeycol  = con_true.
          append ls_color_slis to lt_color_slis.
          loop at <gt_outtab> assigning <ls_outtab>.
            assign component 'TABCOLOR' of structure <ls_outtab> to <l_any>.
            if sy-subrc eq 0.
               <l_any> = lt_color_slis.
            endif.
          endloop.
        endif.
      endloop.

      cs_layo-coltab_fieldname = 'TABCOLOR'.
    *TABCOLOR表可以填写多条,也就可以同行控制多个单元的颜色。

      loop at <gt_outtab> assigning <ls_outtab>.
        add 1 to l_color_index.
        clear lt_color_slis.
        case l_color_index.
          when 1.
            ls_color_slis-color-col = cl_gui_resources=>list_col_background.
            ls_color_slis-color-int = 0.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 2.
            ls_color_slis-color-col = cl_gui_resources=>list_col_background.
            ls_color_slis-color-int = cl_gui_resources=>list_intensified.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 3.
            ls_color_slis-color-col = cl_gui_resources=>list_col_heading.
            ls_color_slis-color-int = 0.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 4.
            ls_color_slis-color-col = cl_gui_resources=>list_col_heading.
            ls_color_slis-color-int = cl_gui_resources=>list_intensified.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 5.
            ls_color_slis-color-col = cl_gui_resources=>list_col_normal.
            ls_color_slis-color-int = 0.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 6.
            ls_color_slis-color-col = cl_gui_resources=>list_col_normal.
            ls_color_slis-color-int = cl_gui_resources=>list_intensified.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 7.
            ls_color_slis-color-col = cl_gui_resources=>list_col_total.
            ls_color_slis-color-int = 0.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 8.
            ls_color_slis-color-col = cl_gui_resources=>list_col_total.
            ls_color_slis-color-int = cl_gui_resources=>list_intensified.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 9.
            ls_color_slis-color-col = cl_gui_resources=>list_col_key.
            ls_color_slis-color-int = 0.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 10.
            ls_color_slis-color-col = cl_gui_resources=>list_col_key.
            ls_color_slis-color-int = cl_gui_resources=>list_intensified.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 11.
            ls_color_slis-color-col = cl_gui_resources=>list_col_positive.
            ls_color_slis-color-int = 0.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 12.
            ls_color_slis-color-col = cl_gui_resources=>list_col_positive.
            ls_color_slis-color-int = cl_gui_resources=>list_intensified.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 13.
            ls_color_slis-color-col = cl_gui_resources=>list_col_negative.
            ls_color_slis-color-int = 0.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 14.
            ls_color_slis-color-col = cl_gui_resources=>list_col_negative.
            ls_color_slis-color-int = cl_gui_resources=>list_intensified.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 15.
            ls_color_slis-color-col = cl_gui_resources=>list_col_group.
            ls_color_slis-color-int = 0.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
          when 16.
            ls_color_slis-color-col = cl_gui_resources=>list_col_group.
            ls_color_slis-color-int = cl_gui_resources=>list_intensified.
            ls_color_slis-color-inv = 0.
            ls_color_slis-nokeycol  = con_true.
            clear l_color_index.
        endcase.
    *查找同行多少列需要设置颜色,则生成多条颜色纪录
        loop at gs_test-color_fields_cell into l_field.
          read table lt_fcat assigning <ls_fcat>
                     with key fieldname = l_field.
          if sy-subrc eq 0.
            ls_color_slis-fieldname = <ls_fcat>-fieldname.
            append ls_color_slis to lt_color_slis.
          endif.
        endloop.
    *将颜色纪录添加到数据输出表的TABCOLOR字段
        assign component 'TABCOLOR' of structure <ls_outtab> to <lt_table>.
        if sy-subrc eq 0.
          append lines of lt_color_slis to <lt_table>.
        endif.
      endloop.
    endform.                    " f01_set_color
    *&---------------------------------------------------------------------*
    *&      Form  f01_f4_fcode
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    form f01_f4_fcode changing c_value type lvc_s_fcat-fieldname.

      data: lt_fcat type slis_t_fieldcat_alv,
            ls_fcat type slis_fieldcat_alv.
      data: lt_values type table of seahlpres,
            lt_fields type table of dfies,
            lt_return type table of ddshretval,
            ls_value  type seahlpres,
            ls_field  type dfies,
            ls_return type ddshretval.
      perform f01_set_fcat changing lt_fcat.
      clear ls_field.
      ls_field-fieldname = 'FIELDNAME'.
      ls_field-intlen    = 30.
      ls_field-leng      = 30.
      ls_field-outputlen = 30.
      ls_field-scrtext_s = ls_field-fieldname.
      ls_field-scrtext_m = ls_field-fieldname.
      ls_field-scrtext_l = ls_field-fieldname.
      ls_field-reptext   = ls_field-fieldname.
      append ls_field to lt_fields.
      loop at lt_fcat into ls_fcat where tech eq space.
        ls_value-string = ls_fcat-fieldname.
        append ls_value to lt_values.
      endloop.
      call function 'F4IF_INT_TABLE_VALUE_REQUEST'
       exporting
         retfield               = 'FIELDNAME'
         display                = space
       tables
         value_tab              = lt_values
         field_tab              = lt_fields
         return_tab             = lt_return
       exceptions
         parameter_error        = 1
         no_values_found        = 2
         others                 = 3.
      if sy-subrc <> 0 and sy-subrc ne 3.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
      read table lt_return into ls_return  with key fieldname = 'FIELDNAME'.
      if sy-subrc eq 0.
        c_value = ls_return-fieldval.
      endif.
    endform.                    " f01_f4_fcode

     
  • 相关阅读:
    SpingMVC类型转换
    SpingMVC系统异常处理(二)
    JDBC 之 事务
    JDBC 基础概念
    部分实用的SQL语句
    JDBC基础学习
    手动去除集合中重复元素
    三种形式遍历集合
    java IO流 复制图片
    java IO流 之 字符流
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157128.html
Copyright © 2011-2022 走看看