09-02-2008 9:01 PM
Hi, I created a alv with objects, this shows the following data:
Jan Feb March April
% REPROCESO MENSUAL 4.000 10.000 3.000 5.000
% REPROCESO ACUMULADO 21.000 26.000 11.000 16.000
By default both rows are gray, but I need than the cells whose value is < 5 be red,when the cells are > 5 and < 20 be yellow,
I used the following code for that,I use this code for each column
of each row:
WA_COLOR-FNAME = FNAME.
WA_COLOR-COLOR-COL = COL.
WA_COLOR-COLOR-INT = INT.
WA_COLOR-COLOR-INV = INV.
APPEND WA_COLOR TO IT_COLOR.
W_DATOS-COLOR_CELL[] = IT_COLOR[].
but when I test,the alv for case of March and April,only the value 16.000 is yellow. I need to paint some cells in the same row.
Please any ideas?
09-02-2008 9:06 PM
You have to fill this the COLOR table for all the fields e.g. Jan, Feb, March, April.. and so on..
WA_COLOR-FNAME = 'JAN'.
WA_COLOR-COLOR-COL = COL.
WA_COLOR-COLOR-INT = INT.
WA_COLOR-COLOR-INV = INV.
APPEND WA_COLOR TO IT_COLOR.
WA_COLOR-FNAME = 'FEB'.
WA_COLOR-COLOR-COL = COL.
WA_COLOR-COLOR-INT = INT.
WA_COLOR-COLOR-INV = INV.
APPEND WA_COLOR TO IT_COLOR.
and so on.
Regards,
Naimesh Patel
09-02-2008 9:06 PM
Yes you can.
have a look at demo program SALV_DEMO_TABLE_COLUMNS.
It colors a column but if you fill parameter FNAME then just a cell is filled with a color.
09-02-2008 9:06 PM
You have to fill this the COLOR table for all the fields e.g. Jan, Feb, March, April.. and so on..
WA_COLOR-FNAME = 'JAN'.
WA_COLOR-COLOR-COL = COL.
WA_COLOR-COLOR-INT = INT.
WA_COLOR-COLOR-INV = INV.
APPEND WA_COLOR TO IT_COLOR.
WA_COLOR-FNAME = 'FEB'.
WA_COLOR-COLOR-COL = COL.
WA_COLOR-COLOR-INT = INT.
WA_COLOR-COLOR-INV = INV.
APPEND WA_COLOR TO IT_COLOR.
and so on.
Regards,
Naimesh Patel
09-02-2008 10:54 PM
Hello Jose
Have a look at my sample report ZUS_SDN_ALV_CELL_STYLE_2. All you need to do is to define your conditions to fill the CELLTAB with the appropriate styles.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_ALV_STYLE_LIST
*&
*&---------------------------------------------------------------------*
*& Thread: Painting cell in alv with objects
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1029759"></a>
*&
*& Thread: styles
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="830498"></a>
*&
*& Thread: Is it possible to assign color to manually modified record in tabcontrol?
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="878289"></a>
*&---------------------------------------------------------------------*
*& The report generates style values and shows their effect in ALV grid.
*&---------------------------------------------------------------------*
REPORT zus_sdn_alv_cell_style_2.
TYPE-POOLS: abap.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES: celltab TYPE lvc_t_styl. " cell style
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
TYPES: BEGIN OF ty_s_outtab2.
INCLUDE TYPE lvc_s_styl.
TYPES: celltab TYPE lvc_t_styl. " cell style
TYPES: END OF ty_s_outtab2.
TYPES: ty_t_outtab2 TYPE STANDARD TABLE OF ty_s_outtab2
WITH DEFAULT KEY.
DATA:
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
gt_fcat TYPE lvc_t_fcat.
DATA:
gt_outtab TYPE ty_t_outtab,
gt_outtab2 TYPE ty_t_outtab2.
parameters:
p_rows type i default 200.
START-OF-SELECTION.
SELECT * FROM knb1 UP TO 100 ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_outtab
WHERE bukrs = '1000'.
PERFORM set_layout_and_variant.
PERFORM set_cell_style.
** CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
** EXPORTING
** i_structure_name = 'KNB1'
** i_grid_title = 'Cell Styles'
** is_layout_lvc = gs_layout
** i_save = 'A'
** is_variant = gs_variant
** TABLES
** t_outtab = gt_outtab
** EXCEPTIONS
** program_error = 1
** OTHERS = 2.
** IF sy-subrc = 0.
** ENDIF.
PERFORM fill_outtab2.
** PERFORM fill_fieldcatalog_2.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'LVC_S_STYL'
i_grid_title = 'Cell Styles'
is_layout_lvc = gs_layout
i_save = 'A'
is_variant = gs_variant
* IT_FIELDCAT_LVC = gt_fcat
TABLES
t_outtab = gt_outtab2
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc = 0.
ENDIF.
END-OF-SELECTION.
*&---------------------------------------------------------------------
*& Form SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------
FORM set_layout_and_variant .
CLEAR: gs_layout,
gs_variant.
gs_layout-cwidth_opt = abap_true.
gs_layout-stylefname = 'CELLTAB'.
gs_variant-report = syst-repid.
gs_variant-handle = 'STYL'.
ENDFORM. " SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*& Form set_cell_style
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM set_cell_style .
* define local data
CONSTANTS:
lc_style_bold TYPE int4 VALUE '00000121',
lc_style_red TYPE int4 VALUE '00000087',
lc_style_cursive TYPE int4 VALUE '00008700',
lc_style_underline_faint TYPE int4 VALUE '00008787',
lc_style_underline TYPE int4 VALUE '00008707',
lc_style_underline_red TYPE int4 VALUE '00008007'.
DATA:
ls_outtab TYPE ty_s_outtab,
ls_style TYPE lvc_s_styl,
lt_celltab TYPE lvc_t_styl.
CLEAR: ls_style.
ls_style-fieldname = 'BUKRS'.
ls_style-style = '00000011'. " make contents invisible
INSERT ls_style INTO TABLE lt_celltab.
** CLEAR: ls_style.
** ls_style-fieldname = 'BUKRS'.
** ls_style-style = lc_style_bold.
** INSERT ls_style INTO TABLE lt_celltab.
***
** CLEAR: ls_style.
** ls_style-fieldname = 'KUNNR'.
** ls_style-style = lc_style_red.
** INSERT ls_style INTO TABLE lt_celltab.
***
** CLEAR: ls_style.
** ls_style-fieldname = 'ERDAT'.
** ls_style-style = lc_style_cursive.
** INSERT ls_style INTO TABLE lt_celltab.
***
** CLEAR: ls_style.
** ls_style-fieldname = 'ERNAM'.
** ls_style-style = lc_style_underline.
** INSERT ls_style INTO TABLE lt_celltab.
ls_outtab-celltab = lt_celltab.
MODIFY gt_outtab FROM ls_outtab
TRANSPORTING celltab
WHERE ( bukrs = '1000' ).
ENDFORM. " SET_CELL_STYLE
*&---------------------------------------------------------------------*
*& Form FILL_OUTTAB2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_outtab2 .
* define local data
DATA: ls_outtab2 TYPE ty_s_outtab2,
ld_num8(8) TYPE n,
ld_idx TYPE i,
ld_fname TYPE fieldname,
ld_perc type i,
ld_text(50) type c.
DATA:
ls_style TYPE lvc_s_styl,
lt_celltab TYPE lvc_t_styl.
FIELD-SYMBOLS: <ld_style> TYPE lvc_style.
ld_num8 = 0.
DO p_rows TIMES.
write syst-index to ld_text no-zero.
condense ld_text NO-GAPS.
ld_perc = ( syst-index * 100 ) / p_rows.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = ld_perc
text = ld_text.
CLEAR: ls_style,
ls_outtab2.
REFRESH: lt_celltab.
ls_outtab2-maxlen = syst-index.
MOVE ld_num8 TO ls_outtab2-style.
ls_style-style = ls_outtab2-style.
INSERT ls_style INTO TABLE lt_celltab.
ls_outtab2-celltab = lt_celltab.
APPEND ls_outtab2 TO gt_outtab2.
ADD 1 TO ld_num8.
ENDDO.
ENDFORM. " FILL_OUTTAB2
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCATALOG_2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_fieldcatalog_2 .
* define local data
DATA: ls_fcat TYPE lvc_s_fcat,
lt_fcat TYPE lvc_t_fcat.
DATA: ld_fname TYPE fieldname.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'LVC_S_STYL'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = lt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DELETE lt_fcat WHERE ( fieldname NE 'STYLE' ).
READ TABLE lt_fcat INTO ls_fcat INDEX 1.
DO 16 TIMES.
ls_fcat-fieldname = 'STYLE'.
ls_fcat-col_pos = syst-index.
WRITE syst-index TO ld_fname NO-ZERO.
CONDENSE ld_fname NO-GAPS.
CONCATENATE ls_fcat-fieldname ld_fname INTO ls_fcat-fieldname.
APPEND ls_fcat TO gt_fcat.
ENDDO.
ENDFORM. " FILL_FIELDCATALOG_2
Regards
Uwe