Application Development and Automation 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: 
Read only

Color cell

Former Member
0 Likes
911

How can I set the cell color in ALV?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
841

Hi Preeti,

The structure that should be included must be of type “LVC_T_SCOL”. If you want to color the entire row, this inner table should contain only one row with field “fname” is set to space, some color value at field “col”, “0” or “1” at fields “int” (intensified) and “inv” (inverse). If you want to <b>color individual cells</b>, then for each cell column, append a line to this inner table which also contains the column name at field “fname”. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table. . Again key field coloring will override your settings. That’s why, we have another field in this inner table called “nokeycol”. For each field represented in the inner table, set this field to ‘X’ to prevent overriding of key color settings. In this procedure, again we must tell the control the name of the inner table containing color data. The field “CTAB_FNAME” of the layout structure is used for this purpose.

Code Part 14 – Adding inner table that will contain cell color data *--- Internal table holding list data

DATA BEGIN OF gt_list OCCURS 0 .

INCLUDE STRUCTURE SFLIGHT .

DATA rowcolor(4) TYPE c .

DATA cellcolors TYPE lvc_t_scol .

DATA END OF gt_list .

Code Part 15 – A sample code to make the cell at row 5 and column ‘SEATSOCC’ colored

DATA ls_cellcolor TYPE lvc_s_scol .

.

.

.

READ TABLE gt_list INDEX 5 .

ls_cellcolor-fname = 'SEATSOCC' .

ls_cellcolor-color-col = '7' .

ls_cellcolor-color-int = '1' .

APPEND ls_cellcolor TO gt_list-cellcolors .

MODIFY gt_list INDEX 5 .

<b>Reward points, if helpful.</b>

Regards,

Atin

5 REPLIES 5
Read only

Former Member
0 Likes
841

Hi,

You cant set color to AlV cells but you can create only strip kind of output.

Reward if helpful,

Regards,

Umasankar.

Read only

Former Member
0 Likes
841

Objects or FM

Read only

Former Member
0 Likes
841
Read only

Former Member
0 Likes
842

Hi Preeti,

The structure that should be included must be of type “LVC_T_SCOL”. If you want to color the entire row, this inner table should contain only one row with field “fname” is set to space, some color value at field “col”, “0” or “1” at fields “int” (intensified) and “inv” (inverse). If you want to <b>color individual cells</b>, then for each cell column, append a line to this inner table which also contains the column name at field “fname”. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table. . Again key field coloring will override your settings. That’s why, we have another field in this inner table called “nokeycol”. For each field represented in the inner table, set this field to ‘X’ to prevent overriding of key color settings. In this procedure, again we must tell the control the name of the inner table containing color data. The field “CTAB_FNAME” of the layout structure is used for this purpose.

Code Part 14 – Adding inner table that will contain cell color data *--- Internal table holding list data

DATA BEGIN OF gt_list OCCURS 0 .

INCLUDE STRUCTURE SFLIGHT .

DATA rowcolor(4) TYPE c .

DATA cellcolors TYPE lvc_t_scol .

DATA END OF gt_list .

Code Part 15 – A sample code to make the cell at row 5 and column ‘SEATSOCC’ colored

DATA ls_cellcolor TYPE lvc_s_scol .

.

.

.

READ TABLE gt_list INDEX 5 .

ls_cellcolor-fname = 'SEATSOCC' .

ls_cellcolor-color-col = '7' .

ls_cellcolor-color-int = '1' .

APPEND ls_cellcolor TO gt_list-cellcolors .

MODIFY gt_list INDEX 5 .

<b>Reward points, if helpful.</b>

Regards,

Atin

Read only

Former Member
0 Likes
841

Hi

1. add one more field to ur final internal table say COLOR(4)

2. in layout wa_layout-style_fname = 'COLOR'. " if its grid

wa_layout-style_fieldname = 'COLOR'. "if its list

3. read table itab index 3.

itab-color = 'C410'.

modify itab index 3

4. see program SHOWCOLO for all color codes

1. Add a field of data type CHAR(3) to the internal output table.

2. Enter the color code in the appropriate field of the row to be colored in the internal

output table:

Code: 'Cxy'

C = Color (all codes begin with 'C')

x = color number ('1' - '9')

y = highlight ('0' = off, '1' = on)

3. Assign the internal output table color code field name to the IS_LAYOUT importing

structure IS_LAYOUT-INFO_FIELDNAME field and pass this structure in the ALV call

interface.

To enable row coloring, you should add an additional field to your list data table. It should be of character type and length at least 4. This field will contain the color code for the row. So, let’s modify declaration of our list data table “gt_list”.

you should fill the color code to this field. Its format will be the same as explained before at section C.6.3. But how will ALV Grid know that you have loaded the color data for the row to this field. So, you make it know this by passing the name of the field containing color codes to the field “INFO_FNAME” of the layout structure.

e.g.

ps_layout-info_fname = <field_name_containing_color_codes>. “e.g. ‘ROWCOLOR’

You can fill that field anytime during execution. But, of course, due to the flow logic of screens, it will be reflected to your list display as soon as an ALV refresh occurs.

You can color an entire row as described in the next section. However, this method is less time consuming.

Coloring Individual Cells

This is the last point about coloring procedures for the ALV Grid. The procedure is similar to coloring an entire row. However, since an individual cell can be addressed with two parameters we will need something more. What is meant by “more” is a table type structure to be included into the structure of the list data table. It seems strange, because including it will make our list data structure deep. But anyhow ALV Grid control handles this.

The structure that should be included must be of type “LVC_T_SCOL”. If you want to color the entire row, this inner table should contain only one row with field “fname” is set to space, some color value at field “col”, “0” or “1” at fields “int” (intensified) and “inv” (inverse).

If you want to color individual cells, then for each cell column, append a line to this inner table which also contains the column name at field “fname”. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table.

Reward points for useful Answers

Regards

Anji