Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Color a specific row in ALV GRID display when user clicks on that row

Former Member
0 Kudos
131

hi

i have the entire code ready of how to check the line selected by the user and also to color that line but after settings those parameters

for to refresh the GRID so that the row apppears coloured .plz reply soon.... points will be awarded.....

wat i have done is

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = i_repid

i_callback_user_command = 'USER_COMMAND'

is_layout = it_layout

it_fieldcat = int_fieldcat

TABLES

t_outtab = int

EXCEPTIONS

program_error = 1

OTHERS = 2.

to display the GRID then when user clicks on any row this module gets called

FORM user_command USING r_ucomm TYPE sy-ucomm

rs_selfield TYPE slis_selfield.

READ TABLE int INDEX rs_selfield-tabindex.

int-rowcolor = 'C410'.

MODIFY int INDEX rs_selfield-tabindex TRANSPORTING rowcolor.

it_layout-info_fieldname = 'ROWCOLOR'.

  • then again i call 'REUSE_ALV_GRID_DISPLAY'

to display the GRID with the user selected line colored . the problem with this is when u go back from this screen u go to the previously displayed grid ....... whihc i dont want .....

ENDFORM. "user_command

4 REPLIES 4

Former Member
0 Kudos
67

Hi,

By using following code,you can set the colors for each row,

Change this based on your requirement.

TABLES VBAK.

TYPE-POOLS SLIS.

  • Data Declaration

TYPES: BEGIN OF T_VBAK,

VBELN TYPE VBAK-VBELN,

ERDAT TYPE VBAK-ERDAT,

ERNAM TYPE VBAK-ERNAM,

AUDAT TYPE VBAK-AUDAT,

VBTYP TYPE VBAK-VBTYP,

NETWR TYPE VBAK-NETWR,

VKORG TYPE VBAK-VKORG,

VKGRP TYPE VBAK-VKGRP,

LINE_COLOR(4) TYPE C,

END OF T_VBAK.

DATA: IT_VBAK TYPE STANDARD TABLE OF T_VBAK INITIAL SIZE 0,

WA_VBAK TYPE T_VBAK.

  • ALV Data Declaration

DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,

GD_LAYOUT TYPE SLIS_LAYOUT_ALV,

GD_REPID TYPE SY-REPID.

START-OF-SELECTION.

PERFORM DATA_RETRIEVAL.

PERFORM BLD_FLDCAT.

PERFORM BLD_LAYOUT.

PERFORM DISPLAY_ALV_REPORT.

  • Build Field Catalog for ALV Report

FORM BLD_FLDCAT.

FLDCAT-FIELDNAME = 'VBELN'.

FLDCAT-SELTEXT_M = 'Sales Document'.

FLDCAT-COL_POS = 0.

*FLDCAT-EMPHASIZE = 'C411'.

FLDCAT-OUTPUTLEN = 20.

FLDCAT-KEY = 'X'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'ERDAT'.

FLDCAT-SELTEXT_L = 'Record Date created'.

FLDCAT-COL_POS = 1.

FLDCAT-KEY = 'X'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'ERNAM'.

FLDCAT-SELTEXT_L = 'Cteated Object Person Name'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'AUDAT'.

FLDCAT-SELTEXT_M = 'Document Date'.

FLDCAT-COL_POS = 3.

FLDCAT-EMPHASIZE = 'C110'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'VBTYP'.

FLDCAT-SELTEXT_L = 'SD Document category'.

FLDCAT-COL_POS = 4.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'NETWR'.

FLDCAT-SELTEXT_L = 'Net Value of the SO in Document Currency'.

FLDCAT-COL_POS = 5.

FLDCAT-OUTPUTLEN = 60.

FLDCAT-DO_SUM = 'X'.

FLDCAT-DATATYPE = 'CURR'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'VKORG'.

FLDCAT-SELTEXT_L = 'Sales Organization'.

FLDCAT-COL_POS = 6.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'VKGRP'.

FLDCAT-SELTEXT_M = 'Sales Group'.

FLDCAT-COL_POS = 7.

FLDCAT-EMPHASIZE = 'C801'.

APPEND FLDCAT TO FLDCAT.

CLEAR FLDCAT.

ENDFORM.

  • Build Layout for ALV Grid Report

FORM BLD_LAYOUT.

GD_LAYOUT-NO_INPUT = 'X'.

GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.

GD_LAYOUT-WINDOW_TITLEBAR = 'GRID DISPLAY'.

GD_LAYOUT-CONFIRMATION_PROMPT = 'X'. “ This asks the confirmation before leaving the screen.

ENDFORM.

  • Display report using ALV grid

FORM DISPLAY_ALV_REPORT.

GD_REPID = SY-REPID.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = GD_REPID

IS_LAYOUT = GD_LAYOUT

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

I_GRID_TITLE = 'SALES DOCUMENT HEADER'

IT_FIELDCAT = FLDCAT[]

I_SAVE = 'X'

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.

  • Retrieve data from VBAK table and populate itab IT_VBAK

FORM DATA_RETRIEVAL.

DATA LD_COLOR(1) TYPE C.

SELECT VBELN ERDAT ERNAM AUDAT VBTYP NETWR VKORG

UP TO 20 ROWS

FROM VBAK

INTO TABLE IT_VBAK.

LOOP AT IT_VBAK INTO WA_VBAK.

LD_COLOR = LD_COLOR + 1.

IF LD_COLOR = 8.

LD_COLOR = 1.

ENDIF.

CONCATENATE 'C' LD_COLOR '10' INTO WA_VBAK-LINE_COLOR.

