Color individual rows in an ALV Grid
Hello,
in an ALV grid I have to distinguish between certain values in the rows so I wanted to use different colors. I see how to change the color of the columns but cannot work out how to change individual row color. I don´t see any values for this in 'Fieldcat'.
Can anybody help?
Thank you,
Kevin
Here is a sample, program, implement it, it will show you what you need to do.
* 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 *
report zrich_0001
no standard page heading.
* 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"
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_check 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 = 60
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.
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.
data: this_color(10) type c.
data: index(3) type c.
select * from mara up to 5 rows.
clear wa_mara-color_line.
move-corresponding mara to wa_mara.
add 1 to wa_mara-counter.
move 'Blabla' to wa_mara-free_text.
* Color line, differnt color for each line
index = sy-tabix.
concatenate 'C' index '10' into this_color.
condense this_color no-gaps.
wa_mara-color_line = this_color.
append wa_mara to it_mara.
endselect.
endform.
*& Form fill_catalog
form fill_catalog.
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.
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.
Regards,
Rich HEilman
Updated the code a bit
Message was edited by: Rich Heilman
Similar Messages
-
Adding a color to row of a alv grid using function modules
Can anybody clearly explains me how to add a color to a row to an alv grid using function module reuse_alv_grid_display.
thanks in advance
regards
anil.hi,
chk this ample pgm
report zxyz_0004
no standard page heading.
type-pools slis.
data: fieldcat type slis_t_fieldcat_alv.
data: begin of imara occurs 0,
matnr type mara-matnr,
mtart type mara-mtart,
maktx type makt-maktx,
color_line(4) type c,
tcolor type slis_t_specialcol_alv, "cell
end of imara.
data: xcolor type slis_specialcol_alv.
start-of-selection.
perform get_data.
perform write_report.
Get_Data
form get_data.
imara-matnr = 'ABC'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for ABC'.
append imara.
imara-matnr = 'DEF'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for DEF'.
append imara.
imara-matnr = 'GHI'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for GHI'.
append imara.
loop at imara.
if sy-tabix = 1.
imara-color_line = 'C410'. " color line
endif.
if sy-tabix = 2. "color CELL
clear xcolor.
xcolor-fieldname = 'MTART'.
xcolor-color-col = '3'.
xcolor-color-int = '1'. "Intensified on/off
xcolor-color-inv = '0'.
append xcolor to imara-tcolor.
endif.
modify imara.
endloop.
endform.
WRITE_REPORT
form write_report.
data: layout type slis_layout_alv.
layout-coltab_fieldname = 'TCOLOR'.
layout-info_fieldname = 'COLOR_LINE'.
perform build_field_catalog.
CALL ABAP LIST VIEWER (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
is_layout = layout
it_fieldcat = fieldcat
tables
t_outtab = imara.
endform.
BUILD_FIELD_CATALOG
form build_field_catalog.
data: fc_tmp type slis_t_fieldcat_alv with header line.
clear: fieldcat. refresh: fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Number'.
fc_tmp-fieldname = 'MATNR'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '18'.
append fc_tmp to fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Type'.
fc_tmp-fieldname = 'MTART'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '4'.
append fc_tmp to fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material'.
fc_tmp-fieldname = 'MAKTX'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '40'.
fc_tmp-emphasize = 'C610'. " color column
append fc_tmp to fieldcat.
endform.
<b>anil , pls chk this link also.
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
very hlpful.</b>
rgds
anver
<b>pls mark points if ur issue solved</b>
Message was edited by: Anversha s
Message was edited by: Anversha s -
Urgent : how to select the rows in the ALV Grid Control
How to select the rows in the ALV Grid control,
I am facing the situation where i need to select the row/rows in the Grid control and then to lock the entries,
If anyone have the solution please help me out
<b>Its very Urgent</b>Hi Bharath,
Go through this hope u can understand.
SEL_MODE. Selection mode, determines how rows can be selected. Can have the following values:
A Multiple columns, multiple rows with selection buttons.
B Simple selection, listbox, Single row/column
C Multiple rows without buttons
D Multiple rows with buttons and select all ICON
Setting and getting selected rows (Columns) and read line contents
You can read which rows of the grid that has been selected, and dynamic select rows of the grid using methods get_selected_rows and set_selected_rows. There are similar methods for columns.
Note that the grid table always has the rows in the same sequence as displayed in the grid, thus you can use the index of the selected row(s) to read the information in the rows from the table. In the examples below the grid table is named gi_sflight.
Data declaration:
DATA:
Internal table for indexes of selected rows
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
Example 1: Reading index of selected row(s) and using it to read the grid table
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows.
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'You must choose a valid line'.
EXIT.
ENDIF.
LOOP AT gi_index_rows INTO g_selected_row.
READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
ENDIF.
ENDLOOP.
Example 2: Set selected row(s).
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines > 0.
CALL METHOD go_grid->set_selected_rows
exporting
it_index_rows = gi_index_rows.
ENDIF.
Reward points if helpful.
Thanks
Naveen khan -
Row Selection in ALV Grid created using CL_GUI_ALV_GRID
Hi,
I have ALV grid using cl_gui_alv_grid. I want to capture the row selection and display the selected rows in 2nd ALV grid (using cl_gui_alv_grid).
Method CALL METHOD Grid->get_selected_rows giving right no. of selected records first time and process these records by POST button and hence shows these records in next alv grid. but when i came back to 1st ALV by pressing BACK button on 2nd ALV then if I again select records on the same 1st ALV grid the same Method CALL METHOD Grid->get_selected_rows fires again. but this times it wouldn't give the selected records. I mean first time this gives me correct no. of selected records but 2nd time wouldn't.
how do I capture the row selection.?
Kindly suggest me. helpful answer will be appreciated.
Thanx in Advance.
RobinHi,
Write this code, you have to free the container.
MODULE user_command_0101 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
c_container->free( ).
c_container1->free( ). " this is the container of secondary list.
clear: r_grid, r_grid1, c_container, c_container1.
LEAVE TO SCREEN 100.
ENDCASE.
Regards and Best wishes. -
Color the sub-total row in an alv-grid
Hi all.
I work on SAP 4.7 WAS6.20 and output a table with the cl_gui_alv_grid. I´m able to color special rows (or columns) in the alv grid. But I want to color individually the sub-total lines (like the lines before) and don´t want the yellow color for all of the sub-total lines.
Do you know how to color the sub-total-lines?
Thanks a lot.
MichaelHi,
U can color an individula row see the link below
Color a line
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
see the link
http://www.sapgenie.com/abap/controls/alvgrid.htm -
Setting Font Color and Bold Property in ALV Grid
I have a requirement to set the font in particular ALV Cells in red color.
Also this font (text) has to be set to Bold.
I know how to set cell coloring in ALV Grid, but have no idea regarding how to set font color.
Could please give me an idea/code segment/suggestion.
Thank You!Please refer this post
Coloring of ROWS in ALV tree -
How can I get the selected rows from two ALV grids at the same time?
I have a program that uses two ALV grids in one dialog screen. I'm using the OO ALV model (SALV* classes).
The user can select any number of rows from each grid. Then, when a toolbar pushbutton is pressed, I'd have to retrieve the selected rows from both grids and start some processing with these rows.
It is no problem to assign event handlers to both grids, and use the CL_SALV_TABLE->GET_SELECTIONS and CL_SALV_SELECTIONS->GET_SELECTED_ROWS methods to find out which rows were marked by the user. Trouble is, this only works when I raise an event in each grid separately, for instance via an own function that I added to the grid's toolbar. So, I can only see the selected rows of the same grid where such an event was raised.
If I try to do this in the PBO of the dialog screen (that contains the two grids), the result of CL_SALV_SELECTIONS->GET_SELECTED_ROWS will be empty, as the program does not recognize the marked entries in the grids. Also, an event for grid1 does not see the selected rows from grid2 either.
As it is right now, I can have an own button in both grid's toolbar, select the rows, click on the extra button in each grid (this will tell me what entries were selected per grid). Then, I'd have to click on a third button (the one in the dialog screen's toolbar), and process the selected rows from both grids.
How can I select the rows, then click on just one button, and process the marked entries from both grids?
Is it somehow possible to raise an event belonging to each grid programmatically, so that then the corresponding CL_SALV_SELECTIONS->GET_SELECTED_ROWS will work?
Thanks.Hello Tamas ,
If I try to do this in the PBO of the dialog screen (that contains the two grids), the result of CL_SALV_SELECTIONS->GET_SELECTED_ROWS will be empty, as the program does not recognize the marked entries in the grids. Also, an event for grid1 does not see the selected rows from grid2 either.--->
is it possible to have a check box in each grid & get the selected lines in PAI of the screen ?
regards
prabhu -
Get Row Data from a selected Row in an ALV Grid
Hello,
I create a Custom Control from an intern table. When i do a double click on a row, i call another dynpro. The data of the marked line should be written into an internal table.
How i implement this?
I tried things like:
Call method alv_list->GET_SELECTED_ROWS_BASE
or
Call method alv_list->GET_SELECTED_ROWSHi Sebastian,
For a double click event we need to register the double click event which goes the following way.
data: lref_alv type ref to cl_gui_alv_grid.
* after initializing ALV
SET HANDLER gref_application->handle_alv_dblclik FOR lref_alv.
Now this double click event needs to be handled in the local class.
eg:
CLASS lcl_application DEFINITION.
PUBLIC SECTION.
METHODS:
* Method to handle double click on ALV grid.............................
handle_alv_dblclik
FOR EVENT double_click
OF cl_gui_alv_grid
IMPORTING e_row
e_column
es_row_no.
endclass.
CLASS lcl_application IMPLEMENTATION.
* Method: HANDLE_ALV_DBLCLICK *
* Text: Event triggers when ALV grid is double clicked *
* -->e_row *
* -->e_column *
* -->es_row_no, *
METHOD handle_alv_dblclik.
data: lv_value(40) TYPE c.
* Get the value of the current cell double clicked......................
CALL METHOD gref_alv->get_current_cell
IMPORTING
e_value = lv_value
* here you can insert the values in the internal table
endmethod.
endclass.
hope this helps.
Regards,
Kinshuk -
How to disable the first row of an ALV Grid?
Hi All,
I am working on a module pool programme. I am displaying ALV grid. I have to give some default values in the first row and disable it. I have to disable the third column and fourth row value. How can i achieve this?
Help will be appreciated.
Thanks,
Ibrahim.here is the code i have written....but its not working...
TYPES : BEGIN OF tp_grid,
fname(25) TYPE c,
reqd,
seqno TYPE n,
tl_styl TYPE lvc_t_styl,
edit,
END OF tp_grid.
DATA : wl_styl TYPE lvc_s_styl.
DATA : wl_layout TYPE lvc_s_layo.
DATA : lt_celltab TYPE lvc_t_styl.
READ TABLE tl_grid INTO wl_grid INDEX 1.
wl_styl-fieldname = 'TAG NUMBER'.
wl_styl-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT wl_styl INTO TABLE lt_celltab.
INSERT LINES OF lt_celltab INTO wl_grid-tl_styl index 1.
MODIFY tl_grid INDEX 1 FROM wl_grid.
wl_layout-stylefname = 'TL_STYL'.
CALL METHOD l_initgrid->set_table_for_first_display
EXPORTING
is_layout = wl_layout
CHANGING
it_outtab = tl_grid
it_fieldcatalog = tl_init_fcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM. " display_initgrid
Help will be appreciated....
Thanks,
Ibrahim -
How to decrease the row height in ALV Grid (OOPS).
HI Experts,
I have displayed ALV Grid using CL_GUI_ALV_GRID=>SET_TABLE_FOR_DISPLAY.
I want to decrease the row height and width.
Can any one suggest how to do this?
Regards,
Kumar.Hi Kumar,
Row height it predefined and you won't change it, but you can adjust column width.
For that use field COL_OPT of layout structure ( type LVC_SLAYO ) to optimize all columns width, or set explicit width using field catalog, setting field OUTPUTLEN for certain column.
Regards
Marcin -
Delete row in OO ALV grid toolbar
Hello;
I am using OO ALV grid to display data. On the standard toolbar when delete row button is activated the relevant row is removed from the screen. The program catches this event only when Enter is pressed. Is it possible to catch it as soon as delete row is pressed?
Thx in advance.
AliHi Ali,
You have to handle standard ALV toolbar. Even you can use Custom Toolbar. But you can handle it from Standard toolbar user command. Register events..
Thanks and Regards,
Sampath -
Multiple values in row in an alv grid
Hi experts,
I have to display data through alv grid control. The problem is I have multiple values in a row for one one field.
How should i display the data for this field in an ALV.
I need to display data like the fomatt:
field1 field2 field3 field4
1 2 5 6
3
4
7 8 12 13
9
10
11Hi,
first ur getting data like for 1st field having one itab with common field (eg) belnr is common field 1st field is (BLART) and 2nd field contain another itab with common field like that 3rd upto 4.
In that common loop itself you have to find which field having more records use the code like
itab1[] = gv_itab[]."pass the 1 field itab to another itab.
DELETE TABLE itab1 WITH TABLE KEY fieldname NE field value. " delete without common value.
DESCRIBE TABLE itab LINES li."1 field internal table
like that you have to do 4 fields itab.
Which is having more record loop the field itab table and use read statement for rest of field itab
and use append statement for getting final itab.
regards,
Dhina..
Edited by: Dhina DMD on Jun 16, 2011 1:17 PM -
HI,
I want to make my ALV Grid only single row select enabled, can some one guide me which variable should be set for the same.
Thanks and Regards,
HarshIf you are using OO for alv then
call method grid1->get_selected_rows
importing
et_index_rows = i_sel_alvrows[].
call method cl_gui_cfw=>flush.
describe table i_sel_alvrows lines v_dbcnt.
if i_sel_alvrows[] is initial.
* Info message : Please select a row
message i176. " Please select a row'.
endif.
if v_dbcnt gt 1.
* Info message : Multiple Row Selection not possible
message i177. " Multiple Row Selection not
" possible'
endif.
or if your using REUSE then
form user_command using p_ucomm type sy-ucomm
rs_selfield type slis_selfield.
" Check the rs_selfield-tabindex value here
" you may get some clue here
endform.
a® -
Appending Rows To Editable ALV Grid
Hi,
I have a requirement to allow users to append rows to ALV grid in order to insert new data. The standard append button works to add the row on the front end, however, when I go to process the row through the DATA_CHANGED event of the CL_GUI_ALV_GRID class the program errors out with a GETWA_NOT_ASSIGNED error.
Any help or examples of programs utilizing the Append button would be much appreciated.
Thanks,
Brian SHi,
check this demo program <b> BCALV_EDIT_04</b>
regards
Vijay -
Sending the rows in an ALV grid chosen by the user to another report
Hello Experts!
I am facing a problem with respect to ALV grid using OOABAP.
I am displaying an ALV grid. The user selects a few rows from this grid and clicks on a button called "Update" which i have incorporated into the grid.
Once the user clicks on update, i should call another report passing only the rows selected by the user. I am using the method "get_selected_rows" do get the indices of the rows selected. But, i am unable to proceed from here. How do i incorporate this logic in my code? Can anyone give me some sample code?
Thanks and Regards,
SmithaHi Smitha
Get the rows of the ALV into an internal table . You are right in using the method GET_SELECTED_ROWS.
Suppose li_tab is the internal table in which you have the rows of ALV.
Write this statement in the report from which you are transporting.
EXPORT li_tab TO MEMORY ID sy-repid.
Write this statement in the report to which you are transporting.
IMPORT sel_tab = li_tab FROM MEMORY ID 'Z_Report_Name'.
hope it works.
Reward points if helpful.
Maybe you are looking for
-
Error while trying to start OC4j11g in standalone mode
I get the following error while trying to start OC4j 11g 11.1.1 in standalone mode: Error initializing server: Shared library "oracle.fabric.runtime" could not be found. FYI, I have the imports for oracle.fabric, oracle.fabric.interceptors in server.
-
Why do I have 2 camera rolls in my iPhone 4?
Why do I have 2 Camera Rolls in my iPhone 4 Photos? The seconf Camera Roll has many dupes. Why does Camera Roll not automatically sync with Pictures in my laptop?
-
Very slow iTunes download to Windows 7
I've got a brand new Windows 7 32 bit computer that runs just great, but the downloading free podcasts thru the iTunes store takes forever -- like 10 minutes for a 20 minute podcast. The first few run fine, but then, it gets slower and slower and slo
-
My itunes shows my iphone but it has an apple logo and a lock on the other side of the screen but i can't sync or restore my iphone. what do i do?
-
MSS ESS document screen shots for ERP2005
Hi All, Does anybody have screen shots for SAP ESS MSS in a word document with content in it apart from the screen shots Thanks in Advance!