Skip to Content
author's profile photo Former Member
Former Member

How to make the column red in field catalog if its value is negetive

i am displaying 25 columns in a field catalog ,

if the value of the cell is negative it should appear in red colour .

for ex,

mat.no custno value

1 10 10

<b>2 20 -10</b>

3 30 20

note:

only cell which is the intersection of second row and third column

should appear red .

not the whole row or column

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 13, 2007 at 06:32 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 13, 2007 at 06:48 AM

    Hi Balaji,

    Please follow the instructions mentioned below:

    <b>step1: your ALV internal table should have a field (say,COLORCELL)of structure LVC_T_SCOL.

    step2: in the layout structure, set the coltab. for eg: is_layout-coltab_fieldname = 'COLORCELL'.

    step3: hide the column field 'COLORCELL' in fieldcatalog. for eg,

    loop at it_fieldcatalog into wa_fieldcatalog.
           if wa_fieldcatalog-fieldname = 'COLORCELL'.
                 wa_fieldcatalog-no_out  = 'X'.
                 modify it_fieldcatalog from wa_fieldcatalog. <b>(index sy-tabix</b> optional here)
           endif.
    endloop.

    step4: loop through the ALV internal table and check the condition where you need to color the cell.

    step5: write the following code:</b>

    perform set_column_color tables ls_alv_display-colorcell
                                       using  'DOCUMENT'             " field name
                                                 '6'                             "column number is red
                                                 '0'                             "inverse     
                                                 '0'.                            "intensity
    
    
    form set_column_color  tables et_color type lvc_t_scol
                                       using  p_fname  type lvc_fname
                                                 p_col    type lvc_col
                                                 p_inv    type lvc_inv
                                                 p_int    type lvc_int.
    data:
        ls_color type lvc_s_scol. 
        ls_color-fname     = p_fname.
        ls_color-color-col = p_col.
        ls_color-color-inv = p_inv.
        ls_color-color-int = p_int.
        append ls_color to et_color.
    endform.                                                  " set_column_color

    Hope this helps.

    Sajan Joseph.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 13, 2007 at 06:54 AM

    Hi,

    <b>Coloring Individual Cells</b>

    The procedure is similar to coloring an entire row. However, since an

    individual cell can be addressed with two parameters we will need something

    more. What is meant by “more” is a table type structure to be

    included into the structure of the list data table. It seems strange,

    because including it will make our list data structure deep. But anyhow ALV

    Grid control handles this.

    The structure that should be included must be of type “LVC_T_SCOL”.

    If you want to color the entire row, this inner table should contain

    only one row with field “fname” is set to space, some color value at

    field “col”, “0” or “1” at fields “int” (intensified)

    and “inv” (inverse).

    If you want to color individual cells, then for each cell column,

    append a line to this inner table which also contains the column name at

    field “fname”. It is obvious that you can color an entire column by

    filling this inner table with a row for that column for each row in the

    list data table.

    Again key field coloring will override your settings. That’s why, we

    have another field in this inner table called “nokeycol”. For each

    field represented in the inner table, set this field to ‘X’ to

    prevent overriding of key color settings.

    In this procedure, again we must tell the control the name of the inner

    table containing color data. The field “CTAB_FNAME” of the layout

    structure is used for this purpose.

    ---Internal table holding list data

    DATA BEGIN OF gt_list OCCURS 0 .

    INCLUDE STRUCTURE SFLIGHT .

    DATA rowcolor(4) TYPE c .

    DATA cellcolors TYPE lvc_t_scol .

    DATA END OF gt_list .

    Code Part 15 – A sample code to make the cell at row 5 and column

    ‘SEATSOCC’ colored

    DATA ls_cellcolor TYPE lvc_s_scol .

    ...

    READ TABLE gt_list INDEX 5 .

    ls_cellcolor-fname = 'SEATSOCC' .

    ls_cellcolor-color-col = '7' .

    ls_cellcolor-color-int = '1' .

    APPEND ls_cellcolor TO gt_list-cellcolors .

    MODIFY gt_list INDEX 5 .

    Hope this helps.

    Reward if helpful.

    Regards,

    Sipra

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 13, 2007 at 07:49 AM

    Hi Balaji,

    Run this code for coloring specific coloum in a row when the value of that column is negative

    REPORT zex34 .

    TYPE-POOLS: slis.

    INCLUDE <icon>.

    DATA: it_fieldcat TYPE slis_t_fieldcat_alv,

    it_fieldcat1 TYPE slis_t_fieldcat_alv..

    DATA: x_fieldcat TYPE slis_fieldcat_alv,

    x_fieldcat1 TYPE slis_fieldcat_alv.

    DATA: it_events TYPE slis_t_event,

    x_events TYPE slis_alv_event,

    i_program LIKE sy-repid.

    x_events-name = 'END_OF_LIST'.

    x_events-form = 'LIST_MODIFY_OUPUT'.

    APPEND x_events TO it_events.

    data : count type i,

    calc1 type i value 1,

    calc2 type i value 1,

    TOTREC TYPE I.

    DATA: BEGIN OF it_mara OCCURS 0,

    matnr LIKE mara-matnr,

    kunnr LIKE mara-kunnr,

    value type i,

    flag(1),

    END OF it_mara.

    SELECT matnr

    kunnr

    UP TO 10 ROWS

    INTO corresponding fields of TABLE it_mara

    FROM mara.

    loop at it_mara.

    count = sy-tabix mod 2.

    if count eq 0.

    it_mara-value = calc1.

    calc1 = calc1 + 6.

    it_mara-flag = ' '.

    else.

    calc2 = calc2 - 5.

    it_mara-value = calc2.

    it_mara-flag = 'X'.

    endif.

    modify it_mara index sy-tabix.

    TOTREC = TOTREC + 1.

    ENDLOOP.

    i_program = sy-repid.

    DATA:l_pos TYPE i VALUE 1.

    CLEAR: l_pos.

    l_pos = l_pos + 1.

    x_fieldcat-seltext_m = 'MATNR'.

    x_fieldcat-fieldname = 'MATNR'.

    x_fieldcat-tabname = 'IT_MARA'.

    x_fieldcat-col_pos = l_pos.

    x_fieldcat-outputlen = '18'.

    APPEND x_fieldcat TO it_fieldcat.

    CLEAR x_fieldcat.

    l_pos = l_pos + 1.

    x_fieldcat-seltext_m = 'KUNNR'.

    x_fieldcat-fieldname = 'KUNNR'.

    x_fieldcat-tabname = 'IT_MARA'.

    x_fieldcat-col_pos = l_pos.

    x_fieldcat-outputlen = '10'.

    APPEND x_fieldcat TO it_fieldcat.

    CLEAR x_fieldcat.

    l_pos = l_pos + 1.

    x_fieldcat-seltext_m = 'VALUE'.

    x_fieldcat-fieldname = 'VALUE'.

    x_fieldcat-tabname = 'IT_MARA'.

    x_fieldcat-col_pos = l_pos.

    x_fieldcat-outputlen = '10'.

    APPEND x_fieldcat TO it_fieldcat.

    CLEAR x_fieldcat.

    l_pos = l_pos + 1.

    x_fieldcat-seltext_m = 'FLAG'.

    x_fieldcat-fieldname = 'FLAG'.

    x_fieldcat-tabname = 'IT_MARA'.

    x_fieldcat-col_pos = l_pos.

    x_fieldcat-outputlen = '1'.

    APPEND x_fieldcat TO it_fieldcat.

    CLEAR x_fieldcat.

    l_pos = l_pos + 1.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

    i_callback_program = i_program

    it_fieldcat = it_fieldcat

    it_events = it_events

    TABLES

    t_outtab = it_mara

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    &----


    *& Form LIST_MODIFY_OUPUT

    &----


    • text

    ----


    FORM list_modify_ouput.

    DATA: l_matnr LIKE mara-matnr,

    l_kunnr LIKE mara-kunnr,

    l_value type i,

    l_index TYPE sy-index.

    CLEAR it_mara.

    DO 20 TIMES.

    CLEAR: l_matnr, l_kunnr , l_value.

    READ LINE sy-index INDEX sy-lsind

    FIELD VALUE it_mara-matnr INTO l_matnr

    it_mara-kunnr INTO l_kunnr

    it_mara-value into l_value.

    *3lines are reserved for alv headings , so i am reading it form 4th

    *line so 4th line is equal to 1st line of itab

    IF sy-subrc = 0 AND sy-index GE 4.

    l_index = sy-index - 3.

    READ TABLE it_mara INDEX l_index.

    IF sy-subrc = 0 AND it_mara-flag = 'X'.

    *-Modifying current list

    MODIFY LINE sy-index INDEX sy-lsind

    FIELD FORMAT it_mara-VALUE COLOR 6 INVERSE.

    ENDIF.

    ENDIF.

    ENDDO.

    ENDFORM.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.