MODIFY IT_VBAK FROM WA_VBAK.

ENDLOOP.

ENDFORM.

FORM TOP_OF_PAGE.

DATA: T_HEADER TYPE SLIS_T_LISTHEADER,

W_HEADER TYPE SLIS_LISTHEADER.

W_HEADER-TYP = 'H'.

W_HEADER-INFO = 'WELCOME HEADER LIST'.

APPEND W_HEADER TO T_HEADER.

W_HEADER-TYP = 'S'.

W_HEADER-KEY = 'REPORT:'.

W_HEADER-INFO = SY-REPID.

APPEND W_HEADER TO T_HEADER.

W_HEADER-TYP = 'S'.

W_HEADER-KEY = 'DATE:'.

CONCATENATE SY-DATUM6(2) ' / ' SY-DATUM4(2) ' / ' SY-DATUM(4) INTO W_HEADER-INFO.

APPEND W_HEADER TO T_HEADER.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = T_HEADER

ENDFORM.

Reward points,if it is useful.

Thanks,

chandu.

0 Kudos
67

hi,

the code given by u highlights the row in the time of initial display it self..... but my requirement is that....

In ALV GRID display output when the user selects a row from the GRID that row color shd change to RED and some msg shd also get displayed in the bottom ....

then if he selects second row then

the 1st row which he selected and the 2nd row both shd be highlighted in RED .......

0 Kudos
67

this is possible thru OOPS

Former Member
0 Kudos
67

Hai Ajantha Ratnakumar,

Go Through This program.

Demo program to color the contents of a field based on a condition using 'REUSE_ALV_LIST_DISPLAY'

By Haritha

REPORT ZALV_LIST4.

TABLES:

SPFLI.

TYPE-POOLS:

SLIS.

DATA:

T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

FS_FIELDCAT LIKE LINE OF T_FIELDCAT,

FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,

W_COLOR(3) ,

W_ROW TYPE I,

W_FIELDNAME(20),

W_PROG TYPE SY-REPID.

DATA:

BEGIN OF T_SPFLI OCCURS 0,

COLOR(3),

CHECKBOX ,

CELL TYPE SLIS_T_SPECIALCOL_ALV,

CARRID TYPE SPFLI-CARRID,

CONNID TYPE SPFLI-CONNID,

CITYFROM TYPE SPFLI-CITYFROM,

CITYTO TYPE SPFLI-CITYTO,

DISTANCE TYPE SPFLI-DISTANCE,

END OF T_SPFLI.

DATA:

FS_CELL LIKE LINE OF T_SPFLI-CELL.

SELECT *

FROM SPFLI

INTO CORRESPONDING FIELDS OF TABLE T_SPFLI.

FS_FIELDCAT-FIELDNAME = 'CARRID'.

FS_FIELDCAT-REF_TABNAME = 'SPFLI'.

FS_FIELDCAT-COL_POS = 1.

FS_FIELDCAT-KEY = 'X'.

FS_FIELDCAT-HOTSPOT = 'X'.

APPEND FS_FIELDCAT TO T_FIELDCAT.

CLEAR FS_FIELDCAT .

FS_FIELDCAT-FIELDNAME = 'CONNID'.

FS_FIELDCAT-REF_TABNAME = 'SPFLI'.

FS_FIELDCAT-COL_POS = 2.

FS_FIELDCAT-KEY = 'X'.

FS_FIELDCAT-HOTSPOT = 'X'.

APPEND FS_FIELDCAT TO T_FIELDCAT.

CLEAR FS_FIELDCAT .

FS_FIELDCAT-FIELDNAME = 'DISTANCE'.

FS_FIELDCAT-REF_TABNAME = 'SPFLI'.

*FS_FIELDCAT-INPUT = 'X'.

FS_FIELDCAT-COL_POS = 3.

FS_FIELDCAT-KEY = ' '.

FS_FIELDCAT-EDIT = 'X'.

APPEND FS_FIELDCAT TO T_FIELDCAT.

CLEAR FS_FIELDCAT.

FS_FIELDCAT-FIELDNAME = 'CITYFROM'.

FS_FIELDCAT-REF_TABNAME = 'SPFLI'.

FS_FIELDCAT-COL_POS = 4.

FS_FIELDCAT-KEY = ' '.

APPEND FS_FIELDCAT TO T_FIELDCAT.

LOOP AT T_SPFLI WHERE DISTANCE GT 600.

W_FIELDNAME = 'DISTANCE'.

FS_CELL-FIELDNAME = W_FIELDNAME .

FS_CELL-COLOR-COL = 5.

FS_CELL-NOKEYCOL = 'X'.

APPEND FS_CELL TO T_SPFLI-CELL.

MODIFY T_SPFLI TRANSPORTING CELL.

ENDLOOP.

FS_LAYOUT-INFO_FIELDNAME = 'COLOR'.

FS_LAYOUT-BOX_FIELDNAME = 'CHECKBOX'.

FS_LAYOUT-COLTAB_FIELDNAME = 'CELL'.

FS_LAYOUT-F2CODE = '&ETA'.

W_PROG = SY-REPID.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = W_PROG

IS_LAYOUT = FS_LAYOUT

IT_FIELDCAT = T_FIELDCAT

TABLES

T_OUTTAB = T_SPFLI

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.

In the above program, the contents of the field ‘DISTANCE’ are colored depending on a condition (i.e., values greater than 600). The list will appear as follows.

If Found helpfull Do Reward.

Regards.

Eshwar.