10-08-2007 12:59 PM
10-08-2007 1:02 PM
Hi,
check these sample programmes....
for line color
http://www.geocities.com/mpioud/Z_ALV_LINE_COLOR.html
for cell color
http://www.geocities.com/mpioud/Z_ALV_CELL_COLOR.html
Regards,
Priyanka.
10-08-2007 1:02 PM
hi,
what do u mean by add colors?
U want to color perticular cell or column?
10-08-2007 1:04 PM
10-08-2007 1:06 PM
so write like this.
&----
*& Report ZALV_DS
*&
&----
*&
*&
&----
REPORT zalv_ds LINE-SIZE 35.
TYPE-POOLS:slis.
TABLES:mara,
makt,
marc.
DATA:BEGIN OF itab OCCURS 0,
matnr LIKE mara-matnr,
maktx LIKE makt-maktx,
werks LIKE marc-werks,
mtart LIKE mara-mtart,
matkl LIKE mara-matkl,
meins LIKE mara-meins,
ntgew LIKE mara-ntgew,
rowcolor(4) TYPE c,
cellcolors TYPE lvc_t_scol,
END OF itab.
DATA:t_fcat TYPE slis_t_fieldcat_alv,
t_eve TYPE slis_t_event.
DATA : st_layout TYPE slis_layout_alv.
SELECTION-SCREEN:BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:mat FOR mara-matnr. " no intervals no-extension.
*PARAMETERS:mat LIKE mara-matnr.
SELECTION-SCREEN:END OF BLOCK blk1.
INITIALIZATION.
PERFORM build_cata USING t_fcat.
PERFORM build_event.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM display_data.
&----
*& Form build_cata
&----
text
----
-->TEMP_FCAT text
----
FORM build_cata USING temp_fcat TYPE slis_t_fieldcat_alv.
sy-tvar0 = sy-uname.
WRITE sy-datum TO sy-tvar1.
DATA:wa_fcat TYPE slis_fieldcat_alv.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_m = 'Material'.
wa_fcat-key = 'X'. "To color e column
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MAKTX'.
wa_fcat-seltext_m = 'Description'.
wa_fcat-fix_column = 'x'.
wa_fcat-key = ''.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'WERKS'.
wa_fcat-seltext_m = 'Plant'.
wa_fcat-fix_column = 'x'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MTART'.
wa_fcat-seltext_m = 'Type'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MATKL'.
wa_fcat-seltext_m = 'Group'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'MEINS'.
wa_fcat-seltext_m = 'Measurement Unit'.
APPEND wa_fcat TO temp_fcat.
wa_fcat-tabname = 'ITAB'.
wa_fcat-fieldname = 'NTGEW'.
wa_fcat-seltext_m = 'Net Value'.
APPEND wa_fcat TO temp_fcat.
ENDFORM. "build_cata
&----
*& Form build_event
&----
text
----
FORM build_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = t_eve
EXCEPTIONS
list_type_wrong = 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. "build_event
&----
*& Form data_retrieval
&----
text
----
FORM data_retrieval.
SELECT maramatnr maramtart maramatkl marameins mara~ntgew
maktmaktx marcwerks
INTO CORRESPONDING FIELDS OF TABLE itab
FROM mara INNER JOIN makt ON
maramatnr = maktmatnr
INNER JOIN marc ON
maramatnr = marcmatnr
WHERE mara~matnr IN mat.
SORT itab BY matnr.
DELETE ADJACENT DUPLICATES FROM itab.
ENDFORM. "data_retrieval
&----
*& Form display_data
&----
text
----
FORM display_data.
**************************************************************************************************
*******************************For setting Cell Color*******************************************
**************************************************************************************************
DATA ls_cellcolor TYPE lvc_s_scol .
st_layout-coltab_fieldname = 'CELLCOLORS'.
READ TABLE itab INDEX 5 .
ls_cellcolor-fname = 'MATNR' .
ls_cellcolor-color-col = '1' .
ls_cellcolor-color-int = '1' .
APPEND ls_cellcolor TO itab-cellcolors .
MODIFY itab INDEX 5 .
st_layout-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = 'ZALV_DS'
is_layout = st_layout
i_save = 'A'
it_fieldcat = t_fcat
it_events = t_eve
TABLES
t_outtab = itab
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.
***************************************************************************************************
***************************************************************************************************
***************************************************************************************************
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = 'ZALV_DS'
it_fieldcat = t_fcat
it_events = t_eve
TABLES
t_outtab = itab
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.
*
LOOP AT itab.
WRITE:/ itab-matnr,itab-maktx,itab-werks.
ENDLOOP.
ENDFORM. "display_data
reward if useful.
10-08-2007 1:06 PM
Hi,
See the standard program SHOWCOLO. It will help you.
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, lets 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.
Check this
http://www.sapfans.com/forums/viewtopic.php?t=52107
Thanks,
Reward If Helpful.
10-08-2007 1:03 PM
10-08-2007 1:04 PM
Please follow the instructions mentioned below:
step1: your ALV internal table should have a
field (say,COLORCELL)of type LVC_T_SCOL.
eg. COLORCELL TYPE LVC_T_SCOL.
step2: in the layout structure, set the coltab.
for eg: is_layout-coltab_fieldname = 'COLORCELL'.
step3: hide the column field 'COLORCELL' in fieldcatalog. for eg,
loop at it_fieldcatalog into wa_fieldcatalog.
if wa_fieldcatalog-fieldname = 'COLORCELL'.
wa_fieldcatalog-no_out = 'X'.
modify it_fieldcatalog from wa_fieldcatalog. <b>
endif.
endloop.
step4: loop through the ALV internal table and check the
condition where you need to color the cell.
step5: write the following code:
perform set_column_color tables ls_alv_display-colorcell
using 'DOCUMENT' " field name
'6' "column number is red
'0' "inverse
'0'. "intensity
form set_column_color tables et_color type lvc_t_scol
using p_fname type lvc_fname
p_col type lvc_col
p_inv type lvc_inv
p_int type lvc_int.
data:
ls_color type lvc_s_scol.
ls_color-fname = p_fname.
ls_color-color-col = p_col.
ls_color-color-inv = p_inv.
ls_color-color-int = p_int.
append ls_color to et_color.
endform. " set_column_color
http://www.sapfans.com/forums/viewtopic.php?t=52107
Please give me reward point If it is useful
Thanks
Murali Poli
10-08-2007 1:05 PM
Hi
<b>Coloring Individual Cells</b>
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.
Again key field coloring will override your settings. Thats 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.
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 .
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 .
Plz go thru these links for sample pgm
http://www.sap-img.com/abap/line-color-in-alv-example.htm
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
REPORT ZOBJK1 .
*****************************************************************
Use of colours in ALV grid (cell, line and column) *
*****************************************************************
Table
tables : mara.
Type
types : begin of ty_mara,
matnr like mara-matnr,
matkl like mara-matkl,
counter(4) type n,
free_text(15) type c,
color_line(4) type c, " Line color
color_cell type lvc_t_scol, " Cell color
end of ty_mara.
Structures
data : wa_mara type ty_mara,
wa_fieldcat type lvc_s_fcat,
is_layout type lvc_s_layo,
wa_color type lvc_s_scol.
Internal table
data : it_mara type standard table of ty_mara,
it_fieldcat type standard table of lvc_s_fcat,
it_color type table of lvc_s_scol.
Variables
data : okcode like sy-ucomm,
w_alv_grid type ref to cl_gui_alv_grid,
w_docking_container type ref to cl_gui_docking_container.
parameters : p_column as checkbox,
p_line as checkbox,
p_cell as checkbox.
at selection-screen output.
perform get_data.
perform fill_catalog.
if w_docking_container is initial.
perform create_objects.
endif.
&----
*& Form create_objects
&----
form create_objects.
create object w_docking_container
exporting
ratio = 40
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
create object w_alv_grid
exporting
i_parent = w_docking_container.
Field that identify color line in internal table
move 'COLOR_LINE' to is_layout-info_fname.
Field that identify cell color in inetrnal table
move 'COLOR_CELL' to is_layout-ctab_fname.
call method w_alv_grid->set_table_for_first_display
exporting
is_layout = is_layout
changing
it_outtab = it_mara
it_fieldcatalog = it_fieldcat
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4.
endform.
&----
*& Form get_data
&----
form get_data.
select * from mara up to 5 rows.
clear : wa_mara-color_line, wa_mara-color_cell.
move-corresponding mara to wa_mara.
add 1 to wa_mara-counter.
move 'Blabla' to wa_mara-free_text.
if wa_mara-counter = '0002'
and p_line = 'X'.
Color line
move 'C410' to wa_mara-color_line.
elseif wa_mara-counter = '0004'
and p_cell = 'X'.
Color cell
move 'FREE_TEXT' to wa_color-fname.
move '6' to wa_color-color-col.
move '1' to wa_color-color-int.
move '1' to wa_color-color-inv.
append wa_color to it_color.
wa_mara-color_cell[] = it_color[].
endif.
append wa_mara to it_mara.
endselect.
endform.
&----
*& Form fill_catalog
&----
form fill_catalog.
*****************************************************************
Colour code : *
Colour is a 4-char field where : *
- 1st char = C (color property) *
- 2nd char = color code (from 0 to 7) *
0 = background color *
1 = blue *
2 = gray *
3 = yellow *
4 = blue/gray *
5 = green *
6 = red *
7 = orange *
- 3rd char = intensified (0=off, 1=on) *
- 4th char = inverse display (0=off, 1=on) *
*
Colour overwriting priority : *
1. Line *
2. Cell *
3. Column *
*****************************************************************
data : w_position type i value '1'.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'MATNR' to wa_fieldcat-fieldname.
move 'MARA' to wa_fieldcat-ref_table.
move 'MATNR' to wa_fieldcat-ref_field.
append wa_fieldcat to it_fieldcat.
add 1 to w_position.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'MATKL' to wa_fieldcat-fieldname.
move 'MARA' to wa_fieldcat-ref_table.
move 'MATKL' to wa_fieldcat-ref_field.
Color column
if p_column = 'X'.
move 'C610' to wa_fieldcat-emphasize.
endif.
append wa_fieldcat to it_fieldcat.
add 1 to w_position.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'COUNTER' to wa_fieldcat-fieldname.
move 'N' to wa_fieldcat-inttype.
move '4' to wa_fieldcat-intlen.
move 'Counter' to wa_fieldcat-coltext.
append wa_fieldcat to it_fieldcat.
add 1 to w_position.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'FREE_TEXT' to wa_fieldcat-fieldname.
move 'C' to wa_fieldcat-inttype.
move '20' to wa_fieldcat-intlen.
move 'Text' to wa_fieldcat-coltext.
append wa_fieldcat to it_fieldcat.
endform
<b>Reward if usefull</b>
10-08-2007 1:05 PM
Hi,
Please check the link below :
http://www.sapdev.co.uk/reporting/alv/alvgrid_color.htm
Thanks,
Sriram Ponna.
10-08-2007 1:05 PM
Hi,
Check the program in the following link:
http://sap-img.com/abap/line-color-in-alv-example.htm
Regards,
Bhaskar