Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Traffic light in ALV

Hi,

I have to implement traffic light in GRID ALV.Can you please send me any simple code.

Tags:
replied

Copy and run the code which will explain traffic lights

PLease award points if found helpful

*&---------------------------------------------------------------------*
*& Report  Z_50657_ALV_EX2                                             *
*&                                                                     *
*&---------------------------------------------------------------------*
*& Program Name: Test Program for ALV                                  *
*  Developer Name: ADCDEV (Rahul Kavuri )                              *
*  Description: ALV Report to Display Vendor Details                   *
*& Date:7th April 2006                                                 *
*&---------------------------------------------------------------------*

REPORT  Z_50657_ALV_EX2
        NO STANDARD PAGE HEADING
        LINE-COUNT 65(3)
        LINE-SIZE 220
        MESSAGE-ID ZZ.


************************************************************************
*                             Type Pools                               *
************************************************************************

TYPE-POOLS: SLIS, ICON.

************************************************************************
*                              Tables                                  *
************************************************************************

TABLES: VBAK. "Sales Document Data

************************************************************************
*                         Internal Tables                              *
************************************************************************

* TABLE TO HOLD DATA OF SALES DOCUMENT

DATA: BEGIN OF IT_VBAK OCCURS 0,
      VBELN LIKE VBAK-VBELN, "Sales Document
      VBTYP LIKE VBAK-VBTYP, "SD document category
      AUDAT LIKE VBAK-AUDAT, "Document date (date received/sent)
      AUGRU LIKE VBAK-AUGRU, "Order reason (reason for the business)
      AUART LIKE VBAK-AUART, "Sales Document Type
      NETWR LIKE VBAK-NETWR, "Net Sales Order in Doc. Currency
      WAERK LIKE VBAK-WAERK, "SD document currency
      ICON TYPE ICON-ID,     "traffic lights
      END OF IT_VBAK.


************************************************************************
*                             Work Areas                               *
************************************************************************

*WORK AREAS DEFINED FOR ALV'S
DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,      "field catalog
      IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,     "field catalog ITAB
      WA_SORT TYPE SLIS_SORTINFO_ALV,           "SORT work area
      IT_SORT TYPE SLIS_T_SORTINFO_ALV,         "SORT ITAB
      LAYOUT TYPE SLIS_LAYOUT_ALV,              "LAYOUT
      WA_FCODE TYPE SLIS_EXTAB,                 "FUN CODE
      I_FCODE_EXTAB TYPE SLIS_T_EXTAB,
      WA_EVENTS TYPE SLIS_ALV_EVENT,
      IT_EVENTS TYPE SLIS_T_EVENT.
.


************************************************************************
*                       Selection-Screen                               *
************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
PARAMETERS: P_VBTYP LIKE VBAK-VBTYP DEFAULT 'C'.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
PARAMETERS: LIST RADIOBUTTON GROUP G1,
            GRID RADIOBUTTON GROUP G1.

SELECTION-SCREEN END OF BLOCK B2.

************************************************************************
*                     At  Selection-Screen                             *
************************************************************************
*VALIDATION

************************************************************************
*                       Start of Selection                             *
************************************************************************

START-OF-SELECTION.

*POPULATION OF DATA INTO INTERNAL TABLE ITAB
  PERFORM GET_DATA.

*DEFINE USER DEFINED FIELDCATALOG
  PERFORM DEFINE_FIELDCATALOG.

*SUBTOTALS AND TOTALS DISPLAY USING SORT
  PERFORM SORT_LIST.

*CHANGE FCODE OF STATUS
  PERFORM CHANGE_FCODE.

*CHECK RADIOBUTTON OPTION AND ACCORDINGLY FINAL DISPLAY
  PERFORM CHECK_OPTION.

