Colors in ALV
Hi How can i add colors in alv.
Can you pls give a good example for this.
thank you,
Deepak
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.
Similar Messages
-
Change color in ALV top of page
Hi all,
Can anyone tell me how (if it is possible) to change color in ALV top-of-page?
Thank you in advance,
HagitHi,
It is not possible to change the color in ALV top of page.
Thanks,
Sriram Ponna. -
To change the subtotals row color in ALV(Grid / List ) .
I am trying to change the color of a row which gives the subtotal...in ALV report...
but it is not working....
I have used the following code but not getting where i m wrong
I have u sed the following code wih the help of our forum only...
<CODE>
TYPE-POOLS: SLIS.
*& Internal Table Delcaration
DATA : BEGIN OF IT_SCALE OCCURS 0,
DATUM LIKE ZSCALE-DATUM,
MCOD1 LIKE ZSCALE-MCOD1,
MATNR LIKE ZSCALE-MATNR,
MAKTG LIKE ZSCALE-MAKTG,
MEINS LIKE ZSCALE-MEINS,
RATE LIKE ZSCALE-RATE,
TOTAL LIKE ZSCALE-TOTAL,
LI_COLOR(4),
END OF IT_SCALE.
DATA : INDEX LIKE SY-TABIX.
*& ALV Data Declaration
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: WA_FIELDCAT LIKE LINE OF IT_FIELDCAT.
DATA : T_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA : IT_EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE.
DATA : G_SAVE(1) TYPE C VALUE 'A',
GX_SAVE(1) TYPE C VALUE 'A',
GX_VARIANT LIKE DISVARIANT,
G_VARIANT LIKE DISVARIANT,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
T_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
T_I_EVENT TYPE SLIS_ALV_EVENT.
DATA : L_LIST(105) TYPE C, "Store the Top-of-page headings
L_DATEFROM(10) TYPE C, "Store date in top-of-page
L_DATETO(10) TYPE C. "Store date in top-of-page
<code>
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM ALV_FIELDCAT.
PERFORM GET_EVENTS.
PERFORM SUB_COMMENT_BUILD USING T_LIST_TOP_OF_PAGE.
PERFORM ALV_DISPLAY.
FORM GET_DATA .
DATA : LINE_COLOR.
SELECT DATUM MCOD1 MATNR MAKTG MEINS RATE TOTAL
FROM ZSCALE INTO CORRESPONDING FIELDS OF TABLE IT_SCALE
WHERE DATUM IN S_DATE
AND LIFNR IN S_LIFNR
AND MATNR IN S_MATNR.
loop at IT_SCALE.
LINE_color = LINE_color + 2.
if LINE_color < 7.
LINE_color = 1.
endif.
concatenate 'C' lINE_color '00' into IT_SCALE-li_color.
modify it_SCALE TRANSPORTING LI_COLOR.
endloop.
FORM ALV_FIELDCAT.
DATA: COUNTER TYPE I.
COUNTER = COUNTER + 1.
WA_FIELDCAT-COL_POS = COUNTER.
WA_FIELDCAT-FIELDNAME = 'DATUM'.
WA_FIELDCAT-TABNAME = 'IT_SCALE'.
WA_FIELDCAT-SELTEXT_L = 'Date'.
WA_FIELDCAT-JUST = 'C'.
WA_FIELDCAT-NO_ZERO = 'X'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
.endform.
FORM ALV_DISPLAY .
GS_LAYOUT-ZEBRA = 'X'.
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GS_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.
gS_layout-no_input = 'X'.
gS_layout-totals_text = 'Totals'(201).
gS_layout-subtotals_text = 'Subtotal'.
IF IT_SCALE[] IS INITIAL.
MESSAGE I001(38) WITH 'No Data to Display'.
ELSE.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
I_SAVE = G_SAVE
IS_VARIANT = GX_VARIANT
TABLES
T_OUTTAB = IT_SCALE[].
ENDIF.
ENDFORM. " ALV_DISPLAY
ThanX in Adavance....Hi Prasad,
I provided some code snippets for you. Please go through.
Hope this proves to be helpful to you.
The steps for coloring a line i the grid is much the same as making a traffic light.
To color a line the structure of the table must include a Char 4 field for color properties
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for line color
types: line_color(4) type c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
Loop trough the table to set the color properties of each line. The color properties field is
Char 4 and the characters is set as follows:
Char 1 = C = This is a color property
Char 2 = 6 = Color code (1 - 7)
Char 3 = Intensified on/of = 1 = on
Char 4 = Inverse display = 0 = of
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-line_color = 'C610'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Name of the color field
gs_layout-info_fname = 'LINE_COLOR'.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
Heres another Example for you:
& Report Z_ALV_COLOURS &
& This report shows how to use colours in REUSE_ALV_GRID_DISPLAY &
& C = Colour (all codes must start with 'C') &
& X = Colour number (1-9) &
& Y = Intensified (0 = off, 1 = on) &
& Z = Inverse (0 = off, 1 = on) &
report z_alv_colours.
data count_1(1) type c.
ALV definitions
type-pools: slis.
data i_fieldcat type slis_t_fieldcat_alv with header line.
data i_layout type slis_layout_alv.
types: begin of t_alv,
f1(4) type c,
f2(15) type c,
f3(4) type c,
f4(4) type c,
f5(4) type c,
f6(4) type c,
colour(4) type c,
coltab type slis_t_specialcol_alv,
end of t_alv.
data: i_alv type standard table of t_alv with header line.
data l_alvcolor type slis_specialcol_alv.
& create table entries for LINE colours &
do 9 times.
count_1 = sy-index.
clear i_alv.
concatenate 'C' count_1 '0' '0' into i_alv-f1.
concatenate 'C' count_1 '0' '0' into i_alv-colour.
i_alv-f2 = 'Line colour'.
i_alv-f3 = 'X'.
append i_alv.
Intensified
clear i_alv.
concatenate 'C' count_1 '1' '0' into i_alv-f1.
concatenate 'C' count_1 '1' '0' into i_alv-colour.
i_alv-f2 = 'Line colour'.
i_alv-f4 = 'X'.
append i_alv.
Inverse
clear i_alv.
concatenate 'C' count_1 '0' '1' into i_alv-f1.
concatenate 'C' count_1 '0' '1' into i_alv-colour.
i_alv-f2 = 'Line colour'.
i_alv-f5 = 'X'.
append i_alv.
Intensified & Inverse
clear i_alv.
concatenate 'C' count_1 '1' '1' into i_alv-f1.
concatenate 'C' count_1 '1' '1' into i_alv-colour.
i_alv-f2 = 'Line colour'.
i_alv-f6 = 'X'.
append i_alv.
enddo.
create table entries for CELL colours
do 9 times.
count_1 = sy-index.
concatenate 'C' count_1 '0' '0' into i_alv-f1.
i_alv-f2 = 'Cell colour'.
concatenate 'C' count_1 '0' '0' into i_alv-f3.
concatenate 'C' count_1 '1' '0' into i_alv-f4.
concatenate 'C' count_1 '0' '1' into i_alv-f5.
concatenate 'C' count_1 '1' '1' into i_alv-f6.
append i_alv.
enddo.
& Create table entries for CELL colours &
loop at i_alv where f2 = 'Cell colour'.
Colour cells
clear l_alvcolor.
l_alvcolor-fieldname = 'F3'.
l_alvcolor-color-col = i_alv-f3+1(1).
l_alvcolor-color-int = i_alv-f3+2(1).
l_alvcolor-color-inv = i_alv-f3+3(1).
l_alvcolor-nokeycol = 'X'.
append l_alvcolor to i_alv-coltab.
clear l_alvcolor.
l_alvcolor-fieldname = 'F4'.
l_alvcolor-color-col = i_alv-f4+1(1).
l_alvcolor-color-int = i_alv-f4+2(1).
l_alvcolor-color-inv = i_alv-f4+3(1).
l_alvcolor-nokeycol = 'X'.
append l_alvcolor to i_alv-coltab.
clear l_alvcolor.
l_alvcolor-fieldname = 'F5'.
l_alvcolor-color-col = i_alv-f5+1(1).
l_alvcolor-color-int = i_alv-f5+2(1).
l_alvcolor-color-inv = i_alv-f5+3(1).
l_alvcolor-nokeycol = 'X'.
append l_alvcolor to i_alv-coltab.
clear l_alvcolor.
l_alvcolor-fieldname = 'F6'.
l_alvcolor-color-col = i_alv-f6+1(1).
l_alvcolor-color-int = i_alv-f6+2(1).
l_alvcolor-color-inv = i_alv-f6+3(1).
l_alvcolor-nokeycol = 'X'.
append l_alvcolor to i_alv-coltab.
modify i_alv.
endloop.
& Configure ALV settings &
Create field catalog
perform create_field_catalog using 'F1' 'T_ALV' 'Colour name'.
perform create_field_catalog using 'F2' 'T_ALV' 'Description'.
perform create_field_catalog using 'F3' 'T_ALV' 'BaseColour'.
perform create_field_catalog using 'F4' 'T_ALV' 'Intensified'.
perform create_field_catalog using 'F5' 'T_ALV' 'Inverse'.
perform create_field_catalog using 'F6' 'T_ALV' 'Both Inv/Int'.
perform create_field_catalog using 'COLOUR' 'T_ALV' 'Colour'.
Layout
clear i_layout.
i_layout-colwidth_optimize = 'X'.
i_layout-info_fieldname = 'COLOUR'. " for line colour
i_layout-coltab_fieldname = 'COLTAB'. " for cell colour
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
is_layout = i_layout
it_fieldcat = i_fieldcat[]
i_default = 'X'
i_save = 'A'
tables
t_outtab = i_alv.
& Form CREATE_FIELD_CATALOG &
form create_field_catalog using p_fieldname
p_tabname
p_text.
i_fieldcat-fieldname = p_fieldname.
i_fieldcat-tabname = p_tabname.
i_fieldcat-seltext_l = p_text.
append i_fieldcat.
endform. " CREATE_FIELD_CATALOG
For more information about Coloring in ALV, Please refer :
Coloring Rows in ALV
Hope this helps you in solving your issue.
Please Reward Points if any of the above points are helpful to you.
Regards,
Kalyan Chakravarthy -
Hi All
I would be greatful if someone could please help...
I am still attempting to get cells painted within a WDA ALV grid display.
I have tried to use the method stated in the WDA sap press book - but this method is for use with TABLE element and I am using a ViewContainerUIElement for my table. There are mentions of wonderful ways to color cells in a list display - but I cannot understand how this can be achieved. I currently have this working appart from the numeric numbers of the design being set into the relavant column cell.
If anyone could help that would be great...
Please see: http://picasaweb.google.co.uk/dave.alexander69/Pictures#5244800978549492338
LOOP AT lt_zdata INTO ls_zdata.
lv_index = sy-tabix.
* set column values
* loop at row data and set colour attributes of individual cells
LOOP AT lt_columns ASSIGNING <fs_column>.
lr_col_header = <fs_column>-r_column->get_header( ).
lr_col_header->set_ddic_binding_field( ).
CREATE OBJECT lr_input_field EXPORTING value_fieldname = <fs_column>-id.
lr_column = lr_column_settings->get_column( <fs_column>-id ).
* for the date columns only...
IF <fs_column>-id(4) = 'CELL'.
* get and set column dates from select option user input
READ TABLE lt_dates INTO ls_dates INDEX 1.
IF lt_dates IS INITIAL.
lr_col_header->set_text( 'Date' ).
ELSE.
ls_dates-low = ls_dates-low + lv_incr_date.
MOVE ls_dates-low+2(2) TO lv_for_col_date+6(2). "Year
MOVE ls_dates-low+4(2) TO lv_for_col_date+3(2). "Month
MOVE ls_dates-low+6(2) TO lv_for_col_date(2). "Day
MOVE lv_for_col_date TO lv_col_date.
lr_col_header->set_text( lv_col_date ).
lv_incr_date = lv_incr_date + 7.
ENDIF.
LOOP AT lt_orgdata_dates INTO ls_orgdata_dates
WHERE crew = ls_zdata-crew
AND position = ls_zdata-position
AND name = ls_zdata-person
AND trip_arr >= ls_dates-low
AND trip_dep <= ls_dates-low.
* column heading settings
lr_field = lr_table->if_salv_wd_field_settings~get_field( <fs_column>-id ).
lr_field->if_salv_wd_sort~set_sort_allowed( abap_false ).
* trying to set cell variants ?@#??!!???
* lr_cv = lr_column->set_key( ls_zdata-variance ).
* lr_cv->set_editor( lr_input_field ).
* lr_cv->set_cell_design( value = '01').
* lr_column->add_cell_variant( lr_cv ).
* current method of seeting the cell colors... (but puts value in cell!)
FIELD-SYMBOLS: <fs> TYPE data.
lr_column->set_cell_design_fieldname( value = <fs_column>-id ).
ASSIGN COMPONENT <fs_column>-id OF STRUCTURE ls_zdata TO <fs>.
WRITE: CL_WD_TABLE_COLUMN=>e_cell_design-one TO <fs>.
MODIFY lt_zdata FROM ls_zdata. " INDEX lv_index.
ENDLOOP.
ENDIF.
Kind Regards
Dave AlexanderHi check this code to set cell colors for ALV grid.
Take a context attribute with type WDUI_TABLE_CELL_DESIGN.
Here i am populating colors based on some condition.Check the loop of the internal table.
method get_flight_details .
data:node_flights type ref to if_wd_context_node,
it_flights type sflight_tab1,
ls_flights type sflight,
it_final type if_componentcontroller=>elements_flights,
ls_final type if_componentcontroller=>element_flights.
select * from sflight into table it_flights
up to 100 rows.
node_flights = wd_context->get_child_node( 'FLIGHTS' ).
loop at it_flights into ls_flights.
move-corresponding ls_flights to ls_final.
if ls_final-price = '185.00'.
ls_final-readonly = abap_true.
ls_final-celldesign =
cl_wd_table_column=>e_cell_design-badvalue_light.
else.
ls_final-readonly = ' '.
ls_final-celldesign =
cl_wd_table_column=>e_cell_design-goodvalue_light.
endif.
append ls_final to it_final.
endloop.
node_flights->bind_table(
new_items = it_final
set_initial_elements = abap_true
* INDEX = INDEX
data: l_ref_cmp_usage type ref to if_wd_component_usage.
l_ref_cmp_usage = wd_this->wd_cpuse_alv( ).
if l_ref_cmp_usage->has_active_component( ) is initial.
l_ref_cmp_usage->create_component( ).
endif.
data: l_ref_interfacecontroller type ref to iwci_salv_wd_table .
l_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).
data:
l_value type ref to cl_salv_wd_config_table.
l_value = l_ref_interfacecontroller->get_model(
* Make Price column editable
data:l_column type ref to cl_salv_wd_column,
l_column1 type ref to cl_salv_wd_column,
lr_input type ref to cl_salv_wd_uie_input_field,
l_input1 type ref to cl_salv_wd_uie_input_field.
l_column = l_value->if_salv_wd_column_settings~get_column( 'PRICE' ).
create object lr_input
exporting
value_fieldname = 'PRICE'
l_column->set_cell_editor( value = lr_input ).
* to make some cells non editable
lr_input->set_read_only_fieldname( value = 'READONLY' ).
l_value->if_salv_wd_column_settings~delete_column( id = 'READONLY' )
*Set the table Editable
l_value->if_salv_wd_table_settings~set_read_only( value = abap_false ).
*Give colors to cells
l_column1 = l_value->if_salv_wd_column_settings~get_column( 'CARRID' ).
l_column1->set_cell_design_fieldname( value = 'CELLDESIGN' ).
l_value->if_salv_wd_column_settings~delete_column( id = 'CELLDESIGN' )
endmethod.
Thanks
Suman -
Hi all,
I am trying to display some selected rows in my report in a different color.
But its not working.
I have .....
i_gs_layout-info_fieldname = 'COLOR_LINE'.
my internal table to be displayed is...
DATA: BEGIN OF T_DISPLAY OCCURS 0,
MATNR TYPE MARA-MATNR,
LOSMENGE TYPE QALS-LOSMENGE,
SLMENGE TYPE MSEG-MENGE,
SL_PPM TYPE P DECIMALS 2,
COLOR_LINE(4) TYPE C,
END OF T_DISPLAY.
On some conditions I am filling the field COLOR_LINE with 'C610'.
The following function module is used for display.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = i_g_repid
i_callback_user_command = ''
i_callback_pf_status_set = ''
i_grid_title = l_title
is_layout = i_gs_layout
it_events = i_gt_events[]
it_fieldcat = i_gt_fieldcat[]
it_sort = i_gt_sort[]
i_save = 'A'
TABLES
t_outtab = T_DISPLAY.
Here everything is working fine except the color.
Eventhough I have the value C610 in my internal table in most of the rows, no row is getting displayed in this color.
Should I use some other function module or am I missing something in this code..?Hi,
Check this link..
http://www.sap-img.com/abap/line-color-in-alv-example.htm
Check this simple example..
Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
TYPE-POOLS: slis. " ALV Global types
TYPES:
BEGIN OF ty_vbak,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
line_color(4), " Line color
END OF ty_vbak.
DATA:
Data displayed
gt_vbak TYPE TABLE OF ty_vbak.
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_fill_color.
PERFORM f_display_data.
Form f_read_data
FORM f_read_data.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
FROM vbak UP TO 100 ROWS.
ENDFORM. " F_READ_DATA
Form f_fill_color
FORM f_fill_color.
DATA l_rnd_value TYPE integer2.
FIELD-SYMBOLS <vbak> TYPE ty_vbak.
LOOP AT gt_vbak ASSIGNING <vbak>.
Random value
CALL FUNCTION 'RANDOM_I2'
EXPORTING
rnd_min = 0
rnd_max = 3
IMPORTING
rnd_value = l_rnd_value.
CASE l_rnd_value.
WHEN 0.
<vbak>-line_color = 'C100'. " Blue.
WHEN 1.
<vbak>-line_color = 'C300'. " Yellow.
WHEN 2.
<vbak>-line_color = 'C500'. " Green.
WHEN 3.
<vbak>-line_color = 'C600'. " Red.
ENDCASE.
ENDLOOP.
ENDFORM. " F_FILL_COLOR
Form f_display_data
FORM f_display_data.
DATA:
ls_layout TYPE slis_layout_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
Build the field catalog
m_fieldcat 'VKORG' 'VBAK'.
m_fieldcat 'KUNNR' 'VBAK'.
m_fieldcat 'VBELN' 'VBAK'.
m_fieldcat 'NETWR' 'VBAK'.
Fill Layout - Name of the field with color
ls_layout-info_fieldname = 'LINE_COLOR'.
Display the list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_vbak.
ENDFORM. " F_DISPLAY_DATA
Thanks,
Naren -
Hi All,
How can I display multiple colors to different cells in an ALV ?.
Please help..
Thanks in advance,
sudeep v d..Hi Sudeep,
In the below mentioned link a topic Color of ALV output, columns, and cells has been mentioned in the section '4.17.3 Appearance of ALV Output'.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/db22242d-0701-0010-28a2-aeaa1fefd706
Best regards,
Suresh -
hi
how can i change row color on alv.Hi
thanks your answer Uday Gubbala
i was examinated this link [https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/abapWebDynproALV-ChangeCellColourbasedonContent]
but i don't do this row wd_this->m_alv_model = lo_value. error message : m_alv_model unknow.
and this sample change column color but i want to row
Thanks. -
How to switch off column coloring of alv grid printouts?
Hello World!
Is there any possibility (a customizing option or a parameter) to switch off cell/column coloring of alv grid printouts?
It is very useful to see colored columns in screens, but they are darkened in printouts. How to avoid it?
Thanks and regards,
VladimirHi,
You can have different layouts for a ALV report and each layout the look and feel can be different.
So, the manual activity is the user will have to switch to the B/W layout before printing. I am not sure if you have enabled the LAYOUT option for the user to change it by himself.
I hope I am able to get across my point.
If you are using OO ALV control, you can dynamically change the layout using set_frontend_layout method. The user can also change the layout --
choose Change layout or Settings ® Layout ® Change.
The Change Layout dialog box shows you which columns are currently displayed and which additional columns can be displayed.
Regards,
Ravi
Note - Please mark the helpful answers
Message was edited by: Ravikumar Allampallam -
Hi all,
I want to give color in a particular column of my ALV List report.
Can u help me.. and also the color will change regarding a condition of that field...
Pls reply asap....use below code
DATA: g_color_green TYPE slis_t_specialcol_alv.
create a table of fieldnames to be coloured intensified green -
PERFORM colour_cells TABLES g_color_green
USING 21 31 5.
|
|
set cells of this line to intensified green
IF CONDITION.....
out-color[] = g_color_green[].
ENDIF.
FORM E05_LAYOUT_BUILD *
ALV Layout options *
<-> E05_LS_LAYOUT *
FORM e05_layout_build USING e05_ls_layout TYPE slis_layout_alv.
Setting this flag avoids having to define field sizes.
e05_ls_layout-colwidth_optimize = 'X'.
FIELD COLOR contains table of FIELDNAME and COLOURS.
e05_ls_layout-coltab_fieldname = 'COLOR'.
ENDFORM.
*& Form colour_cells
Set up table to color field groups different from default colour
<--> t_color table of fields and colours
<-- p_index_from - first field of catalogue to be coloured
<-- p_index_to - last field of catalogue to be coloured
<-- p_color - color number
FORM colour_cells TABLES t_color
USING p_index_from TYPE sy-index
p_index_to TYPE sy-index
p_color TYPE i.
DATA: ls_fieldcat TYPE slis_fieldcat_alv,
w_tab TYPE slis_specialcol_alv.
use field catalogue to build new table for consecutive fields
LOOP AT gt_fieldcat INTO ls_fieldcat FROM p_index_from TO p_index_to.
w_tab-fieldname = ls_fieldcat-fieldname.
w_tab-color-col = p_color.
IF p_color = 5. "green
w_tab-color-int = 1. "intensified on
ELSE.
w_tab-color-int = 0. "intensified off
ENDIF.
APPEND w_tab TO t_color.
ENDLOOP.
ENDFORM. " colour_cells
rgds
rajesh -
Change color in alv list header
hi experts,
how can i change the color in a alv header... for example...
number docum year
001 13245 2006
002 13245 2007
the header.. number, docum and year appears in light blue (all the cell) , how can i do that it appears without a color like the regular rows.
thx in advanceHi Carlos,
FORM HEADING.
FORMAT INTENSIFIED OFF. " Remove any INTENSIFIED
ULINE AT (WIDTH). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED." Title color
WRITE: / SY-VLINE. " Left border
WRITE: 'No |Colour |intensified |intensified off|',
'inverse' NO-GAP.
WRITE: AT WIDTH SY-VLINE. " Right border
ULINE AT (WIDTH). " Line below titles
FORMAT COLOR OFF.
ENDFORM.
regards,
Prabhudas -
Color in ALV grid output based on condition
Hi,
I have generated a ALV Grid output.
I have a internal table ITAB1. It has 2 fields - field1 and field2.
Now, my requirement is if field1 is 'X', the row should be colored in RED, else if field1 is 'Y', the row should be colored in GREEN.
How can it be done?
Thanks,
Shivaa.........Hi,
add another field in the internal table with the type of char04.
use the code given below....
DATA : begin of itab occurs 0,
field1(10) type c,
field2(10) type c,
color(4) type c,
end of itab.
" fetch records in itab..
loop at itab.
if itab-field1 = 'X'.
itab-color = 'C700'. " Trial and error to get the color you want...
elseif itab-field1 = 'Y'.
itab-color = 'C300'. " Trial and error to get the color you want...
endif.
endloop.
fs_fcat-fieldname = 'FIELD1'.
fs_fcat-col_pos = 1.
fs_fcat-coltext = 'FIRST FIELD'.
APPEND fs_fcat TO t_fcat.
fs_fcat-fieldname = 'FIELD2'.
fs_fcat-col_pos = 2.
fs_fcat-coltext = 'SECOND FIELD'.
APPEND fs_fcat TO t_fcat.
fs_layo-sel_mode = 'A'.
fs_layo-INFO_FNAME = 'COLOR'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy_cprog
is_layout_lvc = fs_layo
it_fieldcat_lvc = t_fcat
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
This resolves you issue....
Cheers,
Siddarth -
How to download background color of ALV with button "Export to Excel"
Dear Experts:
I can download the data of ALV in webdynpro for ABAP, but the color is missing.
Does anybody know how to download background color of the ALV cells also by "Export to Excel" button?
Could anybody help on this?
Thanks in advance!
Best Regards
Lingxing Mengnever experienced that...
[chk this link|Download colored ALV output in to EXCEL sheet;
a couple of intersting posts, they talk abt general ALV...
try one of the last post ...when downloading
use local file->HTML only.. but while choosing the file location to save give extension as XLS. -
Hi Experts,
I am using "REUSE_ALV_GRID_DISPLAY" to display output. I am not using oops.
Is there any possibility to show last row in different color.
And also let me know how to different color for one column in ALV grid display.
example:
COL1 | COL2 | COL3 |
=================
XXXX | 10 | 44 | 05 |
YYYY | 01 | 20 | 35 |
ZZZZZ | 05 | 10 | 20 |
I need to show in different color which are bold in the above output.
Thanks
RaghuHello
In order to colour columns you just need to set the colour (e.g. 'C510') in the fieldcatalog (LVC_S_FCAT-EMPHASIZE => SLIS-based ALV should be similar).
You may also have a look at threads
[ALV] Text in color and bold
styles
where you can find my sample report ZUS_SDN_ALV_CELL_STYLE_2 demonstrating what kind of color/style effects are possible in ALV grids.
Regards
Uwe -
Hi ! I have made a ALV report. On the output screen, whenever the user clicks on the material name then, ME1P alike my custom report comes up with material purchase history report.
Now, in this report the requirement iis :-
1). The respective P.O. No. for the material name clicked upon should come in red colour. (Entire row)
2). All the same vendors in the report should come in yellow color.(Entire row)
Please help.HI,
You can able to acheive the colored for all the field which is diaplyed in the entire row.
Please follow the below procedure.
Where you have declared the entire row structure in the data declartion just add the tihis field too in the structure.
cell type slis_t_specialcol_alv,
below kind of procedure to be followed for the colored display
cell-fieldname = FiledName''.
cell-color-col = 7. (cell-color-col = 7 for pink color. you can red for 3 or 4. I am not sure eact one )
cell-nokeycol = 'X'.
append cell to w_final-cell. (w_fial should be work area for final internal table )
append w_final to itab_final.
clear: cell.
Like above you can fill all the fields with and finally append to final table.
in the layout structure you need to define below the way
lf_layout-info_fieldname = 'COLOR'.
lf_layout-coltab_fieldname = 'CELL'.
the below one for ALV parametrs to be enabled.
I_GRID_SETTINGS =
is_layout = lf_layout
Please check and come back to me if u have any issues -
Create dynamic internal table with deep structure;cell coloring dynamic ALV
Hi,
My requirement is to do cell colouring for a dynamic ALV.
So I am creating a dynamic internal table using the following method.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fieldcatalog[]
IMPORTING
ep_table = i_output.
But how do I define field COLORS which should be again an internal table ?
Is there any other way for cell colouring?
Putting my problem in another way:
How do I create a dynamic internal table with one field as another internal table.
Quick replies are highly appreciated.
Thanks,
Nisha Vengal.halo Nisha
Before building the display table . you can add the field in the feild catalog right . This display table gets generated from the field catalog right
1 Create a global structute say ZEXTEND_FIELDCAT
2 Have fields like STYLE type lvc_t_styl
COLOR type LVC_T_SCOL.
3 Now you have to extend ur fieldcatalog
l_fieldcat-fieldname = COLOR'.
l_fieldcat-ref_field = 'COLOR'.
l_fieldcat-ref_table = 'ZEXTEND_FIELDCAT'.
APPEND l_fieldcat TO lt_field_catalog.
CLEAR l_fieldcat.
Maybe you are looking for
-
Migration from Excel 2003 - VBA to 2010
Hi, I support an application that uses VBA macros in XLS 2003 spreadsheets. As support is being discontinued, I need to migrate to 2010. I am having trouble finding information on what functions/features are not compatible in the later version. Is
-
ESI IS CALCULATING ON GROSS SALARY AS WELL AS INCENTIVES,IS IT RIGHT?
Hi Friends, I have one problem regarding ESI Issue. ESI is calculating on gross salary as well as incentives,is it right or Not? In Our company they are calculating on gross only,but in sap it is including incentives. For example: Employee having g
-
Open File Dialog in same monitor as application
I have an application that will be running on computers with dual monitors. I am using the file dialog in my application and it always opens in the primary monitor. Is there a way to have it open in the same monitor as the application? Terry
-
Custom KM Reports: parameter's labels translation
Hi folks, we are facing a problem about custom KM reports development. Currently we have developed one new report according Thilo's how to guide and according the code of a standard one. The report seems works fine, but we are not able to translate i
-
I have read and tried the various solutions posted on the Apple support pages and am unable to solve this problem. I have deleted the named files on several occasions which, I am told, should enable me to download the program. This hasn't worked!