Color in alv ( cell)

hello
i tried to color only some cells in alv but i want just what i write will be colored and not all the row
for exmaple:
if i have in one row the value 500 i want just the 500 will have color and not all the row
thanks

Hi,
here is another sample report..
report zc9_alvgrid_final_now .
*PROGRAM ON ALV-GRID.
*TABLE DECLARATION.
*tables:zc9_employee, zc9_empspec.
type-pools: slis. "ALV Declarations
data: celcol1 type slis_specialcol_alv.
data: syprindex type i value 1.
*INTERNAL TABLE DECLARATION.
data: begin of itab_alv1 OCCURS 0,
emp_id(5) TYPE C,
emp_name(20) TYPE C,
certified(3) TYPE C,
celcol type slis_t_specialcol_alv,
selected(1) type c,
end of itab_alv1.
data: begin of itab_alv3 OCCURS 0,
emp_id(5) TYPE C,
emp_name(20) TYPE C,
certified(3) TYPE C,
end of itab_alv3.
data: mulrowtab1 like line of itab_alv1.
data: mulrowtab like table of itab_alv1.
data: wa_emp_name like zc9_employee-emp_name.
data: mulrowindex type i value 1.
data: maxlines type i.
data: wa like line of itab_alv1.
data: wa_itab like line of itab_alv1.
data: ok-code like sy-ucomm.
data: ok-code1 like sy-ucomm.
data: ind type i.
data: newvar type disvariant.
data: tempvar type i value 0.
data: gd_repid like sy-repid.
*ALV-GRID DATA DECLARATION.
data: fieldcatalog type slis_t_fieldcat_alv.
* FIELD CATALOG.
data: fieldcatalog1 type slis_fieldcat_alv.
data: gd_layout type slis_layout_alv.
* LAYOUT DECLARATION.
data: id_color type c.
data: eventtable type slis_t_event.
data: wa_event type slis_alv_event.
data: newvariant type disvariant.
data: i_exclude type slis_t_extab, "ALV Exclusion Table
wa_exclude type slis_extab. "ALV Exclusion Structure
*VARIANT DECLARATION.
data: vartype like disvariant.
data: var_save(1) type c.
data: w_exit(1) type c.
data: wx_variant like disvariant.
data: variant_para like disvariant-variant.
data: itab_emp like table of zc9_employee.
data: itab_emp1 like line of itab_emp.
data: itab_spec like table of zc9_empspec.
data: itab_spec1 like line of itab_spec.
data: ls_sort type slis_sortinfo_alv.
data: lt_sort type slis_t_sortinfo_alv.
parameter: LAYOUT like disvariant-variant.
* INITIALIZATION.
gd_repid = sy-repid.
*CALLING SELECTION SCREEN-SUBROUTINES.
*AT SELECTION SCREEN
at selection-screen output.
perform init_variant.
perform variant_default using LAYOUT.
at selection-screen on value-request for LAYOUT.
perform variant_select using LAYOUT.
at selection-screen.
perform variant_fill.
newvar = vartype.
* LAYOUT DECLARATION.
gd_layout-zebra = 'X'.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-box_fieldname = 'SELECTED'.
gd_layout-box_tabname = 'ITAB_ALV1'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-coltab_fieldname = 'CELCOL'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = gd_repid
i_internal_tabname = 'ITAB_ALV3'
i_inclname = gd_repid
changing
ct_fieldcat = fieldcatalog
*FIELD-CATALOG DECLARATION.
loop at fieldcatalog into fieldcatalog1.
case fieldcatalog1-fieldname.
when 'EMP_ID'.
fieldcatalog1-seltext_m = 'EMP-ID'.
fieldcatalog1-col_pos = 0.
fieldcatalog1-outputlen = 10.
fieldcatalog1-emphasize = 'C2'.
fieldcatalog1-key = 'X'.
fieldcatalog1-do_sum = 'X'.
fieldcatalog1-sp_group = 'A'.
when 'EMP_NAME'.
fieldcatalog1-fieldname = 'EMP_NAME'.
fieldcatalog1-seltext_m = 'EMPLOYEE_NAME'.
fieldcatalog1-col_pos = 1.
fieldcatalog1-emphasize = 'C2'.
fieldcatalog1-hotspot = 'X'.
fieldcatalog1-key = 'X'.
fieldcatalog1-outputlen = 20.
fieldcatalog1-sp_group = 'B'.
when 'CERTIFIED'.
fieldcatalog1-fieldname = 'CERTIFIED'.
fieldcatalog1-seltext_m = 'CERTIFIED'.
fieldcatalog1-col_pos = 2.
fieldcatalog1-emphasize = 'C2'.
fieldcatalog1-key = 'X'.
fieldcatalog1-sp_group = 'C'.
endcase.
modify fieldcatalog from fieldcatalog1.
endloop.
*SORTING FIELD CATALOG FIELD.
ls_sort-spos = 1.
ls_sort-fieldname = 'EMP_ID'.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
append ls_sort to lt_sort.
*POPULATING THE INTERNAL TABLE.
ITAB_ALV1-EMP_ID = '15530'.
ITAB_ALV1-EMP_NAME = 'THILAKJI'.
ITAB_ALV1-CERTIFIED = 'YES'.
APPEND ITAB_ALV1.
ITAB_ALV1-EMP_ID = '15531'.
ITAB_ALV1-EMP_NAME = 'MATHEWS'.
ITAB_ALV1-CERTIFIED = 'NO'.
APPEND ITAB_ALV1.
ITAB_ALV1-EMP_ID = '15532'.
ITAB_ALV1-EMP_NAME = 'JAISI'.
ITAB_ALV1-CERTIFIED = 'YES'.
APPEND ITAB_ALV1.
ITAB_ALV1-EMP_ID = '15533'.
ITAB_ALV1-EMP_NAME = 'ADAMS'.
ITAB_ALV1-CERTIFIED = 'YES'.
APPEND ITAB_ALV1.
ITAB_ALV1-EMP_ID = '15534'.
ITAB_ALV1-EMP_NAME = 'PAUL'.
ITAB_ALV1-CERTIFIED = 'NO'.
APPEND ITAB_ALV1.
* FORM TO MAKE THE CELL CONTENTS INVISIBLE.
PERFORM INVISIBLE_CELL_CONTENTS.
*EXCLUDE-DECLARATION.
clear wa_exclude.
wa_exclude-fcode = '&VEXCEL'.
append wa_exclude to i_exclude.
* FUNCTION MODULE CALL-REUSE-ALV-GRID-DISPLAY.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE2' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = 'ALV GRID-EMPLOYEE'
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_sort = lt_sort
it_excluding = i_exclude
i_callback_pf_status_set = 'SET_PF_STATUS' "see FORM
i_save = 'A'
is_variant = newvar
tables
t_outtab = itab_alv1
exceptions
program_error = 1
others = 2.
* Form TOP-OF-PAGE *
* ALV Report Header *
form top-of-page2.
data: header type slis_t_listheader,
wa type slis_listheader,
infield like wa-info,
nline type i,
nlinechar(2) type c.
*TITLE AREA
wa-typ = 'H'.
wa-info = 'EMPLOYEE-DETAILS'.
append wa to header.
*BELOW AREA.
wa-typ = 'S'.
wa-key = 'DATE'.
concatenate sy-datum+6(2) '.' sy-datum+4(2) '.' sy-datum(4) into wa-info
append wa to header.
*NEXT LINE.
wa-typ = 'S'.
describe table itab_alv1 lines nline.
nlinechar = nline.
wa-key = 'TABLE DETAILS'.
concatenate 'NO.of.Lines:' nlinechar into wa-info separated by space.
append wa to header.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = header
i_logo = 'ALVLOGO'.
endform.
* FORM SET_PF_STATUS *
form set_pf_status using rt_extab type slis_t_extab.
set pf-status 'NEWSTATUS123'.
endform.
* FORM USER_COMMAND *
* --> R_UCOMM *
* --> RS_SELFIELD *
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
* Check function code
case r_ucomm.
when 'SELM'.
loop at itab_alv1 where selected = 'X'.
move-corresponding itab_alv1 to mulrowtab1.
append mulrowtab1 to mulrowtab.
endloop.
message i029(zmc).
clear mulrowtab1.
when 'DISP'.
* Check field clicked on within ALVgrid report
if rs_selfield-fieldname = 'EMP_ID'.
* Read data table, using index of row user clicked on
read table itab_alv1 into wa index rs_selfield-tabindex.
ind = rs_selfield-tabindex.
message i025(zmc) with rs_selfield-fieldname .
elseif rs_selfield-fieldname = 'EMP_NAME'.
read table itab_alv1 into wa index rs_selfield-tabindex.
ind = rs_selfield-tabindex.
message i028(zmc) with rs_selfield-fieldname wa-emp_name .
endif.
when 'EXIT'.
* MESSAGE I026(ZMC).
leave program.
when 'CHAN'.
* READ TABLE itab_alv1 INTO wa INDEX rs_selfield-tabindex.
read table itab_alv1 into wa index rs_selfield-tabindex.
call screen 1551.
tempvar = 1.
*CALLING THE GRID DISPLAY FUNCTION AGAIN.
* FUNCTION MODULE CALL-REUSE-ALV-GRID-DISPLAY.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = 'ALV GRID-EMPLOYEE'
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_events = eventtable
i_save = 'X'
it_excluding = i_exclude
i_callback_pf_status_set = 'SET_PF_STATUS' "see FORM
is_variant = newvar
tables
t_outtab = itab_alv1
exceptions
program_error = 1
others = 2.
r_ucomm = '&F03'.
when '&F03'.
* IF TEMPVAR = 1.
leave program.
endcase.
clear r_ucomm.
endform.
*& Module USER_COMMAND_1551 INPUT
* text
module user_command_1551 input.
data: syprtabix type i.
case ok-code.
when 'QUIT'.
set screen 0.
leave screen.
clear itab_alv1.
sy-tabix = 0.
when 'UPDA'.
loop at itab_alv1 where emp_id = wa-emp_id.
syprtabix = sy-tabix.
endloop.
modify itab_alv1 from wa index syprtabix transporting emp_id emp_name
certified.
message i027(zmc).
leave screen.
endcase.
endmodule. " USER_COMMAND_1551 INPUT
*& Module STATUS_1551 OUTPUT
* text
module status_1551 output.
set pf-status 'ZNEWSTATUS'.
* SET TITLEBAR 'xxx'.
endmodule. " STATUS_1551 OUTPUT
*FORM FOR SELECTING LAYOUT.
form variant_select using form_varpar.
call function 'LVC_VARIANT_F4'
exporting
is_variant = vartype
* IT_DEFAULT_FIELDCAT =
i_save = var_save
importing
e_exit = w_exit
es_variant = wx_variant
exceptions
not_found = 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.
if w_exit is initial.
vartype-variant = wx_variant-variant.
form_varpar = wx_variant-variant.
endif.
endform.
*& Form init_variant
form init_variant.
clear: vartype.
gd_repid = sy-repid.
vartype-report = sy-repid.
vartype-username = sy-uname.
var_save = 'A'. "All types
endform.
*& Form variant_default
form variant_default using p_variant.
wx_variant = vartype.
if not p_variant is initial.
wx_variant-variant = p_variant.
endif.
call function 'LVC_VARIANT_DEFAULT_GET'
exporting
i_save = var_save
changing
cs_variant = wx_variant
exceptions
wrong_input = 1
not_found = 2
program_error = 3
others = 4.
case sy-subrc.
when 0.
p_variant = wx_variant-variant.
when 2.
clear: p_variant.
endcase.
endform.
*& Form variant_fill
form variant_fill.
clear: vartype.
if LAYOUT is initial.
vartype-variant = 'STANDARD'.
vartype-report = sy-repid.
else.
vartype-variant = LAYOUT.
vartype-report = sy-repid.
call function 'LVC_VARIANT_EXISTENCE_CHECK'
exporting
i_save = var_save
changing
cs_variant = vartype
exceptions
others = 01.
if sy-subrc ne 0.
message i000(zz) with text-g02.
endif.
endif.
endform.
*& Module STATUS_1234 OUTPUT
* text
module status_1234 output.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
endmodule. " STATUS_1234 OUTPUT
*& Module USER_COMMAND_1234 INPUT
* text
module user_command_1234 input.
sort mulrowtab.
describe table mulrowtab lines maxlines.
case ok-code1.
when 'OUT1'.
set screen 0.
leave screen.
when 'PUSH'.
clear mulrowtab1.
if mulrowindex <= maxlines.
read table mulrowtab into mulrowtab1 index mulrowindex.
mulrowindex = mulrowindex + 1.
else.
message i030(zmc).
endif.
endcase.
endmodule. " USER_COMMAND_1234 INPUT
* CEL COLOR TABLE POPULATION.
FORM INVISIBLE_CELL_CONTENTS.
loop at itab_alv1 INTO WA.
IF WA-EMP_ID = ' '.
EXIT.
ENDIF.
clear itab_alv1.
move-corresponding WA to itab_alv1.
clear celcol1.
celcol1-fieldname = 'EMP_ID'.
celcol1-color-col = syprindex.
append celcol1 to itab_alv1-celcol.
celcol1-fieldname = 'EMP_NAME'.
celcol1-color-col = syprindex + 2.
append celcol1 to itab_alv1-celcol.
* CODE FOR MAKING THE GRID CELL CONTENTS INVISIBLE BASED ON THE VALUE OF
*THE CELL.THE CONDITION CHECKED IS WHETHER
* CERTIFIED FIELD HAS VALUE 'NO'.
celcol1-fieldname = 'CERTIFIED'.
if itab_alv1-certified = 'NO'.
itab_alv1-emp_name = ' '.
endif.
celcol1-color-col = syprindex + 3.
append celcol1 to itab_alv1-celcol.
MODIFY ITAB_ALV1.
syprindex = celcol1-color-col - 1.
CLEAR ITAB_ALV1.
endloop.
ENDFORM.
Regards,
Suresh Datti

