10-18-2005 6:52 AM
Hi How can i add colors in alv.
Can you pls give a good example for this.
thank you,
Deepak
10-18-2005 7:04 AM
Hi
The below links will give you enough information for adding colors in ALV.
http://help.sap.com/saphelp_erp2004/helpdata/en/fa/efb529f8a611d2b48d006094192fe3/frameset.htm
http://help.sap.com/saphelp_erp2004/helpdata/en/fa/efb529f8a611d2b48d006094192fe3/frameset.htm
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
Cheers...
Afsal
10-18-2005 6:53 AM
HI,
i am sending you a complete woking code ..you just run it and see the option in the output screen..select any of the check box and hit F8..and there it is.. you can modify the code to meet yur need
Reward point if it satisfy your needs..
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.
10-18-2005 7:04 AM
Hi
The below links will give you enough information for adding colors in ALV.
http://help.sap.com/saphelp_erp2004/helpdata/en/fa/efb529f8a611d2b48d006094192fe3/frameset.htm
http://help.sap.com/saphelp_erp2004/helpdata/en/fa/efb529f8a611d2b48d006094192fe3/frameset.htm
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
Cheers...
Afsal
10-18-2005 7:13 AM
10-18-2005 8:39 AM
Hi deepak,
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,
venu,
10-18-2005 8:45 AM
Hi,
You need the following type of code in your program:
FORM LAYOUT_BUILD USING FP_I_COPY_LTAP TYPE TY_I_LTAP
CHANGING FP_I_REPDTL TYPE TY_I_REPDTL
FP_LAYOUT2 TYPE LVC_S_LAYO.
DATA : LV_COLNO TYPE I,
L_WA_REPDTL TYPE TY_REPDTL,
L_WA_LTAP TYPE TY_LTAP.
*Internal table for coloring cells
DATA: L_I_COL_LAYOUT TYPE STANDARD TABLE OF SLIS_SPECIALCOL_ALV
INITIAL SIZE 0.
FP_LAYOUT2-CWIDTH_OPT = C_X.
FP_LAYOUT2-CTAB_FNAME = C_FLD_COLOR."'COLOR'.
LOOP AT I_REPDTL INTO L_WA_REPDTL.
READ TABLE FP_I_COPY_LTAP INTO L_WA_LTAP
WITH KEY NLENR = L_WA_REPDTL-LENUM BINARY SEARCH.
*
IF SY-SUBRC = 0.
CASE L_WA_LTAP-BESTQ.
CASE L_WA_REPDTL-BESTQ.
WHEN ' '.
L_WA_REPDTL-TEXT = TEXT-004. "'Available'.
LV_COLNO = 5. "color green
PERFORM SUB_SET_COLOR USING L_I_COL_LAYOUT
C_FLD_TEXT "TEXT-Blocking Reason
LV_COLNO.
WHEN 'Q'.
L_WA_REPDTL-TEXT = TEXT-005. "'Quality'.
LV_COLNO = 3. "color
PERFORM SUB_SET_COLOR USING L_I_COL_LAYOUT
C_FLD_TEXT "TEXT-Blocking Reason
LV_COLNO.
WHEN 'R'.
L_WA_REPDTL-TEXT = TEXT-006. "'Returns'.
LV_COLNO = 4. "color
PERFORM SUB_SET_COLOR USING L_I_COL_LAYOUT
C_FLD_TEXT "TEXT-Blocking Reason
LV_COLNO.
WHEN 'S'.
L_WA_REPDTL-TEXT = TEXT-007. "'Blocked'.
LV_COLNO = 6. "color RED
PERFORM SUB_SET_COLOR USING L_I_COL_LAYOUT
C_FLD_TEXT "TEXT-Blocking Reason
LV_COLNO.
ENDCASE.
ENDIF.
L_WA_REPDTL-COLOR = L_I_COL_LAYOUT.
MODIFY FP_I_REPDTL FROM L_WA_REPDTL TRANSPORTING COLOR.
CLEAR L_I_COL_LAYOUT.
ENDLOOP.
ENDFORM. " layout_build
FORM SUB_SET_COLOR USING LS_COLOR TYPE SLIS_T_SPECIALCOL_ALV
P_FIELDNAME1 TYPE SLIS_FIELDNAME
P_COLNO TYPE I.
DATA: I_LFL_COLOR TYPE SLIS_SPECIALCOL_ALV.
CLEAR I_LFL_COLOR.
I_LFL_COLOR-FIELDNAME = P_FIELDNAME1.
I_LFL_COLOR-COLOR-COL = P_COLNO.
I_LFL_COLOR-NOKEYCOL = C_X ."'X'
APPEND I_LFL_COLOR TO LS_COLOR.
ENDFORM. " SUB_SET_COLOR
10-18-2005 9:14 AM
Hi,
Check this link for Line colouring.
http://www.geocities.com/mpioud/Z_ALV_LINE_COLOR.html
Check this link for Cell colouring.
http://www.geocities.com/mpioud/Z_ALV_CELL_COLOR.html
Kindly reward points by clicking the star on the left of reply,if it helps you.
10-18-2005 10:06 AM
That was indeed a gr8 help from all of you guys
Thank you