Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

CELL COLOR IN ALV GETS REPEATED

Former Member
0 Kudos

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.

8 REPLIES 8

Former Member
0 Kudos

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.

0 Kudos

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.

0 Kudos

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.

0 Kudos

THANK YOU EXPERT,

It really worked . The problem is solved.

Former Member
0 Kudos

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.

0 Kudos

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 ?

0 Kudos

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.

0 Kudos

Hi SUMAN,

Actually I have missed the 2nd single-bracket (closing) and that's why got the error.

Once again thank you very much.