用ALV表中的所有最大值填充颜色

问题描述 投票:1回答:2

我需要将颜色放入每列中具有值的所有单元格中。

我想展示这样的东西。

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS85QXNMMi5wbmcifQ==” alt =“带有彩色单元格的ALV网格”>“>

这是我的代码:

    SORT gt_sehir_dilim_alv BY
          saat1 DESCENDING
          saat2 DESCENDING
          saat3 DESCENDING
          saat4 DESCENDING
          saat5 DESCENDING
          saat6 DESCENDING
          saat7 DESCENDING.

  LOOP AT gt_sehir_dilim_alv INTO gs_sehir_dilim_alv.
    lv_index = sy-tabix.

    IF lv_index EQ '1'.

      wa_cellcolor-fname = 'SAAT1'.
      wa_cellcolor-color-col =  1.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
      TRANSPORTING cellcolor.


      wa_cellcolor-fname = 'SAAT2'.
      wa_cellcolor-color-col =  1.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
      TRANSPORTING cellcolor.


      wa_cellcolor-fname = 'SAAT3'.
      wa_cellcolor-color-col =  1.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
      TRANSPORTING cellcolor.

      wa_cellcolor-fname = 'SAAT4'.
      wa_cellcolor-color-col =  1.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
      TRANSPORTING cellcolor.

      wa_cellcolor-fname = 'SAAT5'.
      wa_cellcolor-color-col =  1.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
      TRANSPORTING cellcolor.

      wa_cellcolor-fname = 'SAAT6'.
      wa_cellcolor-color-col =  1.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
      TRANSPORTING cellcolor.

      wa_cellcolor-fname = 'SAAT7'.
      wa_cellcolor-color-col =  1.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
      TRANSPORTING cellcolor.
    ENDIF.
  ENDLOOP.

我也尝试过使用此代码。但是它根据需求绘制基于行的单元格:

  LOOP AT gt_sehir_dilim_alv INTO gs_sehir_dilim_alv.
    lv_index = sy-tabix.

    SORT gt_sehir_dilim_alv BY saat1 saat2 saat3 saat4 saat5
                               saat6 saat7  ASCENDING.
*
*    READ TABLE gt_sehir_dilim_alv INTO gs_sehir_dilim_alv INDEX 1.

    IF gs_sehir_dilim_alv-saat1 NE 0
   and gs_sehir_dilim_alv-saat2 NE 0
   AND gs_sehir_dilim_alv-saat3 NE 0
   AND gs_sehir_dilim_alv-saat4 NE 0
   AND gs_sehir_dilim_alv-saat5 NE 0
   AND gs_sehir_dilim_alv-saat6 NE 0
   AND gs_sehir_dilim_alv-saat7 NE 0.

    ELSEIF gs_sehir_dilim_alv-saat1 GT gs_sehir_dilim_alv-saat2
       AND gs_sehir_dilim_alv-saat1 GT gs_sehir_dilim_alv-saat3
       AND gs_sehir_dilim_alv-saat1 GT gs_sehir_dilim_alv-saat4
       AND gs_sehir_dilim_alv-saat1 GT gs_sehir_dilim_alv-saat5
       AND gs_sehir_dilim_alv-saat1 GT gs_sehir_dilim_alv-saat6
       AND gs_sehir_dilim_alv-saat1 GT gs_sehir_dilim_alv-saat7.

      "7.40 kodu - wa_fcat kullanmadan edit atabiliyoruz.
      APPEND VALUE #( fname     = 'SAAT1'
                      color-col =  6
                      color-int = '1'
                      color-inv = '0' ) TO
