在ALV的输出单元格中着色

在网上搜了一下,这样的信息不是很多,根据找到的相关知识,我自己尝试做了一下:

FORM SUB_FILL_COLOR.
  LOOP AT I_LIST INTO WA_ITAB.
  I_INDEX = SY-TABIX .
  CLEAR WA_ITAB2.
    MOVE-CORRESPONDING WA_ITAB TO WA_ITAB2.
    PERFORM F_MODIFY_COLOR USING 'WERKS' CHANGING WA_ITAB2.
    PERFORM F_MODIFY_COLOR USING 'MATNR' CHANGING WA_ITAB2.
    PERFORM F_MODIFY_COLOR USING 'MAKTX' CHANGING WA_ITAB2.
    PERFORM F_MODIFY_COLOR USING 'MATKL' CHANGING WA_ITAB2.
    MODIFY I_LIST FROM WA_ITAB2 INDEX I_INDEX.
  ENDLOOP.
ENDFORM.

FORM F_MODIFY_COLOR USING U_FIELDNAME TYPE LVC_FNAME
CHANGING USE_ITAB LIKE I_LIST.
DATA :
  L_RND_VALUE TYPE INTEGER2,
  LS_TABCOLOR TYPE LVC_S_SCOL.
* Random value
  CALL FUNCTION 'RANDOM_I2'
    EXPORTING
      RND_MIN   = 0
      RND_MAX   = 3
    IMPORTING
      RND_VALUE = L_RND_VALUE.

  CLEAR LS_TABCOLOR.
  LS_TABCOLOR-FNAME = U_FIELDNAME.
  CASE L_RND_VALUE.
    WHEN 0.
      LS_TABCOLOR-COLOR-COL = 1. " Blue.
      LS_TABCOLOR-COLOR-INT = 0.
      LS_TABCOLOR-COLOR-INV = 0.
    WHEN 1.
      LS_TABCOLOR-COLOR-COL = 3. " Yellow.
      LS_TABCOLOR-COLOR-INT = 0.
      LS_TABCOLOR-COLOR-INV = 0.
    WHEN 2.
      LS_TABCOLOR-COLOR-COL = 5. " Green.
      LS_TABCOLOR-COLOR-INT = 0.
      LS_TABCOLOR-COLOR-INV = 0.
    WHEN 3.
      LS_TABCOLOR-COLOR-COL = 6. " Red.
      LS_TABCOLOR-COLOR-INT = 0.
      LS_TABCOLOR-COLOR-INV = 0.
  ENDCASE.
  INSERT LS_TABCOLOR INTO TABLE USE_ITAB-TABCOLOR.
ENDFORM. " F_MODIFY_COLOR
*-----------------------------------------------*
* Fill Layout
   L_S_LAYOUT-COLTAB_FIELDNAME = 'TABCOLOR'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            ...
   

你可能感兴趣的:(F#)