*&--------------------------------------------------------------------*
*&      Form  GET_DATA
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM GET_DATA.

  SELECT VBELN
         VBTYP
         AUDAT
         AUGRU
         AUART
         NETWR
         WAERK FROM VBAK INTO TABLE IT_VBAK
         WHERE VBELN IN S_VBELN AND VBTYP = P_VBTYP
         AND ERDAT > '01.01.2004' AND NETWR > 0.

  LOOP AT IT_VBAK.

    IF IT_VBAK-NETWR < 10000.
      IT_VBAK-ICON = '@08@'.

    ELSEIF IT_VBAK-NETWR > 100000.
      IT_VBAK-ICON = '@0A@'.

    ELSE.
      IT_VBAK-ICON = '@09@'.

    ENDIF.

    MODIFY IT_VBAK INDEX SY-TABIX.

  ENDLOOP.

ENDFORM.                    "GET_DATA

*&--------------------------------------------------------------------*
*&      Form  CHECK_OPTION
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM CHECK_OPTION.

  WA_EVENTS-NAME = 'TOP_OF_PAGE'.
  WA_EVENTS-FORM = 'TOP'.
  APPEND WA_EVENTS TO IT_EVENTS.
  CLEAR WA_EVENTS.

  WA_EVENTS-NAME = 'END_OF_LIST'.
  WA_EVENTS-FORM = 'END_LIST'.
  APPEND WA_EVENTS TO IT_EVENTS.
  CLEAR WA_EVENTS.
  IF LIST = 'X'.

    PERFORM LIST_DISP.

  ENDIF.
  IF GRID = 'X'.

    PERFORM GRID_DISP.

  ENDIF.

ENDFORM.                    "CHECK_OPTION



*&--------------------------------------------------------------------*
*&      Form  DEFINE_FIELDCATALOG
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM DEFINE_FIELDCATALOG.


  WA_FIELDCAT-COL_POS = 1.
  WA_FIELDCAT-FIELDNAME = 'ICON'.
  WA_FIELDCAT-SELTEXT_L = 'ICON'.
  WA_FIELDCAT-ICON = 'X'.
  WA_FIELDCAT-OUTPUTLEN = 8.
  WA_FIELDCAT-TABNAME = 'IT_VBAK'.
  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-COL_POS = 2.
  WA_FIELDCAT-FIELDNAME = 'VBELN'.
  WA_FIELDCAT-SELTEXT_L = 'SALES DOC NO.'.
  WA_FIELDCAT-OUTPUTLEN = 10.
  WA_FIELDCAT-TABNAME = 'IT_VBAK'.
  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-COL_POS = 3.
  WA_FIELDCAT-FIELDNAME = 'AUDAT'.
  WA_FIELDCAT-SELTEXT_L = 'CREATED ON'.
  WA_FIELDCAT-OUTPUTLEN = 10.
  WA_FIELDCAT-TABNAME = 'IT_VBAK'.
  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-COL_POS = 4.
  WA_FIELDCAT-FIELDNAME = 'VBTYP'.
  WA_FIELDCAT-SELTEXT_L = 'CATEGORY'.
  WA_FIELDCAT-OUTPUTLEN = 1.
  WA_FIELDCAT-TABNAME = 'IT_VBAK'.
  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-COL_POS = 6.
  WA_FIELDCAT-FIELDNAME = 'AUGRU'.
  WA_FIELDCAT-SELTEXT_L = 'REASON'.
  WA_FIELDCAT-OUTPUTLEN = 3.
  WA_FIELDCAT-TABNAME = 'IT_VBAK'.
  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-COL_POS = 5.
  WA_FIELDCAT-FIELDNAME = 'AUART'.
  WA_FIELDCAT-SELTEXT_L = 'DOC TYPE'.
  WA_FIELDCAT-OUTPUTLEN = 4.
  WA_FIELDCAT-TABNAME = 'IT_VBAK'.
  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-COL_POS = 7.
  WA_FIELDCAT-FIELDNAME = 'NETWR'.
  WA_FIELDCAT-SELTEXT_L = 'NET VALUE'.
  WA_FIELDCAT-OUTPUTLEN = 17.
  WA_FIELDCAT-DECIMALS_OUT = 2.
*  WA_FIELDCAT-DO_SUM = 'X'.
  WA_FIELDCAT-TABNAME = 'IT_VBAK'.
  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

  WA_FIELDCAT-COL_POS = 8.
  WA_FIELDCAT-FIELDNAME = 'WAERK'.
  WA_FIELDCAT-SELTEXT_L = 'UNIT'.
  WA_FIELDCAT-OUTPUTLEN = 50.
  WA_FIELDCAT-TABNAME = 'IT_VBAK'.
  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.

