Display Traffic Lights in SAP ALV Grid

DISPLAY TRAFFIC LIGHTS IN SAP ALV GRID | Showing Traffic Light Icon on ALV Grid Report | Showing traffic light for each row status in ALV | Display traffic light icon on ALV grid report.

Showing Traffic Light Icon on ALV Grid Report
DISPLAY TRAFFIC LIGHTS IN SAP ALV GRID

I have an ALV GRID Report. I am using Function Module REUSE_ALV_GRID_DISPLAY to display my alv report. I am passing the field-catalogue automatically. I am getting the output perfectly. Now i have to add traffic lights to that alv report.

Some time we have to display a traffic light in ALV report to create an ALV report with traffic light icon we will follow the below mention steps.

Some of Standard process like creating purchase order by using ME21N, it shows the same traffic lights Red for Error, Green for success and Yellow for Warning.

DISPLAY TRAFFIC LIGHTS IN SAP ALV GRID

Below mention steps are for add traffic light icon in ALV Grid report.

  • Add Column in the structure which holds the traffic light value.
  1. (‘@0A@’ for Red Light Color)
  2. (‘@09@’ for Yellow Light Color)
  3. (‘@08@’ for Green Light Color)
Add Column in the structure which holds the traffic light value
DISPLAY TRAFFIC LIGHTS IN SAP ALV GRID
  • Retrieve Data from Database Tables and maintain value for traffic light icon according to required condition.
Retrieve Data from Database Tables and maintain value for traffic light icon according to required condition.
DISPLAY TRAFFIC LIGHTS IN SAP ALV GRID
  • Create Field catalog for ALV Grid report display.
Create Field catalog for ALV Grid report display
TRAFFIC LIGHTS IN SAP ALV GRID
Create Field catalog for ALV Grid report display
TRAFFIC LIGHTS IN SAP ALV GRID
Create Field catalog for ALV Grid report display
TRAFFIC LIGHTS IN SAP ALV GRID
  • Pass the fieldcatalog, table and layout into the function “REUSE_ALV_GRID_DISPLAY”.
Pass the fieldcatalog, table and layout into the function "REUSE_ALV_GRID_DISPLAY".
Create Field catalog for ALV Grid report displayTRAFFIC LIGHTS IN SAP
  • If you use below mention value for traffic light icon then you have to maintain the field ‘traffic’ which you use for traffic icon in layout-lights-fieldname = ‘traffic’.
  1. (1 for Red Light Color)
  2. (2 for Yellow Light Color)
  3. (3 for Green Light Color)
If you use below mention value for traffic light icon then you have to maintain the field 'traffic' which you use for traffic icon in layout-lights-fieldname = 'traffic'.
Create Field catalog for ALV Grid report display

Program Example of Showing Traffic light Icon in ALV Grid Report.


TYPES: BEGIN OF TY_EKPO,
         EBELN      TYPE EKPO-EBELN,
         EBELP      TYPE EKPO-EBELP,
         STATU      TYPE EKPO-STATU,
         AEDAT      TYPE EKPO-AEDAT,
         MATNR      TYPE EKPO-MATNR,
         MENGE      TYPE EKPO-MENGE,
         MEINS      TYPE EKPO-MEINS,
         NETPR      TYPE EKPO-NETPR,
         PEINH      TYPE EKPO-PEINH,
         TRAFFIC(4) TYPE C,
       END OF TY_EKPO.

DATA: IT_EKPO TYPE TABLE OF TY_EKPO,
      WA_EKPO TYPE          TY_EKPO.

DATA: IT_FCAT   TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT   TYPE SLIS_FIELDCAT_ALV,
      WA_LAYOUT TYPE SLIS_LAYOUT_ALV.

DATA L_COUNT TYPE I.

START-OF-SELECTION.

  PERFORM DATA_RETRIEVE.
  PERFORM BUILD_FIELDCATALOG.
  PERFORM BUILD_LAYOUT.
  PERFORM DISPLAY_REPORT.
*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DATA_RETRIEVE .

  SELECT EBELN EBELP STATU AEDAT MATNR MENGE MEINS NETPR PEINH
    FROM EKPO UP TO 10 ROWS
    INTO TABLE IT_EKPO.

  LOOP AT IT_EKPO INTO WA_EKPO.
    L_COUNT = L_COUNT + 1.

    CASE L_COUNT.
      WHEN 1.
        WA_EKPO-TRAFFIC = '@08@'.    "Green Light
      WHEN 2 .
        WA_EKPO-TRAFFIC = '@09@'.    "Yellow Light
      WHEN 3.
        WA_EKPO-TRAFFIC = '@0A@'.    "Red Light
        CLEAR: L_COUNT.
    ENDCASE.

    MODIFY IT_EKPO FROM WA_EKPO TRANSPORTING TRAFFIC.
    CLEAR WA_EKPO.

  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG .

  REFRESH IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = 0.
  WA_FCAT-FIELDNAME = 'TRAFFIC'.
  WA_FCAT-SELTEXT_M = 'TRAFFIC'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = 1.
  WA_FCAT-FIELDNAME = 'EBELN'.
  WA_FCAT-SELTEXT_L = 'PURCHASE ORDER NUMBER'.
  WA_FCAT-EMPHASIZE = 'X'.
  WA_FCAT-KEY = 'X'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = 2.
  WA_FCAT-FIELDNAME = 'EBELP'.
  WA_FCAT-SELTEXT_M = 'PO ITEM'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = 3.
  WA_FCAT-FIELDNAME = 'AEDAT'.
  WA_FCAT-SELTEXT_M = 'ITEM CHANGE DATE'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.


  WA_FCAT-COL_POS = 4.
  WA_FCAT-FIELDNAME = 'MATNR'.
  WA_FCAT-SELTEXT_M = 'MATERIAL NUMBER'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.


  WA_FCAT-COL_POS = 5.
  WA_FCAT-FIELDNAME = 'MENGE'.
  WA_FCAT-SELTEXT_M = 'PO QUANTITY'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.


  WA_FCAT-COL_POS = 6.
  WA_FCAT-FIELDNAME = 'MEINS'.
  WA_FCAT-SELTEXT_M = 'ORDER UNIT'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.



  WA_FCAT-COL_POS = 7.
  WA_FCAT-FIELDNAME = 'NETPR'.
  WA_FCAT-SELTEXT_M = 'NET PRICE'.
  WA_FCAT-DO_SUM = 'X'.
  WA_FCAT-DATATYPE = 'CURR'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.


  WA_FCAT-COL_POS = 8.
  WA_FCAT-FIELDNAME = 'PEINH'.
  WA_FCAT-SELTEXT_M = 'PRICE UNIT'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT .

  CLEAR WA_LAYOUT.

  WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  WA_LAYOUT-TOTALS_TEXT = 'TOTALS'(200).
  WA_LAYOUT-NO_INPUT = 'X'.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_REPORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_REPORT .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = 'SY-REPID'
      IS_LAYOUT          = WA_LAYOUT
      IT_FIELDCAT        = IT_FCAT
    TABLES
      T_OUTTAB           = IT_EKPO.
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.


ENDFORM.

OUTPUT OF PROGRAM.

Output with maintaining layout and without maintaining layout.

Maintain layout
Maintain layout

Without Maintaining Layout
Without Maintaining Layout

You May Also Like :

For the next blog please connect with us and follow us on twitter.com/einfonett

5 thoughts on “Display Traffic Lights in SAP ALV Grid”

Leave a Comment