06-30-2011 7:58 AM
Hello Experts,
I need to COLOR each and every CELL in an ALV GRID DISPLAY. I have used the below code lines :
TYPES : BEGIN OF T_EKPO,
-
(OTHER FIELDS)
CELL_COLOR TYPE LVC_T_SCOL,
END OF T_EKPO.
Ater that I have written CODE -LINES FOR FIELDCATALOG.
For the LAYOUT I have written,
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-coltab_fieldname = 'CELL_COLOR'.
endform. " BUILD_LAYOUT
FOR DATA FETCHING :
form data_retrieval.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into CORRESPONDING FIELDS OF TABLE it_ekpo.
endform.
FOR FILLING COLOR IN CELLS :
form set_color.
DATA: WA_CELLCOLOR TYPE LVC_S_SCOL.
DATA: ld_color TYPE sy-tabix.
LOOP AT IT_EKPO into wa_ekpo.
LD_color = SY-TABIX.
IF ld_color = 8.
ld_color = 1.
ENDIF.
WA_CELLCOLOR-FNAME = 'EBELN'.
WA_CELLCOLOR-COLOR-COL = LD_color.
WA_CELLCOLOR-COLOR-INT = '1'.
WA_CELLCOLOR-COLOR-INV = '0'.
APPEND WA_CELLCOLOR TO wa_ekpo-CELL_COLOR.
MODIFY it_ekpo from wa_ekpo INDEX ld_color TRANSPORTING CELL_COLOR.
if wa_ekpo-netpr gt 0.
WA_CELLCOLOR-FNAME = 'NETPR'.
WA_CELLCOLOR-COLOR-COL = LD_color.
WA_CELLCOLOR-COLOR-INT = '1'.
WA_CELLCOLOR-COLOR-INV = '0'.
APPEND WA_CELLCOLOR TO wa_ekpo-CELL_COLOR.
MODIFY it_ekpo from wa_ekpo INDEX ld_color TRANSPORTING CELL_COLOR.
endif.
WA_CELLCOLOR-FNAME = 'AEDAT'.
WA_CELLCOLOR-COLOR-COL = LD_color.
WA_CELLCOLOR-COLOR-INT = '1'.
WA_CELLCOLOR-COLOR-INV = '0'.
APPEND WA_CELLCOLOR TO wa_ekpo-CELL_COLOR.
MODIFY it_ekpo from wa_ekpo INDEX ld_color TRANSPORTING CELL_COLOR.
ENDLOOP.
IF ld_color = 8.
ld_color = 1.
ENDIF.
ENDFORM. " SET_CELL_COLOURS
FINALLY I HAVE PASSED ALL THE GD_LAYOT , FIELDCATALOG ETC. IN FM 'REUSE_ALV_GRID_DISPLAY.
MY PROBLEM IS : after the 7th line of each column I'm getting the SAME COLOR for the remaining 3 lines (bluish-gray), but I want the colors to be displayed alternatively for THE LAST 3 CELLS of each columns .
PLEASE HELP.
06-30-2011 11:31 AM
hi,
you have 10 rows in your internal table.
The colour for each row is appended in the last column which you have added for the colour.
You intend to display just the last 3 rows in 3 different colours.
Then just loop your internal table from index 8-10.
In the loop assign a new colour in each loop.
modify your internal table.
pass the same to fieldcatalog.
06-30-2011 12:54 PM
HELLO EXPERT,
I actually have wanted to color all the cells of a particular cplumn. But only the 1st 7 cells are displayed with different colours (blue,green,yellow etc) and those are displayed accordingly.
But the remaining 3 cells are getting same color, I want them to be displayed as the other 7 rows, that is with 3 different colors.
PLEASE ADVICE.
07-01-2011 6:10 AM
Hi,
you ar epassing colour based on sy-tabix.
LOOP AT IT_EKPO into wa_ekpo.
LD_color = SY-TABIX.
So the colour would change with the row no.But since we have options from 0-7, the values more then 7 are not identified.
As also mentioned by suman, What you can do is :
ld_color = 0
loop at itab into wa.
ld_color = ld_color + 1.
If sy-tabix = 8.
clear ld_Color.
endif.
endloop.
07-01-2011 7:27 AM
06-30-2011 9:49 PM
Valid values for Color are from 1 to 7. So in your Loop at IT_EKPO as you are assigning LD_Color with Sy-tabix value, the first 7 are getting different colors and the remaining 8,9,10 are getting default color as color value 8,9,10 are invalid. Check the below logic which would generate 1 to 7 for the sy-tabix value 1 to 10.
LOOP AT IT_EKPO into wa_ekpo.
LD_color = ( SY-TABIX - 1 ) mod 7 + 1. " Returns 1 to 7 for different Sy-tabix values
WA_CELLCOLOR-FNAME = 'EBELN'.
WA_CELLCOLOR-COLOR-COL = LD_color.
WA_CELLCOLOR-COLOR-INT = '1'.
..... " Existing logic
ENDLOOP.
07-01-2011 7:35 AM
Hi SUMAN,
Your solution is very helpful, but anyhow I couldn't use the ' MOD ' properly and got an error like - ' IN PLACE OF ''MOD 7'' (+ * , OR ANY BIT OPERATION IS EXPECTED '.
Would you please tell me what the problem is ?
07-01-2011 2:51 PM
Can you paste your code - line with MOD statement so that I can tell the exact issue. The code I provided didnt give me any error though. Copy paste the below code into your code and try.
LD_color = ( ( SY-TABIX - 1 ) mod 7 ) + 1.
07-02-2011 4:53 PM
Hi SUMAN,
Actually I have missed the 2nd single-bracket (closing) and that's why got the error.
Once again thank you very much.