ENDFORM.                    "DEFINE_FIELDCATALOG

*&--------------------------------------------------------------------*
*&      Form  DEFINE_LAYOUT
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM DEFINE_LAYOUT.

  LAYOUT-ZEBRA = 'X'.
  LAYOUT-SUBTOTALS_TEXT = 'SUBTOTAL SUM'.
  LAYOUT-WINDOW_TITLEBAR = 'EXERCISE 2'.
  LAYOUT-TOTALS_TEXT  = 'TOTAL'.

ENDFORM.                    "DEFINE_LAYOUT

*&--------------------------------------------------------------------*
*&      Form  SORT_LIST
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM SORT_LIST.

  WA_SORT-FIELDNAME = 'VBELN'.
  WA_SORT-TABNAME = 'IT_VBAK'.
  WA_SORT-SPOS = 1.
  WA_SORT-UP = 'X'.
  WA_SORT-SUBTOT = 'X'.
  APPEND WA_SORT TO IT_SORT.
  CLEAR WA_SORT.

  WA_SORT-FIELDNAME = 'NETWR'.
  WA_SORT-TABNAME = 'IT_VBAK'.
  WA_SORT-UP = 'X'.
  WA_SORT-SPOS = 2.
  WA_SORT-SUBTOT = 'X'.
  APPEND WA_SORT TO IT_SORT.
  CLEAR WA_SORT.

ENDFORM.                    "SORT_LIST
*&--------------------------------------------------------------------*
*&      Form  LIST_DISP
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM LIST_DISP.

  PERFORM DEFINE_LAYOUT.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
     I_CALLBACK_PROGRAM             = SY-REPID
     IT_FIELDCAT                    = IT_FIELDCAT
     IS_LAYOUT                      = LAYOUT
     IT_SORT                        = IT_SORT
     I_CALLBACK_PF_STATUS_SET       = 'STATUS'
     IT_EXCLUDING                   = I_FCODE_EXTAB
     I_CALLBACK_USER_COMMAND        = 'USER_COMMAND'
     IT_EVENTS                      = IT_EVENTS[]


*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER        =
*     ES_EXIT_CAUSED_BY_USER         =
    TABLES
     T_OUTTAB                       = IT_VBAK
*   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.                    "LIST_DISP


*&--------------------------------------------------------------------*
*&      Form  GRID_DISP
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM GRID_DISP.

  PERFORM DEFINE_LAYOUT.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID
      IS_LAYOUT                = LAYOUT
      IT_FIELDCAT              = IT_FIELDCAT
      IT_SORT                  = IT_SORT
      I_CALLBACK_PF_STATUS_SET = 'STATUS'
      IT_EXCLUDING             = I_FCODE_EXTAB
      I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
      IT_EVENTS                = IT_EVENTS[]
    TABLES
      T_OUTTAB                 = IT_VBAK.

* 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.                    "GRID_DISP

*&--------------------------------------------------------------------*
*&      Form  STATUS
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->P_EXTAB    text
*---------------------------------------------------------------------*
FORM STATUS USING P_EXTAB TYPE SLIS_T_EXTAB.

  SET PF-STATUS 'STATUS' EXCLUDING P_EXTAB.

ENDFORM.                    "STATUS

*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*

FORM USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                               RS_SELFIELD TYPE SLIS_SELFIELD.

  CASE R_UCOMM.
    WHEN 'BACK' OR 'CANC' OR 'EXIT'.
      LEAVE TO SCREEN 0.

    WHEN '&IC1'.
      SET PARAMETER ID 'AUN' FIELD RS_SELFIELD-VALUE.
      CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
  ENDCASE.

ENDFORM.                    "USER_COMMAND