gs_sehir_dilim_alv-cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
      TRANSPORTING cellcolor.

    ELSEIF gs_sehir_dilim_alv-saat2 GT gs_sehir_dilim_alv-saat1
       AND gs_sehir_dilim_alv-saat2 GT gs_sehir_dilim_alv-saat3
       AND gs_sehir_dilim_alv-saat2 GT gs_sehir_dilim_alv-saat4
       AND gs_sehir_dilim_alv-saat2 GT gs_sehir_dilim_alv-saat5
       AND gs_sehir_dilim_alv-saat2 GT gs_sehir_dilim_alv-saat6
       AND gs_sehir_dilim_alv-saat2 GT gs_sehir_dilim_alv-saat7.


      wa_cellcolor-fname = 'SAAT2'.
      wa_cellcolor-color-col =  6.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.


    ELSEIF gs_sehir_dilim_alv-saat3 GT gs_sehir_dilim_alv-saat1
       AND gs_sehir_dilim_alv-saat3 GT gs_sehir_dilim_alv-saat2
       AND gs_sehir_dilim_alv-saat3 GT gs_sehir_dilim_alv-saat4
       AND gs_sehir_dilim_alv-saat3 GT gs_sehir_dilim_alv-saat5
       AND gs_sehir_dilim_alv-saat3 GT gs_sehir_dilim_alv-saat6
       AND gs_sehir_dilim_alv-saat3 GT gs_sehir_dilim_alv-saat7.

      wa_cellcolor-fname = 'SAAT3'.
      wa_cellcolor-color-col =  6.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
            TRANSPORTING cellcolor.


    ELSEIF gs_sehir_dilim_alv-saat4 GT gs_sehir_dilim_alv-saat1
       AND gs_sehir_dilim_alv-saat4 GT gs_sehir_dilim_alv-saat2
       AND gs_sehir_dilim_alv-saat4 GT gs_sehir_dilim_alv-saat3
       AND gs_sehir_dilim_alv-saat4 GT gs_sehir_dilim_alv-saat5
       AND gs_sehir_dilim_alv-saat4 GT gs_sehir_dilim_alv-saat6
       AND gs_sehir_dilim_alv-saat4 GT gs_sehir_dilim_alv-saat7
      .
      wa_cellcolor-fname = 'SAAT4'.
      wa_cellcolor-color-col =  6.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
            TRANSPORTING cellcolor.


    ELSEIF gs_sehir_dilim_alv-saat5 GT gs_sehir_dilim_alv-saat1
       AND gs_sehir_dilim_alv-saat5 GT gs_sehir_dilim_alv-saat2
       AND gs_sehir_dilim_alv-saat5 GT gs_sehir_dilim_alv-saat3
       AND gs_sehir_dilim_alv-saat5 GT gs_sehir_dilim_alv-saat4
       AND gs_sehir_dilim_alv-saat5 GT gs_sehir_dilim_alv-saat6
       AND gs_sehir_dilim_alv-saat5 GT gs_sehir_dilim_alv-saat7.

      wa_cellcolor-fname = 'SAAT5'.
      wa_cellcolor-color-col =  6.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.

      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
            TRANSPORTING cellcolor.


    ELSEIF gs_sehir_dilim_alv-saat6 GT gs_sehir_dilim_alv-saat1
       AND gs_sehir_dilim_alv-saat6 GT gs_sehir_dilim_alv-saat2
       AND gs_sehir_dilim_alv-saat6 GT gs_sehir_dilim_alv-saat3
       AND gs_sehir_dilim_alv-saat6 GT gs_sehir_dilim_alv-saat4
       AND gs_sehir_dilim_alv-saat6 GT gs_sehir_dilim_alv-saat5
       AND gs_sehir_dilim_alv-saat6 GT gs_sehir_dilim_alv-saat7.

      wa_cellcolor-fname = 'SAAT6'.
      wa_cellcolor-color-col =  6.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
            TRANSPORTING cellcolor.

    ELSEIF gs_sehir_dilim_alv-saat7 GT gs_sehir_dilim_alv-saat1
       AND gs_sehir_dilim_alv-saat7 GT gs_sehir_dilim_alv-saat2
       AND gs_sehir_dilim_alv-saat7 GT gs_sehir_dilim_alv-saat3
       AND gs_sehir_dilim_alv-saat7 GT gs_sehir_dilim_alv-saat4
       AND gs_sehir_dilim_alv-saat7 GT gs_sehir_dilim_alv-saat5
       AND gs_sehir_dilim_alv-saat7 GT gs_sehir_dilim_alv-saat6.

      wa_cellcolor-fname = 'SAAT7'.
      wa_cellcolor-color-col =  6.
      wa_cellcolor-color-int = '1'.
      wa_cellcolor-color-inv = '0'.
      APPEND wa_cellcolor TO gs_sehir_dilim_alv-cellcolor.
      CLEAR: wa_cellcolor.
      MODIFY gt_sehir_dilim_alv FROM gs_sehir_dilim_alv
      TRANSPORTING cellcolor.

    ENDIF.
  ENDLOOP.

我需要将颜色放入每列中具有值的所有单元格中。我想展示这样的东西。这是我的代码:按saat1降序排序SORT gt_sehir_dilim_alv ...

sap abap alv
2个回答
0
投票

我创建了另一个额外的itab,我将所有值都放入其中。按照排序顺序降序后,我选择索引1与表itab进行比较,现在无法将单元格颜色设为最高值。


0
投票

这里是示例,如何对表ANLC的3个字段执行此操作,而没有附加的Itab和循环:

© www.soinside.com 2019 - 2024. All rights reserved.