Similar Messages

  • Fill colors to ALV cells

    Hi All,
    How can I display multiple colors to different cells in an ALV ?.
    Please help..
    Thanks in advance,
    sudeep v d..

    Hi Sudeep,
    In the below mentioned link a topic Color of ALV output, columns, and cells has been mentioned in the section '4.17.3 Appearance of ALV Output'.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/db22242d-0701-0010-28a2-aeaa1fefd706
    Best regards,
    Suresh

  • Coloring an ALV Cell with DYNAMIC INTERNAL TABLES

    Hello Gurus,
    I need your help regarding coloring of a cell in my ALV Grid report with DYNAMIC tables.
    I have used the call method in calling my ALV. (CALL METHOD gr_alvgrid->set_table_for_first_display).
    Now my problem is, I can not bring out the cellcolor succesfully, I always ended up to dump (GETWA_NOT_ASSIGNED = You attempted to access an unassigned field symbol     
    (data segment 32807).                                  
    What I have done:
    I've created 2 internal tables:
    *1st table
    *After appended all of my columns to  gt_fieldcat
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gt_fieldcat
        IMPORTING
          ep_table        = gp_both.
      ASSIGN gp_both->* TO <i_xtab1>.
    *2nd table
    Appended these column for CellColor
      CLEAR wa_gtfldcat.
      wa_gtfldcat-fieldname = 'CELLCOLOR'.
      wa_gtfldcat-ref_table = 'CALENDAR_TYPE'.
      wa_gtfldcat-ref_field = 'COLTAB'.
      APPEND wa_gtfldcat TO gt_fieldcat.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gt_fieldcat
        IMPORTING
          ep_table        = gp_alvgrid.
      ASSIGN gp_alvgrid->* TO <i_xtab2>.
    *Work Areas for tab1 and tab2
    CREATE DATA dref1 LIKE LINE OF <i_xtab1>.
      ASSIGN dref1->* TO <wa_xtab1>.
      CREATE DATA dref2 LIKE LINE OF <i_xtab2>.
      ASSIGN dref2->* TO <wa_xtab2>.
    *Move contents of table1 to table2 and modify cellcolor column
    LOOP AT <i_xtab1> ASSIGNING <wa_xtab1>.
    *-----Cell color assignment
        DESCRIBE TABLE gt_fieldcat.
        DO sy-tfill TIMES.
          READ TABLE gt_fieldcat INTO wa_gtfldcat INDEX sy-index.
          ASSIGN COMPONENT wa_gtfldcat-fieldname
            OF STRUCTURE <wa_xtab1> TO <fs4>.
          IF sy-subrc NE 0. EXIT .ENDIF.
          ASSIGN COMPONENT wa_gtfldcat-fieldname
            OF STRUCTURE <wa_xtab2> TO <fs3>.
          IF sy-subrc NE 0. EXIT .ENDIF.
            <fs3> = <fs4>.
        ENDDO.
        ASSIGN COMPONENT 'CELLCOLOR' OF STRUCTURE <wa_xtab2> TO <fs3>.
        IF sy-subrc = 0.
          PERFORM modify_cell_color USING 'ZZMATNR' <fs3>.
        ENDIF.
        APPEND <wa_xtab1> TO <i_xtab2>.
    ENDLOOP.
    *Call ALV
    gs_layout-ctab_fname = 'COLORCELL'
        CALL METHOD gr_alvgrid->set_table_for_first_display
          EXPORTING
            is_layout                     = gs_layout
          CHANGING
            it_outtab                     = <i_xtab2d>[]
            it_fieldcatalog               = gt_fieldcat
            it_sort                       = lt_sort
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            OTHERS                        = 4.
        IF sy-subrc <> 0.
    *--->Exception handling
        ENDIF.
    FORM modify_cell_color  USING p_fieldname   TYPE lvc_fname
                                  pt_cellcolor  TYPE table.
      DATA l_cellcolor TYPE lvc_s_scol.
      CLEAR l_cellcolor.
      l_cellcolor-fname = p_fieldname.
      l_cellcolor-color-col = 6.       " Red.
      l_cellcolor-color-int = 0.
      l_cellcolor-color-inv = 0.
      INSERT l_cellcolor INTO TABLE pt_cellcolor.
    ENDFORM.                    " MODIFY_CELL_COLOR

    Hi,
    The internal tabl which you are using to display the output should have one column in the end.
    The cell in this column will contain an internal table of type 'lvc_s_scol'.
    The contents of this internal table will be the field names of all other columns of your main internal table in the field FNAME and the required color in the field COLOR.
    Please note that the field COLOR will have a hex value for different colors.
    In the stucture is_layout  whihc you pass to the method 'set_table_for_first_display'
    the name of this last column should be given to the field 'ctab_fname'.
    This will help you to give the colors to each cell.
    for example
    I have my data table as follows:-
    ITAB1
    MATNR  MAKTX        COLOR_TAB
    1           ABC            FNAME  COLOR  NOKEYCOL
                                    MATNR 8000
                                    MAKTX 8000
    2          XYZ             MATNR 10000
                                  MAKTX  10000
    So my internal table ITAB1 had 3 columns MATNR MAKTX and COLOR_TAB.
    And COLOR_TAB will contain an internal table with 3 columns FNAME COLOR and NOKEYCOL.
    The value to importing parameter IS_LAYOUT-CTAB_FNAME will be COLOR_TAB.
    This will help you to assign various colors to the cell of the internal table ITAB.
    When you have to change any color, then you will have to just change the entries in cell COLOR_TAB for the particular row and cell.
    Regards,
    Ankur Parab

  • Different colors in alv cell

    Hello experts,
    I use reuse_Alv for displaying my alv.
    I use this command to color single cells background color
      LOOP AT gt_mytab  INTO ls_mytab.
        ld_index = sy-tabix.
        IF ls_mytab-expstatus = '0000'.
          wa_cellcolor-fname = 'EXPSTATUS'.
          "color code 1-7, if outside rage defaults to 7
          wa_cellcolor-color-col = 5.
          "1 = Intensified on, 0 = Intensified off
          wa_cellcolor-color-int = '0'.
          "1 = text colour, 0 = background colour
          wa_cellcolor-color-inv = '0'.
          APPEND wa_cellcolor TO ls_mytab-cellcolor.
          MODIFY gt_mytab FROM ls_mytab INDEX ld_index
          TRANSPORTING cellcolor.
        ENDIF.
      ENDLOOP.
    But what if i wanted to color the cell background fx. yellow and the text in the cell green, is this possible?
    Thanks in advance.
    Kenneth

    Hi Kenneth,
    Try to use '-emphasize' field to adjust cell that you are going to set.
    Or, please refer to this [link|http://forums.sdn.sap.com/thread.jspa?threadID=1336861].
    Hope it helps.
    Regards,
    Dondi.

  • How to color a specific cell in ALV (not REUSE_ALV_GRID_DISPLAY)

    Hi
    I want to change color font or background to a specify position in ALV grid
    It is possible but by creating ALV container (not FM for example REUSE_ALV_GRID_DISPLAY)?

    Hi,
    REPORT ZALV_LIST1.
    TABLES:
    SPFLI.
    TYPE-POOLS:
    SLIS.
    PARAMETERS:
    P_COL TYPE I ,
    P_ROW TYPE I,
    P_COLOR(4) TYPE C .
    DATA:
    T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
    FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,
    W_COLOR(4) ,
    W_ROW TYPE I,
    W_FIELDNAME(20),
    W_PROG TYPE SY-REPID.
    DATA:
    BEGIN OF T_SPFLI OCCURS 0,
    COLOR(4),
    CHECKBOX ,
    CELL TYPE SLIS_T_SPECIALCOL_ALV,
    CARRID TYPE SPFLI-CARRID,
    CONNID TYPE SPFLI-CONNID,
    CITYFROM TYPE SPFLI-CITYFROM,
    CITYTO TYPE SPFLI-CITYTO,
    DISTANCE TYPE SPFLI-DISTANCE,
    END OF T_SPFLI.
    DATA:
    FS_CELL LIKE LINE OF T_SPFLI-CELL.
    SELECT *
    FROM SPFLI
    INTO CORRESPONDING FIELDS OF TABLE T_SPFLI.
    W_COLOR = P_COLOR.
    T_SPFLI-COLOR = P_COLOR.
    IF P_COL IS INITIAL AND P_ROW GT 0.
    MODIFY T_SPFLI INDEX P_ROW TRANSPORTING COLOR.
    ENDIF.
    FS_FIELDCAT-FIELDNAME = 'CARRID'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 1.
    FS_FIELDCAT-KEY = 'X'.
    FS_FIELDCAT-HOTSPOT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT .
    FS_FIELDCAT-FIELDNAME = 'CONNID'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 2.
    FS_FIELDCAT-KEY = 'X'.
    FS_FIELDCAT-HOTSPOT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT .
    FS_FIELDCAT-FIELDNAME = 'DISTANCE'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 3.
    FS_FIELDCAT-KEY = ' '.
    FS_FIELDCAT-EDIT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT.
    FS_FIELDCAT-FIELDNAME = 'CITYFROM'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 4.
    FS_FIELDCAT-KEY = ' '.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    LOOP AT T_FIELDCAT INTO FS_FIELDCAT.
    IF FS_FIELDCAT-COL_POS EQ P_COL.
    FS_FIELDCAT-EMPHASIZE = P_COLOR.
    W_FIELDNAME = FS_FIELDCAT-FIELDNAME.
    IF P_ROW IS INITIAL AND P_COL GT 0.
    MODIFY T_FIELDCAT FROM FS_FIELDCAT TRANSPORTING EMPHASIZE.
    ENDIF.
    ENDIF.
    ENDLOOP.
    FS_CELL-FIELDNAME = W_FIELDNAME .
    FS_CELL-COLOR-COL = 6.
    FS_CELL-NOKEYCOL = 'X'.
    APPEND FS_CELL TO T_SPFLI-CELL.
    IF P_ROW IS NOT INITIAL AND P_COL IS NOT INITIAL.
    MODIFY T_SPFLI INDEX P_ROW TRANSPORTING CELL.
    ENDIF.
    FS_LAYOUT-INFO_FIELDNAME = 'COLOR'.
    FS_LAYOUT-BOX_FIELDNAME = 'CHECKBOX'.
    FS_LAYOUT-COLTAB_FIELDNAME = 'CELL'.
    FS_LAYOUT-F2CODE = '&ETA'.
    W_PROG = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = W_PROG
    IS_LAYOUT = FS_LAYOUT
    IT_FIELDCAT = T_FIELDCAT
    TABLES
    T_OUTTAB = T_SPFLI
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2

  • Display Color for sigle  CELL in ALV report

    Hi all,
    I have one doubt is it possible to make a particular cell as read color in ALV.
    Ex: I have one field which shows amount in my ALV report,My requirement is that when ever the amount is less then 'ZERO', I have to show that particular cell in read color.
    Regards
    Anil Kumar.N

    hi,
    here code for coloring a perticular cell
    TYPE-POOLS:slis.
    TABLES:mara,
           makt,
           marc.
    DATA:BEGIN OF itab OCCURS 0,
          matnr LIKE mara-matnr,
          maktx LIKE makt-maktx,
          werks LIKE marc-werks,
          mtart LIKE mara-mtart,
          matkl LIKE mara-matkl,
          meins LIKE mara-meins,
          ntgew LIKE mara-ntgew,
         rowcolor(4) TYPE c,
          cellcolors TYPE lvc_t_scol,
         END OF itab.
    DATA:t_fcat TYPE slis_t_fieldcat_alv,
         t_eve TYPE slis_t_event.
    DATA : st_layout TYPE slis_layout_alv.
    SELECTION-SCREEN:BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS:mat FOR mara-matnr.  " no intervals no-extension.
    *PARAMETERS:mat LIKE mara-matnr.
    SELECTION-SCREEN:END OF BLOCK blk1.
    INITIALIZATION.
      PERFORM build_cata USING t_fcat.
      PERFORM build_event.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM display_data.
    *&      Form  build_cata
          text
         -->TEMP_FCAT  text
    FORM build_cata USING temp_fcat TYPE slis_t_fieldcat_alv.
      sy-tvar0 = sy-uname.
      WRITE sy-datum TO sy-tvar1.
      DATA:wa_fcat TYPE slis_fieldcat_alv.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MATNR'.
      wa_fcat-seltext_m = 'Material'.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MAKTX'.
      wa_fcat-seltext_m = 'Description'.
      wa_fcat-fix_column = 'x'.
      wa_fcat-key = 'X'.                                     "To color a column
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'WERKS'.
      wa_fcat-seltext_m = 'Plant'.
      wa_fcat-key = ' '.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MTART'.
      wa_fcat-seltext_m = 'Type'.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MATKL'.
      wa_fcat-seltext_m = 'Group'.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MEINS'.
      wa_fcat-seltext_m = 'Measurement Unit'.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'NTGEW'.
      wa_fcat-seltext_m = 'Net Value'.
      APPEND wa_fcat TO temp_fcat.
    ENDFORM.                    "build_cata
    *&      Form  build_event
          text
    FORM build_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = t_eve
        EXCEPTIONS
          list_type_wrong = 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.
    ENDFORM.                    "build_event
    *&      Form  data_retrieval
          text
    FORM data_retrieval.
      SELECT maramatnr  maramtart maramatkl marameins mara~ntgew
       maktmaktx  marcwerks
      INTO CORRESPONDING FIELDS OF TABLE itab
      FROM mara INNER JOIN makt ON
      maramatnr = maktmatnr
      INNER JOIN marc ON
      maramatnr = marcmatnr
      WHERE mara~matnr IN mat.
      SORT itab BY matnr.
      DELETE ADJACENT DUPLICATES FROM itab.
    ENDFORM.                    "data_retrieval
    *&      Form  display_data
          text
    FORM display_data.
    *******************************For setting Cell Color*******************************************
      DATA ls_cellcolor TYPE lvc_s_scol .
      st_layout-coltab_fieldname = 'CELLCOLORS'.
      READ TABLE itab INDEX 5 .
      ls_cellcolor-fname = 'MATNR' .
      ls_cellcolor-color-col = '1' .
      ls_cellcolor-color-int = '1' .
      APPEND ls_cellcolor TO itab-cellcolors .
      MODIFY itab INDEX 5 .
    st_layout-colwidth_optimize = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = 'ZALV_DS'
          is_layout          = st_layout
          i_save             = 'A'
          it_fieldcat        = t_fcat
          it_events          = t_eve
        TABLES
          t_outtab           = itab
        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.
    ENDFORM.                    "display_data
    Please reward if useful...

  • Setting cell color in ALV

    Hi All
    I would be greatful if someone could please help...
    I am still attempting to get cells painted within a WDA ALV grid display.
    I have tried to use the method stated in the WDA sap press book - but this method is for use with TABLE element and I am using a ViewContainerUIElement for my table. There are mentions of wonderful ways to color cells in a list display - but I cannot understand how this can be achieved. I currently have this working appart from the numeric numbers of the design being set into the relavant column cell.
    If anyone could help that would be great...
    Please see: http://picasaweb.google.co.uk/dave.alexander69/Pictures#5244800978549492338
       LOOP AT lt_zdata INTO ls_zdata.
            lv_index = sy-tabix.
    *       set column values
    *       loop at row data and set colour attributes of individual cells
            LOOP AT lt_columns ASSIGNING <fs_column>.
              lr_col_header = <fs_column>-r_column->get_header( ).
              lr_col_header->set_ddic_binding_field( ).
              CREATE OBJECT lr_input_field EXPORTING value_fieldname = <fs_column>-id.
              lr_column = lr_column_settings->get_column( <fs_column>-id ).
    *         for the date columns only...
              IF <fs_column>-id(4) = 'CELL'.
    *           get and set column dates from select option user input
                READ TABLE lt_dates INTO ls_dates INDEX 1.
                IF lt_dates IS INITIAL.
                  lr_col_header->set_text( 'Date' ).
                ELSE.
                  ls_dates-low = ls_dates-low + lv_incr_date.
                  MOVE ls_dates-low+2(2) TO lv_for_col_date+6(2).   "Year
                  MOVE ls_dates-low+4(2) TO lv_for_col_date+3(2).   "Month
                  MOVE ls_dates-low+6(2) TO lv_for_col_date(2).     "Day
                  MOVE lv_for_col_date   TO lv_col_date.
                  lr_col_header->set_text( lv_col_date ).
                  lv_incr_date = lv_incr_date + 7.
                ENDIF.
                LOOP AT lt_orgdata_dates INTO ls_orgdata_dates
                  WHERE crew = ls_zdata-crew
                    AND position = ls_zdata-position
                    AND name = ls_zdata-person
                    AND trip_arr >= ls_dates-low
                    AND trip_dep <= ls_dates-low.
    *             column heading settings
                  lr_field = lr_table->if_salv_wd_field_settings~get_field( <fs_column>-id ).
                  lr_field->if_salv_wd_sort~set_sort_allowed( abap_false ).
    * trying to set cell variants ?@#??!!???
    *              lr_cv = lr_column->set_key( ls_zdata-variance ).
    *              lr_cv->set_editor( lr_input_field ).
    *              lr_cv->set_cell_design( value = '01').
    *              lr_column->add_cell_variant( lr_cv ).
    * current method of seeting the cell colors... (but puts value in cell!)
                  FIELD-SYMBOLS: <fs> TYPE data.
                  lr_column->set_cell_design_fieldname( value = <fs_column>-id ).
                  ASSIGN COMPONENT <fs_column>-id OF STRUCTURE ls_zdata TO <fs>.
                  WRITE: CL_WD_TABLE_COLUMN=>e_cell_design-one TO <fs>.
                  MODIFY lt_zdata FROM ls_zdata. " INDEX lv_index.
                ENDLOOP.
              ENDIF.
    Kind Regards
    Dave Alexander

    Hi check this code to set cell colors for ALV grid.
    Take a context attribute with type WDUI_TABLE_CELL_DESIGN.
    Here i am populating colors based on some condition.Check the loop of the internal table.
    method get_flight_details .
    data:node_flights type ref to if_wd_context_node,
         it_flights type sflight_tab1,
         ls_flights type sflight,
         it_final type   if_componentcontroller=>elements_flights,
         ls_final type   if_componentcontroller=>element_flights.
        select * from sflight into table it_flights
    up to 100 rows.
        node_flights = wd_context->get_child_node( 'FLIGHTS' ).
        loop at it_flights into ls_flights.
           move-corresponding ls_flights to ls_final.
           if ls_final-price = '185.00'.
              ls_final-readonly = abap_true.
              ls_final-celldesign =
    cl_wd_table_column=>e_cell_design-badvalue_light.
           else.
              ls_final-readonly = ' '.
              ls_final-celldesign =
    cl_wd_table_column=>e_cell_design-goodvalue_light.
           endif.
           append ls_final to it_final.
        endloop.
        node_flights->bind_table(
            new_items            = it_final
            set_initial_elements = abap_true
    *        INDEX                = INDEX
    data: l_ref_cmp_usage type ref to if_wd_component_usage.
    l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
    if l_ref_cmp_usage->has_active_component( ) is initial.
       l_ref_cmp_usage->create_component( ).
    endif.
    data: l_ref_interfacecontroller type ref to iwci_salv_wd_table .
    l_ref_interfacecontroller =   wd_this->wd_cpifc_alv( ).
       data:
         l_value type ref to cl_salv_wd_config_table.
       l_value = l_ref_interfacecontroller->get_model(
    * Make Price column editable
    data:l_column type ref to cl_salv_wd_column,
          l_column1 type ref to cl_salv_wd_column,
          lr_input type ref to cl_salv_wd_uie_input_field,
          l_input1 type ref to cl_salv_wd_uie_input_field.
    l_column = l_value->if_salv_wd_column_settings~get_column( 'PRICE' ).
    create object lr_input
      exporting
        value_fieldname = 'PRICE'
    l_column->set_cell_editor( value = lr_input ).
    * to make some cells non editable
    lr_input->set_read_only_fieldname( value = 'READONLY' ).
    l_value->if_salv_wd_column_settings~delete_column( id = 'READONLY'   )
    *Set the table Editable
    l_value->if_salv_wd_table_settings~set_read_only( value = abap_false ).
    *Give colors to cells
    l_column1 = l_value->if_salv_wd_column_settings~get_column( 'CARRID' ).
    l_column1->set_cell_design_fieldname( value = 'CELLDESIGN'  ).
    l_value->if_salv_wd_column_settings~delete_column( id = 'CELLDESIGN' )
    endmethod.
    Thanks
    Suman

  • Two colors in a cell ALV

    Hi All,
    I want to produce a report in ALV , where I have to print two diff colors in a cell..
    Eg:       In a cell  128(38)  
    128(    ) in black and 38 in red.
    Thanks in advance.
    Balamurugan.R

    hi,
    see the below example which may be useful.
    types:  begin of ty_vbak,
            Vbeln type vbeln_va,
            erdat type erdat,
            ernam type ernam,
    cellcolors type lvc_t_scol,  " table type for cell coloring
    cellstyles TYPE lvc_t_styl,  " table type for Style Table for Cells
            end of ty_vbak.
    data:  t_vbak type table of ty_vbak,
           w_vbak type ty_vbak.
    data: gt_fieldcat type lvc_t_fcat,
          gs_fieldcat like line of gt_fieldcat,
          gw_layout type lvc_s_layo.
    Reference to Custom container
    DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
           G_CONTAINER TYPE SCRFNAME VALUE  'CC_ALV',
        G_GRID TYPE REF TO CL_GUI_ALV_GRID,
    *&      Module  STATUS_0001  OUTPUT
          text
    MODULE STATUS_0001 OUTPUT.
    SET PF-STATUS 'xxxxxxxx'.
    SET TITLEBAR 'xxx'.
    CREATE OBJECT G_CUSTOM_CONTAINER
       EXPORTING
        PARENT                      =
         CONTAINER_NAME              = G_CONTAINER
        STYLE                       =
        LIFETIME                    = LIFETIME_DEFAULT
        REPID                       =
        DYNNR                       =
        NO_AUTODEF_PROGID_DYNNR     =
      EXCEPTIONS
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5
        OTHERS                      = 6
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
      CREATE OBJECT G_GRID
        EXPORTING
         I_SHELLSTYLE      = 0
         I_LIFETIME        =
          I_PARENT          =  G_CUSTOM_CONTAINER
         I_APPL_EVENTS     = SPACE
         I_PARENTDBG       =
         I_APPLOGPARENT    =
         I_GRAPHICSPARENT  =
         I_NAME            =
         I_FCAT_COMPLETE   = SPACE
       EXCEPTIONS
         ERROR_CNTL_CREATE = 1
         ERROR_CNTL_INIT   = 2
         ERROR_CNTL_LINK   = 3
         ERROR_DP_CREATE   = 4
         OTHERS            = 5
      IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    perform populate_data.
    perform fieldcat.
    perform populate_layout.
    perform display_output.
    ENDMODULE.                 " STATUS_0001  OUTPUT
    *&      Form  populate_data
          populating the data
    -->  p1        text
    <--  p2        text
    FORM populate_data .
      data: color(1) type c.
    DATA lw_cellcolor TYPE lvc_s_scol . "line type for cell coloring
    select  vbeln
            erdat
            ernam from vbak into CORRESPONDING FIELDS OF TABLE t_vbak up to 10 rows.
    *coloring the particular cell.
    READ TABLE t_vbak INTO w_vbak  INDEX 5 .
    lw_cellcolor-fname = 'ERDAT' .
    lw_cellcolor-color-col = '4' .
    lw_cellcolor-color-int = '1' .
    APPEND lw_cellcolor TO w_vbak-cellcolors .
    modify t_vbak index 5 from w_vbak.
    READ TABLE t_vbak INTO w_vbak  INDEX 7.
    lw_cellcolor-fname = 'ERNAM' .
    lw_cellcolor-color-col = '7' .
    lw_cellcolor-color-int = '1' .
    APPEND lw_cellcolor TO w_vbak-cellcolors .
    modify t_vbak index 7 from w_vbak.
    ENDFORM.                    " populate_data
    *&      Form  fieldcat
          populatin the fieldcat
    -->  p1        text
    <--  p2        text
    FORM fieldcat .
      clear gs_fieldcat.
      gs_fieldcat-fieldname = 'VBELN'.
      gs_fieldcat-tabname = 'T_VBAk'.
      gs_fieldcat-outputlen = '20'.
      gs_fieldcat-SCRTEXT_M = 'DOCUMENT NUMBER'.
      append gs_fieldcat to GT_fieldcat.
      clear gs_fieldcat.
      gs_fieldcat-fieldname = 'ERDAT'.
      gs_fieldcat-tabname = 'T_VBAK'.
      gs_fieldcat-outputlen = '20'.
      gs_fieldcat-SCRTEXT_M = 'CREATED ON'.
      append gs_fieldcat to GT_fieldcat.
      clear gs_fieldcat.
      gs_fieldcat-fieldname = 'ERNAM'.
      gs_fieldcat-tabname = 'T_VBAK'.
      gs_fieldcat-outputlen = '20'.
      gs_fieldcat-SCRTEXT_M = 'CREATED BY'.
      append gs_fieldcat to GT_fieldcat.
    ENDFORM.                    " fieldcat
    *&      Form  display_output
          text
    -->  p1        text
    <--  p2        text
    FORM display_output .
      CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
         I_BUFFER_ACTIVE               =
         I_BYPASSING_BUFFER            =
         I_CONSISTENCY_CHECK           =
         I_STRUCTURE_NAME              =
         IS_VARIANT                    =
         I_SAVE                        =
         I_DEFAULT                     = 'X'
        IS_LAYOUT                      = gw_layout
         IS_PRINT                      =
         IT_SPECIAL_GROUPS             =
       IT_TOOLBAR_EXCLUDING           = *      IT_HYPERLINK                  =
         IT_ALV_GRAPHICS               =
         IT_EXCEPT_QINFO               =
         IR_SALV_ADAPTER               =
        CHANGING
          IT_OUTTAB                      = t_vbak
          IT_FIELDCATALOG                = GT_fieldcat
         IT_SORT                       =
         IT_FILTER                     =
       EXCEPTIONS
         INVALID_PARAMETER_COMBINATION = 1
         PROGRAM_ERROR                 = 2
         TOO_MANY_LINES                = 3
         OTHERS                        = 4
      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  populate_layout
          populating the layout
         <--P_GW_LAYOUT   internal table for the layput
    FORM populate_layout."  CHANGING P_GW_LAYOUT type lvc_s_layo.
    gw_layout-zebra = 'X'.
    gw_layout-ctab_fname = 'CELLCOLORS'. "cell coloring
    *gw_layout-info_fname = 'ROW_COLOR'.    "row coloring
    gw_layout-stylefname = 'CELLSTYLES'.   "styles
    ENDFORM.                    " populate_layout
    thanks and regards

  • ALV color a particular cell on meeting certain condition

    hi all
         i am working with ALV , my requirement is to color a particular cell if condition mate.
    like .
       i have two fields in my ITAB  PlanedCost and ActualCost
    If ACTUALCOST is >= 80% of PLANEDCOST then
    ACTUALCOST cell must come in RED COLOR.
    how to do so .
    please guide me.

    Hi Rock,
            I tried a program to color a cell based on its value, but it is not working. Am pasting the code below and please can u exactly tell me what is the problem it.
    *& Report  ZSAPCOLV
    REPORT  zsapcolv.
    TABLES:mara.
    TYPES:BEGIN OF ty_mara,
          matnr TYPE mara-matnr,
          mtart TYPE mara-mtart,
          color1(4),
         END OF ty_mara.
    DATA:it_mara TYPE STANDARD TABLE OF ty_mara,
         it_color  TYPE TABLE  OF lvc_s_scol,
         wa_mara TYPE ty_mara,
         wa_color    TYPE lvc_s_scol,
         is_layout   TYPE lvc_s_layo.
    DATA: t_newtable TYPE REF TO data,
    t_newline  TYPE REF TO data.
    FIELD-SYMBOLS: <dyntab> TYPE STANDARD TABLE,
                   <wa_dyntab> TYPE ANY,
                   <gfs_wa> TYPE ANY.
    TYPES: BEGIN OF ty_cmara,
        matnr TYPE mara-matnr,
         mtart TYPE mara-mtart,
       tabcolor TYPE lvc_t_scol,
    END OF ty_cmara.   " Cell color
    DATA:it_cmara TYPE STANDARD TABLE OF ty_cmara.
    DATA:
          gr_table     TYPE REF TO cl_salv_table,
          gr_functions TYPE REF TO cl_salv_functions,
          gr_display   TYPE REF TO cl_salv_display_settings.
    DATA:   it_fcat TYPE lvc_t_fcat,
            wa_fcat TYPE lvc_s_fcat.
    DATA:it_fcat1 TYPE lvc_t_fcat, "with cell color
         it_fcat2 TYPE lvc_t_fcat,
    wa_fieldcat LIKE LINE OF it_fcat1,
    wa_cellcolors TYPE lvc_s_scol,
    wa_is_layout TYPE lvc_s_layo.
    FIELD-SYMBOLS:<t_cellcolors> TYPE lvc_t_scol,
    <w_field> TYPE ANY.
    DATA:t_line  TYPE REF TO data .
    *-----design selection screen for plant and material type.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-b01.
    SELECT-OPTIONS:
                     s_matnr     FOR mara-matnr.    "material type
    SELECTION-SCREEN END OF BLOCK b1.
    START-OF-SELECTION.
      PERFORM fetch_data.
      PERFORM display_data.
    *&      Form  fetch_data
    FORM fetch_data .
      DATA:wa_cmara TYPE ty_cmara.
      DATA: ls_tabcolor TYPE lvc_s_scol.
      SELECT
    FROM mara
        INTO CORRESPONDING FIELDS OF TABLE it_mara WHERE matnr IN s_matnr.
      CHECK sy-subrc EQ 0.
      PERFORM build_catalog USING '1' 'MATNR' 'Material number' 'Material Number' ' ' '18'.
      PERFORM build_catalog USING '1' 'MTART' 'Material type' 'Material type' ' ' '10'.
      it_fcat1[] = it_fcat[].
       wa_fieldcat-fieldname = 'T_CELLCOLORS'.
       wa_fieldcat-ref_field = 'COLTAB'.
       wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
      APPEND wa_fieldcat TO it_fcat.
      cl_alv_table_create=>create_dynamic_table( EXPORTING it_fieldcatalog = it_fcat
                                                  IMPORTING ep_table = t_newtable ).
      ASSIGN t_newtable->* TO <dyntab>.
      CREATE DATA t_line LIKE LINE OF <dyntab>.
      ASSIGN t_line->* TO <gfs_wa>.
      PERFORM fill_data.
    ENDFORM.                    " fetch_data
    *&      Form  build_catalog
    FORM build_catalog  USING    p_pos TYPE lvc_colpos
                           p_field TYPE lvc_fname
                           p_reptext TYPE reptext
                           p_coltext TYPE coltext
                           p_check TYPE lvc_checkb
                           p_len TYPE lvc_outlen.
      wa_fcat-col_pos    = p_pos.
      wa_fcat-fieldname  = p_field.
      wa_fcat-reptext    = p_reptext.
      wa_fcat-checkbox   = p_check.
      wa_fcat-outputlen  = p_len.
      wa_fcat-emphasize = '6'.
      IF p_check = 'X'.
        wa_fcat-edit = 'X'.
      ENDIF.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
    ENDFORM.                    " catalog
    *&      Form  fill_data
    FORM fill_data .
      FIELD-SYMBOLS: <wa_tmp> TYPE ANY,
                     <v_fld> TYPE ANY,
                     <color> TYPE ANY,
                     <wa_color> TYPE lvc_s_scol.
      DATA: v_fld(20).
      DATA : lv_cnt TYPE i,
             t_newline1  type ref to data,
             lv_cnt1 TYPE i.
        FIELD-SYMBOLS: <ta_color> TYPE lvc_t_scol.
         DATA : field(15) TYPE c,
             col TYPE lvc_s_scol.
      create data t_newline1 LIKE <wa_color>.
      LOOP AT it_mara INTO wa_mara.
        lv_cnt1 = lv_cnt1 + 1.
        LOOP AT it_fcat INTO wa_fcat.
          UNASSIGN <wa_tmp>.
          ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <wa_tmp>.
          CONCATENATE 'WA_MARA-' wa_fcat-fieldname INTO v_fld.
          ASSIGN (v_fld) TO <v_fld>.
          CHECK sy-subrc EQ 0.
          IF <v_fld> = '000000000000000004'.
             col-fname = wa_fcat-fieldname.
             col-color-col = '5' .
             col-color-int = '0' .
              "ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <ta_color>.
               ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <ta_color> .
               APPEND col TO <ta_color>.
            <wa_tmp> = <v_fld>.
            lv_cnt = lv_cnt + 1.
          ENDIF.
          IF lv_cnt = 1.
            APPEND <gfs_wa> TO <dyntab>.
          ELSE.
            MODIFY <dyntab> INDEX lv_cnt1 FROM <gfs_wa>.
          ENDIF.
        ENDLOOP.
        lv_cnt = 0.
        CLEAR wa_mara.
      ENDLOOP.
    ENDFORM.                    " fill_data
    *&      Form  display_data
    FORM display_data .
    IF <dyntab> IS NOT INITIAL.
       LOOP AT <dyntab> INTO <gfs_wa>.
         ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gfs_wa> TO <w_field>.
         ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <t_cellcolors> .
         CLEAR wa_cellcolors.
        "wa_cellcolors-fname = 'MATNR'.
         "IF <w_field> = '000000000000000004'.
           "FORMAT INTENSIFIED COLOR = 6.
           wa_cellcolors-fname = 'MATNR'.
           wa_cellcolors-color-col = '7'.
           wa_cellcolors-color-int = '1'.
           "wa_cellcolors-color-inv = '1'.
           "wa_cellcolors-NOKEYCOL = ''.
          "ELSE.
          "wa_cellcolors-color-col = '5'.
        "ENDIF.
         APPEND wa_cellcolors TO <t_cellcolors>.
         MODIFY <dyntab> FROM <gfs_wa>.
       ENDLOOP.
      cl_salv_table=>factory( IMPORTING r_salv_table = gr_table CHANGING t_table = <dyntab> ).
      gr_functions = gr_table->get_functions( ).
      gr_functions->set_all( abap_true ).
      gr_display = gr_table->get_display_settings( ).
      gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
      gr_display->set_list_header( 'MARA DATA' ).
      gr_table->display( ).
      "ENDIF.
    ENDFORM.                    " display_data

  • Alv cell color with FM

    hi ,
    can one send me program for alv cell color with help of function modules
    kiran

    Hi Kiran .
    <b>1.Cell Color.</b>
    While Building Fieldcatalog ,there is one field called
    EMPHASIZE.You have to set like this .
    i_field-emphasize = 'C26'.
    <b>2.ROW COLOR.</b>
    Have a look at this example .
    <b>a</b>.Define one variable COLOR in ur main ITAB.
    <b>b</b>.Fill it .
    <b>c</b>.Pass this info.
      w_layout-info_fieldname = 'COLOR'.
    <b>d</b>. display it .
    *& Report  ZGRID_COLOR                                                 *
    REPORT  zgrid_color                             .
    TYPE-POOLS slis.
    DATA: BEGIN OF i_pa0001 OCCURS 0,
    <b>        color(3) TYPE c,</b>
            pernr TYPE pa0001-pernr,
            subty TYPE pa0001-subty,
          END OF i_pa0001.
    DATA :i_field TYPE slis_t_fieldcat_alv,
          w_field LIKE LINE OF i_field,
          w_layout TYPE slis_layout_alv.
    START-OF-SELECTION .
      PERFORM get_data.
      PERFORM fieldcat.
      PERFORM layout_build.
      PERFORM dispaly .
    *&      Form  fieldcat
    FORM fieldcat .
      CLEAR :w_field,i_field[].
      w_field-fieldname = 'PERNR'.
      w_field-tabname   = 'I_PA0001'.
      w_field-seltext_m = 'PERNR'.
      APPEND w_field TO i_field.
      CLEAR w_field.
      w_field-fieldname = 'SUBTY'.
      w_field-tabname   = 'I_PA0001'.
      w_field-seltext_m = 'SUBTY'.
      APPEND w_field TO i_field.
      CLEAR w_field.
    ENDFORM.                    " fieldcat
    *&      Form  dispaly
    FORM dispaly .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
       i_callback_program                = 'ZGRID_COLOR'
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
    <b>   is_layout                         = w_layout</b>
       it_fieldcat                       = i_field
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      I_HTML_HEIGHT_TOP                 =
      I_HTML_HEIGHT_END                 =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
        TABLES
          t_outtab                          = i_pa0001
    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.
    ENDFORM.                    " dispaly
    *&      Form  get_data
    FORM get_data .
      SELECT pernr subty
      FROM pa0001
      INTO CORRESPONDING FIELDS OF TABLE i_pa0001
      UP TO 10 ROWS.
    LOOP AT i_pa0001.
        IF sy-tabix GT 5.
      <b>    i_pa0001-color = 'C51'.</b>
          MODIFY i_pa0001 INDEX sy-tabix.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " get_data
    *&      Form  layout_build
    FORM layout_build .
    <b>  w_layout-info_fieldname = 'COLOR'.</b>
    ENDFORM.                    " layout_build
    I hope it helps u .
    <b>Thanks,
    Venkat.O</b>

  • To change the subtotals row color in ALV(Grid / List ) .

    I am trying to change the color of a row which gives the subtotal...in ALV report...
    but it is not working....
    I have used the following code but not getting where i m wrong
    I have u sed the following code wih the help of our forum only...
    <CODE>
    TYPE-POOLS: SLIS.
    *& Internal Table Delcaration
    DATA : BEGIN OF IT_SCALE OCCURS 0,
             DATUM LIKE ZSCALE-DATUM,
             MCOD1 LIKE ZSCALE-MCOD1,
             MATNR LIKE ZSCALE-MATNR,
             MAKTG LIKE ZSCALE-MAKTG,
             MEINS LIKE ZSCALE-MEINS,
             RATE LIKE ZSCALE-RATE,
             TOTAL LIKE ZSCALE-TOTAL,
             LI_COLOR(4),
           END OF IT_SCALE.
    DATA : INDEX LIKE SY-TABIX.
    *& ALV Data Declaration
    DATA: IT_FIELDCAT  TYPE SLIS_T_FIELDCAT_ALV.
    DATA: WA_FIELDCAT  LIKE LINE OF IT_FIELDCAT.
    DATA : T_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
    DATA : IT_EVENTS   TYPE SLIS_T_EVENT WITH HEADER LINE.
    DATA : G_SAVE(1)   TYPE C VALUE 'A',
           GX_SAVE(1)  TYPE C VALUE 'A',
           GX_VARIANT  LIKE DISVARIANT,
           G_VARIANT   LIKE DISVARIANT,
           GS_LAYOUT   TYPE SLIS_LAYOUT_ALV,
           T_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
           T_I_EVENT      TYPE SLIS_ALV_EVENT.
    DATA : L_LIST(105)    TYPE C,         "Store the Top-of-page headings
           L_DATEFROM(10) TYPE C,         "Store date in top-of-page
           L_DATETO(10)   TYPE C.         "Store date in top-of-page
    <code>
    START-OF-SELECTION.
      PERFORM GET_DATA.
      PERFORM ALV_FIELDCAT.
      PERFORM GET_EVENTS.
      PERFORM SUB_COMMENT_BUILD USING T_LIST_TOP_OF_PAGE.
      PERFORM ALV_DISPLAY.
    FORM GET_DATA .
    DATA : LINE_COLOR.
      SELECT DATUM MCOD1 MATNR MAKTG MEINS RATE TOTAL
             FROM ZSCALE INTO CORRESPONDING FIELDS OF TABLE IT_SCALE
             WHERE DATUM IN S_DATE
               AND LIFNR IN S_LIFNR
               AND MATNR IN S_MATNR.
    loop at IT_SCALE.
      LINE_color = LINE_color + 2.
      if LINE_color < 7.
        LINE_color = 1.
      endif.
      concatenate 'C' lINE_color '00' into IT_SCALE-li_color.
      modify it_SCALE TRANSPORTING LI_COLOR.
    endloop.
    FORM ALV_FIELDCAT.
      DATA: COUNTER      TYPE I.
      COUNTER = COUNTER + 1.
      WA_FIELDCAT-COL_POS    = COUNTER.
      WA_FIELDCAT-FIELDNAME  = 'DATUM'.
      WA_FIELDCAT-TABNAME    = 'IT_SCALE'.
      WA_FIELDCAT-SELTEXT_L  = 'Date'.
      WA_FIELDCAT-JUST       = 'C'.
      WA_FIELDCAT-NO_ZERO    = 'X'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR WA_FIELDCAT.
    .endform.
    FORM ALV_DISPLAY .
    GS_LAYOUT-ZEBRA        = 'X'.
      GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
      GS_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.
    gS_layout-no_input          = 'X'.
      gS_layout-totals_text       = 'Totals'(201).
      gS_layout-subtotals_text = 'Subtotal'.
      IF IT_SCALE[] IS INITIAL.
        MESSAGE I001(38) WITH 'No Data to Display'.
      ELSE.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM             = SY-REPID
       IS_LAYOUT                      = GS_LAYOUT
      IT_FIELDCAT                    = IT_FIELDCAT
       I_SAVE                         = G_SAVE
       IS_VARIANT                     = GX_VARIANT
      TABLES
        T_OUTTAB                       = IT_SCALE[].
      ENDIF.
    ENDFORM.                    " ALV_DISPLAY
    ThanX in Adavance....

    Hi Prasad,
    I provided some code snippets for you. Please go through.
    Hope this proves to be helpful to you.
    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.
    Heres another Example for you:
        & Report  Z_ALV_COLOURS                                              &
        & This report shows how to use colours in REUSE_ALV_GRID_DISPLAY     &
        & C = Colour        (all codes must start with 'C')                  &
        & X = Colour number (1-9)                                            &
        & Y = Intensified   (0 = off, 1 = on)                                &
        & Z = Inverse       (0 = off, 1 = on)                                &
        report  z_alv_colours.
        data count_1(1) type c.
    ALV definitions
        type-pools: slis.
        data i_fieldcat type slis_t_fieldcat_alv with header line.
        data i_layout   type slis_layout_alv.
        types: begin of t_alv,
              f1(4) type c,
              f2(15) type c,
              f3(4) type c,
              f4(4) type c,
              f5(4) type c,
              f6(4) type c,
              colour(4)   type c,
              coltab type slis_t_specialcol_alv,
        end of t_alv.
        data: i_alv type standard table of t_alv with header line.
        data l_alvcolor type slis_specialcol_alv.
        & create table entries for LINE colours                              &
        do 9 times.
          count_1 = sy-index.
          clear i_alv.
          concatenate 'C' count_1 '0' '0' into i_alv-f1.
          concatenate 'C' count_1 '0' '0' into i_alv-colour.
          i_alv-f2 = 'Line colour'.
          i_alv-f3 = 'X'.
          append i_alv.
    Intensified
          clear i_alv.
          concatenate 'C' count_1 '1' '0' into i_alv-f1.
          concatenate 'C' count_1 '1' '0' into i_alv-colour.
          i_alv-f2 = 'Line colour'.
          i_alv-f4 = 'X'.
          append i_alv.
    Inverse
          clear i_alv.
          concatenate 'C' count_1 '0' '1' into i_alv-f1.
          concatenate 'C' count_1 '0' '1' into i_alv-colour.
          i_alv-f2 = 'Line colour'.
          i_alv-f5 = 'X'.
          append i_alv.
    Intensified & Inverse
          clear i_alv.
          concatenate 'C' count_1 '1' '1' into i_alv-f1.
          concatenate 'C' count_1 '1' '1' into i_alv-colour.
          i_alv-f2 = 'Line colour'.
          i_alv-f6 = 'X'.
          append i_alv.
        enddo.
    create table entries for CELL colours
        do 9 times.
          count_1 = sy-index.
          concatenate 'C' count_1 '0' '0' into i_alv-f1.
          i_alv-f2 = 'Cell colour'.
          concatenate 'C' count_1 '0' '0' into i_alv-f3.
          concatenate 'C' count_1 '1' '0' into i_alv-f4.
          concatenate 'C' count_1 '0' '1' into i_alv-f5.
          concatenate 'C' count_1 '1' '1' into i_alv-f6.
          append i_alv.
        enddo.
        & Create table entries for CELL colours                              &
        loop at i_alv where f2 = 'Cell colour'.
    Colour cells
          clear l_alvcolor.
          l_alvcolor-fieldname = 'F3'.
          l_alvcolor-color-col = i_alv-f3+1(1).
          l_alvcolor-color-int = i_alv-f3+2(1).
          l_alvcolor-color-inv = i_alv-f3+3(1).
          l_alvcolor-nokeycol = 'X'.
          append l_alvcolor to i_alv-coltab.
          clear l_alvcolor.
          l_alvcolor-fieldname = 'F4'.
          l_alvcolor-color-col = i_alv-f4+1(1).
          l_alvcolor-color-int = i_alv-f4+2(1).
          l_alvcolor-color-inv = i_alv-f4+3(1).
          l_alvcolor-nokeycol = 'X'.
          append l_alvcolor to i_alv-coltab.
          clear l_alvcolor.
          l_alvcolor-fieldname = 'F5'.
          l_alvcolor-color-col = i_alv-f5+1(1).
          l_alvcolor-color-int = i_alv-f5+2(1).
          l_alvcolor-color-inv = i_alv-f5+3(1).
          l_alvcolor-nokeycol = 'X'.
          append l_alvcolor to i_alv-coltab.
          clear l_alvcolor.
          l_alvcolor-fieldname = 'F6'.
          l_alvcolor-color-col = i_alv-f6+1(1).
          l_alvcolor-color-int = i_alv-f6+2(1).
          l_alvcolor-color-inv = i_alv-f6+3(1).
          l_alvcolor-nokeycol = 'X'.
          append l_alvcolor to i_alv-coltab.
          modify i_alv.
        endloop.
        & Configure ALV settings                                             &
    Create field catalog
        perform create_field_catalog using 'F1'     'T_ALV' 'Colour name'.
        perform create_field_catalog using 'F2'     'T_ALV' 'Description'.
        perform create_field_catalog using 'F3'     'T_ALV' 'BaseColour'.
        perform create_field_catalog using 'F4'     'T_ALV' 'Intensified'.
        perform create_field_catalog using 'F5'     'T_ALV' 'Inverse'.
        perform create_field_catalog using 'F6'     'T_ALV' 'Both Inv/Int'.
        perform create_field_catalog using 'COLOUR' 'T_ALV' 'Colour'.
    Layout
        clear i_layout.
        i_layout-colwidth_optimize   = 'X'.
        i_layout-info_fieldname      = 'COLOUR'.   " for line colour
        i_layout-coltab_fieldname    = 'COLTAB'.   " for cell colour
        call function 'REUSE_ALV_GRID_DISPLAY'
          exporting
            i_callback_program      = sy-cprog
            i_callback_user_command = 'USER_COMMAND'
            is_layout               = i_layout
            it_fieldcat             = i_fieldcat[]
            i_default               = 'X'
            i_save                  = 'A'
          tables
            t_outtab                = i_alv.
        & Form  CREATE_FIELD_CATALOG                                          &
        form create_field_catalog using    p_fieldname
                                           p_tabname
                                           p_text.
          i_fieldcat-fieldname        = p_fieldname.
          i_fieldcat-tabname          = p_tabname.
          i_fieldcat-seltext_l        = p_text.
          append i_fieldcat.
        endform.                    " CREATE_FIELD_CATALOG
    For more information about Coloring in ALV, Please refer :
    Coloring Rows in ALV
    Hope this helps you in solving your issue.
    Please Reward Points if any of the above points are helpful to you.
    Regards,
    Kalyan Chakravarthy

  • How to download background color of ALV with button "Export to Excel"

    Dear Experts:
    I can download the data of ALV in webdynpro for ABAP, but the color is missing.
    Does anybody know how to download background color of the ALV cells also by "Export to Excel" button?
    Could anybody help on this?
    Thanks in advance!
    Best Regards
    Lingxing Meng

    never experienced that...
    [chk this link|Download colored ALV output in to EXCEL sheet;
    a couple of intersting posts, they talk abt general ALV...
    try one of the last post ...when downloading
    use local file->HTML only.. but while choosing the file location to save give extension as XLS.

  • Colors in ALV

    Hi How can i add colors in alv.
    Can you pls give a good example for this.
    thank you,
    Deepak

    HI,
    i am sending you a complete woking code ..you just run it and see the option in the output screen..select any of the check box and hit F8..and there it is.. you can modify the code to meet yur need
    Reward point if it satisfy your needs..
    REPORT ZOBJK1 .
    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
              color_cell    type lvc_t_scol,  " Cell 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_column as checkbox,
                 p_line   as checkbox,
                 p_cell   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                       = 40
        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.
    Field that identify cell color in inetrnal table
      move 'COLOR_CELL' to is_layout-ctab_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.
      select * from mara up to 5 rows.
        clear : wa_mara-color_line, wa_mara-color_cell.
        move-corresponding mara to wa_mara.
        add 1                   to wa_mara-counter.
        move 'Blabla'           to wa_mara-free_text.
        if wa_mara-counter = '0002'
        and p_line = 'X'.
    Color line
          move 'C410' to wa_mara-color_line.
        elseif wa_mara-counter = '0004'
        and p_cell = 'X'.
    Color cell
          move 'FREE_TEXT' to wa_color-fname.
          move '6'         to wa_color-color-col.
          move '1'         to wa_color-color-int.
          move '1'         to wa_color-color-inv.
          append wa_color to it_color.
          wa_mara-color_cell[] = it_color[].
        endif.
        append wa_mara to it_mara.
      endselect.
    endform.
    *&      Form  fill_catalog
    form fill_catalog.
    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                                                   *
      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.
    Color column
      if p_column = 'X'.
        move 'C610'     to wa_fieldcat-emphasize.
      endif.
      append wa_fieldcat to it_fieldcat.
      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.

  • Colors in ALV report - column wise

    Hi,
    I have a ALV report. I want color in my report like Column Wise.
    ex.
    Document No........Date.........Amount......Document No......Date........Amount........Document Nov........Date.............Amount....
    2008000123...10.07.2009....2000.00......2008000133....10.07.2009....2000.00.....2008000143.......10.07.2009.......2000.00
    2008000124...10.07.2009....2000.00......2008000134....10.07.2009....2000.00.....2008000144.......10.07.2009.......2000.00
    2008000125...10.07.2009....2000.00......2008000135....10.07.2009....2000.00.....2008000145.......10.07.2009.......2000.00
    Please see, there is 3 times Document No, Date and Amount. I want that there should come diff. colors for diff. document numbers.
    It is possible or not. If yes, then how...
    Thanks...

    Hi,
    go though this link....
    i hope this will help u
    TABLES:
    SPFLI.
    TYPE-POOLS:
    SLIS.
    PARAMETERS:
    P_COL TYPE I ,
    P_ROW TYPE I,
    P_COLOR(4) TYPE C .
    DATA:
    T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
    FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,
    W_COLOR(4) ,
    W_ROW TYPE I,
    W_FIELDNAME(20),
    W_PROG TYPE SY-REPID.
    DATA:
    BEGIN OF T_SPFLI OCCURS 0,
    COLOR(4),
    CHECKBOX ,
    CELL TYPE SLIS_T_SPECIALCOL_ALV,
    CARRID TYPE SPFLI-CARRID,
    CONNID TYPE SPFLI-CONNID,
    CITYFROM TYPE SPFLI-CITYFROM,
    CITYTO TYPE SPFLI-CITYTO,
    DISTANCE TYPE SPFLI-DISTANCE,
    END OF T_SPFLI.
    DATA:
    FS_CELL LIKE LINE OF T_SPFLI-CELL.
    SELECT *
    FROM SPFLI
    INTO CORRESPONDING FIELDS OF TABLE T_SPFLI.
    W_COLOR = P_COLOR.
    T_SPFLI-COLOR = P_COLOR.
    IF P_COL IS INITIAL AND P_ROW GT 0.
    MODIFY T_SPFLI INDEX P_ROW TRANSPORTING COLOR.
    ENDIF.
    FS_FIELDCAT-FIELDNAME = 'CARRID'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 1.
    FS_FIELDCAT-KEY = 'X'.
    FS_FIELDCAT-HOTSPOT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT .
    FS_FIELDCAT-FIELDNAME = 'CONNID'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 2.
    FS_FIELDCAT-KEY = 'X'.
    FS_FIELDCAT-HOTSPOT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT .
    FS_FIELDCAT-FIELDNAME = 'DISTANCE'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 3.
    FS_FIELDCAT-KEY = ' '.
    FS_FIELDCAT-EDIT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT.
    FS_FIELDCAT-FIELDNAME = 'CITYFROM'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 4.
    FS_FIELDCAT-KEY = ' '.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    LOOP AT T_FIELDCAT INTO FS_FIELDCAT.
    IF FS_FIELDCAT-COL_POS EQ P_COL.
    FS_FIELDCAT-EMPHASIZE = P_COLOR.
    W_FIELDNAME = FS_FIELDCAT-FIELDNAME.
    IF P_ROW IS INITIAL AND P_COL GT 0.
    MODIFY T_FIELDCAT FROM FS_FIELDCAT TRANSPORTING EMPHASIZE.
    ENDIF.
    ENDIF.
    ENDLOOP.
    FS_CELL-FIELDNAME = W_FIELDNAME .
    FS_CELL-COLOR-COL = 6.
    FS_CELL-NOKEYCOL = 'X'.
    APPEND FS_CELL TO T_SPFLI-CELL.
    IF P_ROW IS NOT INITIAL AND P_COL IS NOT INITIAL.
    MODIFY T_SPFLI INDEX P_ROW TRANSPORTING CELL.
    ENDIF.
    FS_LAYOUT-INFO_FIELDNAME = 'COLOR'.
    FS_LAYOUT-BOX_FIELDNAME = 'CHECKBOX'.
    FS_LAYOUT-COLTAB_FIELDNAME = 'CELL'.
    FS_LAYOUT-F2CODE = '&ETA'.
    W_PROG = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = W_PROG
    IS_LAYOUT = FS_LAYOUT
    IT_FIELDCAT = T_FIELDCAT
    TABLES
    T_OUTTAB = T_SPFLI
    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.
    NOTE
    Column and Row are colored with a coded color u2018Cxyzu2019.
        Where C: Color (coding must begin with C)
                     X: Color Number
                     Y: Bold
                     Z: Inverse.
    Thanks
    Ashu

  • Change color in alv column

    how do change color of a column in ALV.

    Hi
    The below abap program shows how to change the colour of individual ALV cells /fields. Only a small number of changes are required from a basic ALV grid which include adding a new field to ALV data declaration table(it_ekko), populating this field with the field name identifier and colour attributes and finally adding an entry to layout control work area. These changes are highlighted in bold below.
    REPORT  zdemo_alvgrid                 .
    REPORT  ZALV_CELLCOLOR.
    TABLES:     ekko.
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
      CELLCOLOR TYPE LVC_T_SCOL,
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid,
          gt_events     type slis_t_event,
          gd_prntparams type slis_print_alv.
    *Start-of-selection.
    START-OF-SELECTION.
      perform data_retrieval.
      perform build_fieldcatalog.
      perform build_layout.
      perform set_cell_colours.
      perform display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    form build_fieldcatalog.
    There are a number of ways to create a fieldcat.
    For the purpose of this example i will build the fieldcatalog manualy
    by populating the internal table fields individually and then
    appending the rows. This method can be the most time consuming but can
    also allow you  more control of the final product.
    Beware though, you need to ensure that all fields required are
    populated. When using some of functionality available via ALV, such as
    total. You may need to provide more information than if you were
    simply displaying the result
                  I.e. Field type may be required in-order for
                       the 'TOTAL' function to work.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    fieldcatalog-do_sum      = 'X'.
    fieldcatalog-no_zero     = 'X'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
      fieldcatalog-col_pos     = 5.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.
      fieldcatalog-datatype     = 'CURR'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    endform.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    form build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
      gd_LAYOUT-coltab_fieldname = 'CELLCOLOR'.  "CTAB_FNAME
    endform.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
          Display report using ALV grid
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
                i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
               i_callback_user_command = 'USER_COMMAND'
               i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tabgroup
              it_events               = gt_events
              is_print                = gd_prntparams
                i_save                  = 'X'
               is_variant              = z_template
           tables
                t_outtab                = it_ekko
           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.
    endform.                    " DISPLAY_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    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_ekko.
    endform.                    " DATA_RETRIEVAL
    Form  TOP-OF-PAGE                                                 *
    ALV Report Header                                                 *
    Form top-of-page.
    *ALV Header declarations
      data: t_header type slis_t_listheader,
            wa_header type slis_listheader,
            t_line like wa_header-info,
            ld_lines type i,
            ld_linesc(10) type c.
    Title
      wa_header-typ  = 'H'.
      wa_header-info = 'EKKO Table Report'.
      append wa_header to t_header.
      clear wa_header.
    Date
      wa_header-typ  = 'S'.
      wa_header-key = 'Date: '.
      CONCATENATE  sy-datum+6(2) '.'
                   sy-datum+4(2) '.'
                   sy-datum(4) INTO wa_header-info.   "todays date
      append wa_header to t_header.
      clear: wa_header.
    Total No. of Records Selected
      describe table it_ekko lines ld_lines.
      ld_linesc = ld_lines.
      concatenate 'Total No. of Records Selected: ' ld_linesc
                        into t_line separated by space.
      wa_header-typ  = 'A'.
      wa_header-info = t_line.
      append wa_header to t_header.
      clear: wa_header, t_line.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = t_header.
               i_logo             = 'Z_LOGO'.
    endform.                    "top-of-page
    *&      Form  SET_CELL_COLOURS
          Set colour of individual ALV cell, field
    FORM SET_CELL_COLOURS .
      DATA: WA_CELLCOLOR TYPE LVC_S_SCOL.
      DATA: ld_index TYPE SY-TABIX.
      LOOP AT IT_EKKO into wa_ekko.
        LD_INDEX = SY-TABIX.
      Set colour of EBELN field to various colors based on sy-tabix value
        WA_CELLCOLOR-FNAME = 'EBELN'.
        WA_CELLCOLOR-COLOR-COL = sy-tabix.  "color code 1-7, if outside rage defaults to 7
        WA_CELLCOLOR-COLOR-INT = '1'.  "1 = Intensified on, 0 = Intensified off
        WA_CELLCOLOR-COLOR-INV = '0'.  "1 = text colour, 0 = background colour
        APPEND WA_CELLCOLOR TO wa_ekko-CELLCOLOR.
        MODIFY it_ekko from wa_ekko INDEX ld_index TRANSPORTING CELLCOLOR.
      Set colour of NETPR field to color 4 if gt 0
        if wa_ekko-netpr gt 0.
          WA_CELLCOLOR-FNAME = 'NETPR'.
          WA_CELLCOLOR-COLOR-COL = 4.  "color code 1-7, if outside rage defaults to 7
          WA_CELLCOLOR-COLOR-INT = '0'.  "1 = Intensified on, 0 = Intensified off
          WA_CELLCOLOR-COLOR-INV = '0'.  "1 = text colour, 0 = background colour
          APPEND WA_CELLCOLOR TO wa_ekko-CELLCOLOR.
          MODIFY it_ekko from wa_ekko INDEX ld_index TRANSPORTING CELLCOLOR.
        endif.
      Set colour of AEDAT field text to red(6)
        WA_CELLCOLOR-FNAME = 'AEDAT'.
        WA_CELLCOLOR-COLOR-COL = 6.  "color code 1-7, if outside rage defaults to 7
        WA_CELLCOLOR-COLOR-INT = '0'.  "1 = Intensified on, 0 = Intensified off
        WA_CELLCOLOR-COLOR-INV = '1'.  "1 = text colour, 0 = background colour
        APPEND WA_CELLCOLOR TO wa_ekko-CELLCOLOR.
        MODIFY it_ekko from wa_ekko INDEX ld_index TRANSPORTING CELLCOLOR.
      ENDLOOP.
    ENDFORM.                    " SET_CELL_COLOURS

Maybe you are looking for

  • OOP's ABAP

    Hi, I want to know under which scenario Singleton concept has to be implemented?

  • Wrap off in sql

    Hi, I am running a sql to get the DDL of sequences, spooling it into a file but the lines are wraping, any suggestion how to make it in separate lines ? Also I would like to put a "/" between each DDL statement. here is how the output looks like CREA

  • Query Builder - Reference

    Hi, I am new to Query Builder.  I have to find out all the reports thats using a particular Universe.  I cannot do it manually.  Please let me know the reference for query builder tool.  I am unable to find anything in help.sap.com/product guides Tha

  • (Internationalization) in Javascript Messages......

    Hello does anyone have any idea how to show Chinese/Japanese/French/German characters in the alert messages of javascript ? My web pages are able to show all these languages, but would like to know how to do the same for javascript alert messages. I

  • M/c will not recognise printer installation cd

    Having problems with a friends newish mac.  It will not recognise cd's (not sure if that is all cd's). I am trying to install a new printer but m/c will not recognise installation disc.