ALV Row Color in ABAP F4 Help

To highlight ALV rows in different colors in F4 help popup just fill the proper color key.

Create a field in the output internal table to store color key. The internal output table field must be of type CHAR(3).

The coding must have the following syntax:
‘Cxy’:
C = color (each code must begin with ‘C’)
x = color number (‘1’-‘9’)
y = highlight (‘0’ = off, ‘1’ = on)

Note: the color of the key columns is not affected.

TYPE-POOLS: slis.
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_spfli,
       color(3) TYPE c.
INCLUDE TYPE spfli.
TYPES: END OF ty_spfli.
*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gt_spfli     TYPE TABLE OF ty_spfli.
DATA: gwa_spfli    TYPE ty_spfli.
DATA: gwa_selfield TYPE slis_selfield.
*--------------------------------------------------------------*
*Selection-Screen
*--------------------------------------------------------------*
PARAMETER: p_carrid TYPE spfli-carrid.
*--------------------------------------------------------------*
*Selection-Screen on Value-Request
*--------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_carrid.

  CLEAR: gwa_selfield.
**Fetch data from database
  SELECT * FROM spfli INTO CORRESPONDING FIELDS OF
           TABLE gt_spfli.
**Update color keys
  LOOP AT gt_spfli INTO gwa_spfli.
    IF gwa_spfli-carrid = 'AA'.
      gwa_spfli-color = 'C51'. " GREEN Color
    ELSEIF gwa_spfli-carrid = 'LH'.
      gwa_spfli-color = 'C71'. " ORANGE Color
    ENDIF.
    MODIFY gt_spfli FROM gwa_spfli.
    CLEAR gwa_spfli.
  ENDLOOP.
**Display ALV
  CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
    EXPORTING
      i_linemark_fieldname = 'COLOR'
      i_tabname            = 'GT_SPFLI'  " Internal table name
      i_structure_name     = 'SPFLI'
    IMPORTING
      es_selfield          = gwa_selfield
    TABLES
      t_outtab             = gt_spfli  " Internal table which contains entries
    EXCEPTIONS
      program_error        = 1
      OTHERS               = 2.

**User can click on any field in the popup, so just get the line index
**and get the corresponding carrid from internal table
READ TABLE gt_spfli INTO gwa_spfli INDEX gwa_selfield-tabindex.
IF sy-subrc = 0.
  p_carrid = gwa_selfield-value.
ENDIF.

Output

abap-alv-row-color-f4-help


1 Comment

Leave a Reply

Your email address will not be published.


*