Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

1. Have a field designated for the color.

For eg:

Error rendering macro 'code': Invalid value specified for parameter 'lang'
TYPES:
    BEGIN OF TW_XRESULT,
            TEXT      TYPE ZSDTYPE,
            VBELN    TYPE VBELN,
            ERNAM   TYPE ERNAM,
            PERSRB   TYPE ZPERS_RESP,
            ERDAT     TYPE ERDAT,
            VKORG     TYPE VKORG,
            VTWEG    TYPE VTWEG,
            SPART      TYPE SPART,
            VKBUR     TYPE VKBUR,
            VKGRP     TYPE VKGRP,
            VBTYP     TYPE VBTYP,
            FEHLER     TYPE ZNUMBER,
            NETWR     TYPE NETWR_AK,
            UVALL       TYPE UVALL,
            UVVLK      TYPE UVVLK,
            UVFAK     TYPE UVFAK,
            UVPRS     TYPE UVPRS,
            T_COLOR  TYPE LVC_T_SCOL,     "For row color
          END OF TW_XRESULT .
TYPES:
  TT_RESULT  TYPE STANDARD TABLE OF TW_XRESULT .
2. REGISTER THE EVENTS FOR WHICH YOU NEED TO ACT UPON.
METHOD ALV_SET_EVENTS.
  DATA: LR_EVENTS TYPE REF TO CL_SALV_EVENTS_TABLE.
  LR_EVENTS = MCN_ALV-> GET_EVENT().
*- Register the event Double click
  SET HANDLER ME->MT_ON_DOUBLE_CLICK FOR LR_EVENTS.
*- Register the event User command
  SET HANDLER ME->MT_ON_USER_COMMAND FOR LR_EVENTS.
ENDMETHOD.                    "ALV_SET_EVENTS
*3. ONCE THE REQUIRED DATA IS FETCHED INTO THE INTERNAL TABLE (SAY, INTO INTERNAL TABLE MT_RESULT), WE USE THE FOLLOWING CODE, TO DISPLAY THE RECORDS WITH PROVISION TO SELECT MULTIPLE RECORDS (THROUGH THE SELECTION PUSHBUTTON ON THE LEFT FOR EACH RECORD)
METHOD ALV_SHOW .
  DATA : LR_SELECTIONS TYPE REF TO CL_SALV_SELECTIONS.
  FIELD-SYMBOLS: <FS_DATA> TYPE STANDARD TABLE.
*- Show ALV on the screen
  ASSIGN ME->MN_DATA->* TO <FS_DATA>.
  CHECK <FS_DATA> IS ASSIGNED.
  TRY.
      CL_SALV_TABLE=>FACTORY( EXPORTING LIST_DISPLAY = ABAP_FALSE
                              IMPORTING R_SALV_TABLE = MCN_ALV
                               CHANGING T_TABLE = <FS_DATA> ).
    CATCH CX_SALV_MSG INTO MCN_ALV_EXCEPTION.
      MESSAGE MCN_ALV_EXCEPTION TYPE 'E'.
      EXIT.
  ENDTRY.
  ME->ALV_SET_FUNCTIONS( ).
  ME->ALV_SET_COLUMNS( ).
  ME->ALV_SET_LAYOUT( MF_VARIANTNAME ).
  ME->ALV_SET_EVENTS( ).
  ME->ALV_SET_HEADERS( ).
  CALL METHOD ALV_MODIFY_SETTINGS( ).
  LR_SELECTIONS = MCN_ALV->GET_SELECTIONS( ).
  LT_ROWS = LR_SELECTIONS->GET_SELECTED_ROWS().      " This will get the selected record numbers, in lt_rows.
*- Set selection mode
  LR_SELECTIONS->SET_SELECTION_MODE( IF_SALV_C_SELECTION_MODE=>ROW_COLUMN ).
  MCN_ALV->SET_SCREEN_STATUS(
  PFSTATUS      =  'ZREPINCOMP'
  REPORT        =  MF_REPID
  SET_FUNCTIONS = MCN_ALV->C_FUNCTIONS_ALL ).
  MCN_ALV->DISPLAY( ).
ENDMETHOD.                    "ALV_SET_EVENTS
*4. WITH THE ABOVE CODE, YOU WILL BE ABLE TO SELECT MULTIPLE RECORDS, AND THEN THE FOLLOWING CODE WILL PROCESS THE SELECTED RECORDS, AND SET A COLOR FOR THE PROCESSED RECORDS.
DATA:   LW_ROW        TYPE I,
     LT_COLOR TYPE LVC_T_SCOL ,
     LS_COLOR TYPE LVC_S_SCOL .
FIELD-SYMBOLS: <FS_RESULT> TYPE TW_XRESULT.                 "#EC NEEDED
LOOP AT LT_ROWS INTO LW_ROW.
  READ TABLE MT_RESULT ASSIGNING <FS_RESULT> INDEX LW_ROW.
  IF SY_SUBRC EQ 0.
*    <CODE FOR PROCESSING YOUR SELECTED RECORD>
*- For setting the color to the record
    CLEAR LT_COLOR.
    CLEAR LS_COLOR.
    LS_COLOR-COLOR-COL = CO_COLOR.
    LS_COLOR-COLOR-INT = 0.
    LS_COLOR-COLOR-INV = 0.
    APPEND LS_COLOR TO LT_COLOR.
    <FS_RESULT>-T_COLOR =  LT_COLOR.
  ENDIF.
ENDLOOP.