*&--------------------------------------------------------------------*
*&      Form  CHANGE_FCODE
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM CHANGE_FCODE.

  WA_FCODE = 'PRNT'.
  APPEND WA_FCODE TO I_FCODE_EXTAB.

  WA_FCODE = '&OAD'.
  APPEND WA_FCODE TO I_FCODE_EXTAB.

  WA_FCODE = '&AVE'.
  APPEND WA_FCODE TO I_FCODE_EXTAB.

  WA_FCODE = '&EB9'.
  APPEND WA_FCODE TO I_FCODE_EXTAB.

  WA_FCODE = '&SUM'.
  APPEND WA_FCODE TO I_FCODE_EXTAB.

  WA_FCODE = '&UMC'.
  APPEND WA_FCODE TO I_FCODE_EXTAB.

  WA_FCODE = '&XPA'.
  APPEND WA_FCODE TO I_FCODE_EXTAB.

  WA_FCODE = '&OMP'.
  APPEND WA_FCODE TO I_FCODE_EXTAB.


ENDFORM.                    "CHANGE_FCODE


*&--------------------------------------------------------------------*
*&      Form  TOP
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM TOP.

  IF LIST = 'X'.

    WRITE:/ SY-ULINE.
    WRITE:/ 'DATE:', SY-DATUM,55 'INTELLIGROUP ASIA PVT LTD'.
    WRITE:/ 'TIME:', SY-UZEIT.
    WRITE:/ 'USER NAME:', SY-UNAME,60 SY-TITLE.
    WRITE:/ 'PAGE', SY-PAGNO.
    WRITE:/ SY-ULINE.

  ENDIF.

  IF GRID = 'X'.

    DATA: LS_LINE TYPE SLIS_LISTHEADER,
          E04_LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

*   Listen├╝berschrift: Typ H
    CLEAR LS_LINE.
    LS_LINE-TYP  = 'H'.

*   LS_LINE-KEY:  not used for this type
    LS_LINE-INFO = 'Summary'.
    APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

*   Kopfinfo: Typ S
    CLEAR LS_LINE.
    LS_LINE-TYP  = 'S'.
    LS_LINE-KEY  = 'Intelligroup'.
    LS_LINE-INFO = ''.
    APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
    LS_LINE-KEY  = 'ASIA'.
    LS_LINE-INFO = 'PVT LTD'.
    APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

*   Aktionsinfo: Typ A
    CLEAR LS_LINE.
    LS_LINE-TYP  = 'A'.

*   LS_LINE-KEY:  not used for this type
    LS_LINE-INFO = 'truman'.
    APPEND LS_LINE TO  E04_LT_TOP_OF_PAGE.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY = E04_LT_TOP_OF_PAGE
        I_LOGO             = 'ENJOY_SAP_LOGO'.
  ENDIF.

ENDFORM.                    "TOP

*&--------------------------------------------------------------------*
*&      Form  END_LIST
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM END_LIST.

  IF LIST = 'X'.
    SKIP 2.
    WRITE:/60 'END OF PAGE'.
  ENDIF.

  IF GRID = 'X'.

      DATA: LS_LINE TYPE SLIS_LISTHEADER,
          E04_LT_END_OF_LIST TYPE SLIS_T_LISTHEADER.

*   Listen├╝berschrift: Typ H
    CLEAR LS_LINE.
    LS_LINE-TYP  = 'H'.

*   LS_LINE-KEY:  not used for this type
    LS_LINE-INFO = 'Summary'.
    APPEND LS_LINE TO E04_LT_END_OF_LIST.

*   Kopfinfo: Typ S
    CLEAR LS_LINE.
    LS_LINE-TYP  = 'S'.
    LS_LINE-KEY  = 'Intelligroup'.
    LS_LINE-INFO = ''.
    APPEND LS_LINE TO E04_LT_END_OF_LIST.
    LS_LINE-KEY  = 'ASIA'.
    LS_LINE-INFO = 'PVT LTD'.
    APPEND LS_LINE TO E04_LT_END_OF_LIST.

*   Aktionsinfo: Typ A
    CLEAR LS_LINE.
    LS_LINE-TYP  = 'A'.

*   LS_LINE-KEY:  not used for this type
    LS_LINE-INFO = TEXT-105.
    APPEND LS_LINE TO  E04_LT_END_OF_LIST.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY = E04_LT_END_OF_LIST.


  ENDIF.

ENDFORM.                    "END_LIST

Message was edited by: Rahul Kavuri

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question