Coloring a Particular Cell
Hi,
Please find below the sample program in which tried to color a particular cell. But it is not applying the color. Please help me to resolve this issues.
Thanks in Advance,
Sunil Kumar
*& Report ZSAPCOLV
REPORT ZSAPCOLV.
TABLES:mara.
TYPES:BEGIN OF ty_mara,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
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.
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.
DATA: v_fld(20).
DATA : lv_cnt TYPE i,
lv_cnt1 TYPE i.
DATA:wa_cmara TYPE ty_cmara.
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.
<wa_tmp> = <v_fld>.
lv_cnt = lv_cnt + 1.
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> = '000000000100000012'.
wa_cellcolors-color-col = '6'.
wa_cellcolors-color-int = '1'.
wa_cellcolors-color-inv = '1'.
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
Hi Sunil,
Coloring a cell is pretty simple.
1.
FORMAT COLOR 3 INTENSIFIED ON.
WRITE:/15 FS_TABLE-FIELD1.
FORMAT COLOR OFF.
Color 3 which is Yellow, begins from 0 to last letter of FIELD1.
To color up the entire row, you can mention
FORMAT COLOR 3 INTENSIFIED ON.
WRITE:/15(255) FS_TABLE-FIELD1.
FORMAT COLOR OFF.
2. Coloring a cell, carries a bit different method
LOOP..
WRITE:/ FS_TABLE-FIELD1 COLOR 3,
FS_TABLE-FIELD2-COLOR4.
ENDLOOP.
Hope this really helps you,
Courtesy: Zahackson
Edited by: Zahackson on Feb 6, 2009 10:25 AM
Similar Messages
-
Coloring of Particular Cells in a dynamic internal table(field symbols)
Hi,
I have a requirement to introduce color into some particular cells in a dynamic internal table(Field symbol) based on some conditions.I know that color can be introduced at cell level in the case of static internal table.But, can anybody tell me whether it is possible to introduce color to particular cells in the dynamic internal table(Field Symbol) .Please suggest me on this issue.
Thanks in advance,
RajeshHi,
This is the sample coding for the colour cell report.
Kindly go through it. It will helps u.
REPORT YMS_COLOURTEST .
DATA: BEGIN OF TP OCCURS 10, ID, NR(8), TEXT(255), END OF TP.
DATA: LENGTH TYPE I VALUE 8, " Length of list
TESTSTRING(15) TYPE C VALUE '012345678901234',
WIDTH TYPE I. " Width of list
DATA: TXT_REPORT LIKE DOKHL-OBJECT.
START-OF-SELECTION.
PERFORM HEADING.
PERFORM OUTPUT_BODY.
FORM HEADING.
FORMAT INTENSIFIED OFF. " Remove any INTENSIFIED
ULINE AT (WIDTH). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED." Title color
WRITE: / SY-VLINE. " Left border
WRITE: 'No |Colour |intensified |intensified off|',
'inverse' NO-GAP.
WRITE: AT WIDTH SY-VLINE. " Right border
ULINE AT (WIDTH). " Line below titles
FORMAT COLOR OFF.
ENDFORM.
FORM OUTPUT_BODY.
DO LENGTH TIMES.
PERFORM WRITE_LINE USING SY-INDEX.
ENDDO.
ENDFORM.
FORM WRITE_LINE USING COUNT TYPE I.
DATA: HELP(14) TYPE C,
COUNT1 TYPE I.
COUNT1 = SY-INDEX - 1.
WRITE: / SY-VLINE NO-GAP.
WRITE: (4) COUNT1 COLOR COL_KEY INTENSIFIED NO-GAP.
WRITE: SY-VLINE NO-GAP.
CASE COUNT1.
WHEN '0'.
HELP = 'COL_BACKGROUND'.
WHEN '1'.
HELP = 'COL_HEADING'.
WHEN '2'.
HELP = 'COL_NORMAL'.
WHEN '3'.
HELP = 'COL_TOTAL'.
WHEN '4'.
HELP = 'COL_KEY'.
WHEN '5'.
HELP = 'COL_POSITIVE'.
WHEN '6'.
HELP = 'COL_NEGATIVE'.
WHEN '7'.
HELP = 'COL_GROUP'.
ENDCASE.
WRITE: HELP COLOR COL_KEY INTENSIFIED NO-GAP.
WRITE: SY-VLINE NO-GAP.
WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED NO-GAP.
WRITE: SY-VLINE NO-GAP.
WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED OFF NO-GAP.
WRITE: SY-VLINE NO-GAP.
WRITE: TESTSTRING COLOR = COUNT1 INVERSE NO-GAP.
WRITE AT WIDTH SY-VLINE NO-GAP.
ENDFORM.
Thanks,
Shankar -
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 -
Hi Techies
I have one req in which i need to color the Particular cell, Provide me the Logic for that in which only change filed should be highlight to a specific Color.
I have alogic for color the whole column and Row, but i need to color only particular cell.
Moderator message: vague, help not possible without asking return questions, what cells are we talking about, provide as much technical detail as possible when posting.
Edited by: Thomas Zloch on Feb 15, 2012Thanks Edward for ur reply...
But in Inventory In warehouse report they gave the total as in different color.How they done that?????
Regards,
Anitha -
How to color a particular cell in ALV.
hi,
I have a requirement where i need to select a particular cell of a column in ALV and upon selection , i need to change the color of the selected cell. I choose the color from the dropdown toolbar created by me.
plz help, thanks.REPORT ZTEST_DHR.
TYPE-POOLS : SLIS.
TYPES: BEGIN OF TY_MARA,
FLAG TYPE CHAR1,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
WESCH TYPE MARA-WESCH,
STYLE TYPE LVC_T_STYL,
CELLCOLR TYPE LVC_T_SCOL,
END OF TY_MARA.
DATA : IT_MARA TYPE STANDARD TABLE OF TY_MARA.
DATA : IT_MARA1 TYPE STANDARD TABLE OF TY_MARA,
WA_MARA TYPE TY_MARA,
WA_MARA1 TYPE TY_MARA.
* for reuse alv grid display
*DATA : IT_FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV,
* WA_FIELDCATALOG TYPE SLIS_FIELDCAT_ALV,
* WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
* GV_REPID TYPE SY-REPID.
*for LVC Display
DATA : WA_SETTINGS TYPE LVC_S_GLAY.
DATA : WA_LAYOUT TYPE LVC_S_LAYO.
DATA : IT_FIELDCATALOG TYPE LVC_T_FCAT,
WA_FIELDCATALOG TYPE LVC_S_FCAT.
DATA REF1 TYPE REF TO CL_GUI_ALV_GRID.
DATA: LS_EDIT TYPE LVC_S_STYL,
LT_EDIT TYPE LVC_T_STYL.
DATA : LS_CELL_COLOR TYPE LVC_S_SCOL.
DATA : LT_CELL_COLOR TYPE LVC_T_SCOL.
START-OF-SELECTION.
SELECT MATNR ERSDA ERNAM WESCH
FROM MARA INTO CORRESPONDING FIELDS OF TABLE IT_MARA
UP TO 10 ROWS.
END-OF-SELECTION.
PERFORM BUILD_FIELDCATALOG.
PERFORM BUILD_LAYOUT.
PERFORM DISPLAY_ALV_REPORT.
*& Form BUILD_FIELDCATALOG
* text
FORM BUILD_FIELDCATALOG .
WA_FIELDCATALOG-FIELDNAME = 'FLAG'.
WA_FIELDCATALOG-OUTPUTLEN = 6.
WA_FIELDCATALOG-CHECKBOX = 'X'. "as checkbox
WA_FIELDCATALOG-EDIT = 'X'.
WA_FIELDCATALOG-SELTEXT = 'Check box'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME = 'MATNR'.
WA_FIELDCATALOG-OUTPUTLEN = 20.
WA_FIELDCATALOG-SELTEXT = 'Mat no'.
* wa_fieldcatalog-input = 'X'.
wa_fieldcatalog-edit = 'X'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME = 'ERSDA'.
WA_FIELDCATALOG-OUTPUTLEN = 15.
WA_FIELDCATALOG-SELTEXT = 'Creation Date'.
* wa_fieldcatalog-input = 'X'.
* wa_fieldcatalog-edit = 'X'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME = 'ERNAM'.
WA_FIELDCATALOG-OUTPUTLEN = 20.
WA_FIELDCATALOG-SELTEXT = 'Creation Time'.
* wa_fieldcatalog-input = 'X'.
* wa_fieldcatalog-edit = 'X'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME = 'WESCH'.
WA_FIELDCATALOG-OUTPUTLEN = 20.
WA_FIELDCATALOG-SELTEXT = 'Quantity'.
* wa_fieldcatalog-input = 'X'.
* wa_fieldcatalog-edit = 'X'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
ENDFORM. "build_fieldcatalog
*& Form BUILD_LAYOUT
* text
FORM BUILD_LAYOUT .
CONSTANTS : LC_X TYPE CHAR1 VALUE 'X'.
* WA_LAYOUT-NO_INPUT = LC_X.
WA_LAYOUT-CWIDTH_OPT = LC_X.
WA_LAYOUT-ZEBRA = LC_X.
WA_LAYOUT-STYLEFNAME = 'STYLE'.
WA_LAYOUT-CTAB_FNAME = 'CELLCOLR'.
ENDFORM. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
* text
FORM DISPLAY_ALV_REPORT .
LS_EDIT-FIELDNAME = 'FLAG'.
LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
INSERT LS_EDIT INTO TABLE LT_EDIT.
INSERT LINES OF LT_EDIT INTO TABLE WA_MARA1-STYLE.
LS_CELL_COLOR-FNAME = 'MATNR'.
LS_CELL_COLOR-COLOR-COL = '7'.
LS_CELL_COLOR-COLOR-INT = '1'.
INSERT LS_CELL_COLOR into table LT_CELL_COLOR.
INSERT LINES OF LT_CELL_COLOR into TABLE WA_MARA1-CELLCOLR.
LOOP AT IT_MARA INTO WA_MARA.
IF WA_MARA-ERSDA EQ '20080625'.
MODIFY IT_MARA INDEX SY-TABIX FROM WA_MARA1 TRANSPORTING STYLE CELLCOLR.
ENDIF.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'F_SET_STATUS'
I_CALLBACK_USER_COMMAND = 'F_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 = 'Example of select and deselect'
* I_GRID_SETTINGS =
IS_LAYOUT_LVC = WA_LAYOUT
IT_FIELDCAT_LVC = IT_FIELDCATALOG
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.
* CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
* EXPORTING
* I_CALLBACK_PROGRAM = GV_REPID
* I_CALLBACK_PF_STATUS_SET = 'F_SET_STATUS'
* I_CALLBACK_USER_COMMAND = 'F_USER_COMMAND'
* I_GRID_TITLE = 'Example of select and deselect'
* I_GRID_SETTINGS = WA_SETTINGS
* IS_LAYOUT = WA_LAYOUT
* IT_FIELDCAT = IT_FIELDCATALOG[]
* TABLES
* T_OUTTAB = IT_MARA.
* 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 f_set_status
* text
FORM F_SET_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STATUS1'.
ENDFORM. " f_set_status
*& Form f_user_command
* text
FORM F_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
* BREAK-POINT.
CASE R_UCOMM.
WHEN 'ASEL'.
LOOP AT IT_MARA INTO WA_MARA.
WA_MARA-FLAG = 'X'.
MODIFY IT_MARA FROM WA_MARA.
ENDLOOP.
RS_SELFIELD-REFRESH = 'X'.
WHEN 'DSEL'.
LOOP AT IT_MARA INTO WA_MARA.
WA_MARA-FLAG = ' '.
MODIFY IT_MARA FROM WA_MARA.
ENDLOOP.
RS_SELFIELD-REFRESH = 'X'.
WHEN 'DELETE'.
* BREAK-POINT.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF1.
CALL METHOD REF1->CHECK_CHANGED_DATA.
DELETE IT_MARA
WHERE FLAG = 'X'.
RS_SELFIELD-REFRESH = 'X'.
WHEN 'INSERT'.
CLEAR WA_MARA.
APPEND WA_MARA TO IT_MARA.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF1.
CALL METHOD REF1->REFRESH_TABLE_DISPLAY.
WHEN 'SAVEDB'.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF1.
CALL METHOD REF1->CHECK_CHANGED_DATA.
* CODE TO BE WRITTEN TO SAVE in DB just an insert statement
*ENDLOOP.
ENDCASE.
ENDFORM.
REPORT ZTEST_DHR.
TYPE-POOLS : SLIS.
TYPES: BEGIN OF TY_MARA,
FLAG TYPE CHAR1,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
WESCH TYPE MARA-WESCH,
STYLE TYPE LVC_T_STYL,
CELLCOLR TYPE LVC_T_SCOL,
END OF TY_MARA.
DATA : IT_MARA TYPE STANDARD TABLE OF TY_MARA.
DATA : IT_MARA1 TYPE STANDARD TABLE OF TY_MARA,
WA_MARA TYPE TY_MARA,
WA_MARA1 TYPE TY_MARA.
* for reuse alv grid display
*DATA : IT_FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV,
* WA_FIELDCATALOG TYPE SLIS_FIELDCAT_ALV,
* WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
* GV_REPID TYPE SY-REPID.
*for LVC Display
DATA : WA_SETTINGS TYPE LVC_S_GLAY.
DATA : WA_LAYOUT TYPE LVC_S_LAYO.
DATA : IT_FIELDCATALOG TYPE LVC_T_FCAT,
WA_FIELDCATALOG TYPE LVC_S_FCAT.
DATA REF1 TYPE REF TO CL_GUI_ALV_GRID.
DATA: LS_EDIT TYPE LVC_S_STYL,
LT_EDIT TYPE LVC_T_STYL.
DATA : LS_CELL_COLOR TYPE LVC_S_SCOL.
DATA : LT_CELL_COLOR TYPE LVC_T_SCOL.
START-OF-SELECTION.
SELECT MATNR ERSDA ERNAM WESCH
FROM MARA INTO CORRESPONDING FIELDS OF TABLE IT_MARA
UP TO 10 ROWS.
END-OF-SELECTION.
PERFORM BUILD_FIELDCATALOG.
PERFORM BUILD_LAYOUT.
PERFORM DISPLAY_ALV_REPORT.
*& Form BUILD_FIELDCATALOG
* text
FORM BUILD_FIELDCATALOG .
WA_FIELDCATALOG-FIELDNAME = 'FLAG'.
WA_FIELDCATALOG-OUTPUTLEN = 6.
WA_FIELDCATALOG-CHECKBOX = 'X'. "as checkbox
WA_FIELDCATALOG-EDIT = 'X'.
WA_FIELDCATALOG-SELTEXT = 'Check box'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME = 'MATNR'.
WA_FIELDCATALOG-OUTPUTLEN = 20.
WA_FIELDCATALOG-SELTEXT = 'Mat no'.
* wa_fieldcatalog-input = 'X'.
wa_fieldcatalog-edit = 'X'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME = 'ERSDA'.
WA_FIELDCATALOG-OUTPUTLEN = 15.
WA_FIELDCATALOG-SELTEXT = 'Creation Date'.
* wa_fieldcatalog-input = 'X'.
* wa_fieldcatalog-edit = 'X'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME = 'ERNAM'.
WA_FIELDCATALOG-OUTPUTLEN = 20.
WA_FIELDCATALOG-SELTEXT = 'Creation Time'.
* wa_fieldcatalog-input = 'X'.
* wa_fieldcatalog-edit = 'X'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME = 'WESCH'.
WA_FIELDCATALOG-OUTPUTLEN = 20.
WA_FIELDCATALOG-SELTEXT = 'Quantity'.
* wa_fieldcatalog-input = 'X'.
* wa_fieldcatalog-edit = 'X'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
ENDFORM. "build_fieldcatalog
*& Form BUILD_LAYOUT
* text
FORM BUILD_LAYOUT .
CONSTANTS : LC_X TYPE CHAR1 VALUE 'X'.
* WA_LAYOUT-NO_INPUT = LC_X.
WA_LAYOUT-CWIDTH_OPT = LC_X.
WA_LAYOUT-ZEBRA = LC_X.
WA_LAYOUT-STYLEFNAME = 'STYLE'.
WA_LAYOUT-CTAB_FNAME = 'CELLCOLR'.
ENDFORM. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
* text
FORM DISPLAY_ALV_REPORT .
LS_EDIT-FIELDNAME = 'FLAG'.
LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
INSERT LS_EDIT INTO TABLE LT_EDIT.
INSERT LINES OF LT_EDIT INTO TABLE WA_MARA1-STYLE.
LS_CELL_COLOR-FNAME = 'MATNR'.
LS_CELL_COLOR-COLOR-COL = '7'.
LS_CELL_COLOR-COLOR-INT = '1'.
INSERT LS_CELL_COLOR into table LT_CELL_COLOR.
INSERT LINES OF LT_CELL_COLOR into TABLE WA_MARA1-CELLCOLR.
LOOP AT IT_MARA INTO WA_MARA.
IF WA_MARA-ERSDA EQ '20080625'.
MODIFY IT_MARA INDEX SY-TABIX FROM WA_MARA1 TRANSPORTING STYLE CELLCOLR.
ENDIF.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'F_SET_STATUS'
I_CALLBACK_USER_COMMAND = 'F_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 = 'Example of select and deselect'
* I_GRID_SETTINGS =
IS_LAYOUT_LVC = WA_LAYOUT
IT_FIELDCAT_LVC = IT_FIELDCATALOG
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.
* CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
* EXPORTING
* I_CALLBACK_PROGRAM = GV_REPID
* I_CALLBACK_PF_STATUS_SET = 'F_SET_STATUS'
* I_CALLBACK_USER_COMMAND = 'F_USER_COMMAND'
* I_GRID_TITLE = 'Example of select and deselect'
* I_GRID_SETTINGS = WA_SETTINGS
* IS_LAYOUT = WA_LAYOUT
* IT_FIELDCAT = IT_FIELDCATALOG[]
* TABLES
* T_OUTTAB = IT_MARA.
* 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 f_set_status
* text
FORM F_SET_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STATUS1'.
ENDFORM. " f_set_status
*& Form f_user_command
* text
FORM F_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
* BREAK-POINT.
CASE R_UCOMM.
WHEN 'ASEL'.
LOOP AT IT_MARA INTO WA_MARA.
WA_MARA-FLAG = 'X'.
MODIFY IT_MARA FROM WA_MARA.
ENDLOOP.
RS_SELFIELD-REFRESH = 'X'.
WHEN 'DSEL'.
LOOP AT IT_MARA INTO WA_MARA.
WA_MARA-FLAG = ' '.
MODIFY IT_MARA FROM WA_MARA.
ENDLOOP.
RS_SELFIELD-REFRESH = 'X'.
WHEN 'DELETE'.
* BREAK-POINT.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF1.
CALL METHOD REF1->CHECK_CHANGED_DATA.
DELETE IT_MARA
WHERE FLAG = 'X'.
RS_SELFIELD-REFRESH = 'X'.
WHEN 'INSERT'.
CLEAR WA_MARA.
APPEND WA_MARA TO IT_MARA.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF1.
CALL METHOD REF1->REFRESH_TABLE_DISPLAY.
WHEN 'SAVEDB'.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF1.
CALL METHOD REF1->CHECK_CHANGED_DATA.
* CODE TO BE WRITTEN TO SAVE in DB just an insert statement
*ENDLOOP.
ENDCASE.
ENDFORM.
About Selecting a Color From Dropdown? even i need to check for now this is the how u do cell color in alv -
How to give color of particular cell in alv list display for dynamic table
Dear Experts,
i want to give color of a particular cell in alv list display (reuse_alv_list_display). Here i am passing data through dynamic table?Hi,
Se this:
DATA: lt_color TYPE lvc_t_scol WITH HEADER LINE.
DATA: BEGIN OF data_tab OCCURS 0.
tabcolor TYPE lvc_t_scol,
END OF data_tab.
* Befone ALV call
alv_layout-coltab_fieldname = 'TABCOLOR'.
* For each row in data_tab
REFRESH: lt_color.
CLEAR: lt_color.
lt_color-color-col = 6.
lt_color-color-int = 1.
lt_color-fname = FIELD1'.
APPEND lt_color.
lt_color-color-col = 2.
lt_color-color-int = 0.
lt_color-fname = 'FIELD2'.
APPEND lt_color.
data_tab-tabcolor[] = lt_color[].
append data_tab.
Best regards,
Leandro Mengue -
Color a particular cell in ALV
Hi all,
I am working with ALV using class cl_salv_table. i can colorize a particular colomn using cl_salv_column_table->set_color method. I was able to do it. I have done it for an amount column. Now I want to show the amount in some other color if it is 0. Let me know whether that possibility is there or not. If yes, please let me know the corresponding class and method and how we can implement it.
Thank u.Hi ,
fill emphasize of field catelog
wa_fcat-emphasize = color_code eg 'C400' .
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)
hope it helps ..... -
HOW TO CHANGE COLOR OF PARTICULAR CELL IN ALV
I HAVE DISPLAYED A REPORT IN ALV
I WANT TO CHANGE THE COLOR OF VBELN FIELD ON WHICH HOTSPOT IS ON?
HOW TO DO THIS?Hi Lovleen,
Check out the code
*& Report ZDEMO_ALVGRID *
*& Example of a simple ALV Grid Report *
*& The basic ALV grid, Enhanced to display each row in a different *
*& colour *
REPORT zdemo_alvgrid .
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,
line_color(4) type c, "Used to store row color attributes
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.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
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-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).
Set layout field for row attributes(i.e. color)
gd_layout-info_fieldname = 'LINE_COLOR'.
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
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_XEVENTS
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.
data: ld_color(1) type c.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
*Populate field with color attributes
loop at it_ekko into wa_ekko.
Populate color variable with colour properties
Char 1 = C (This is a color property)
Char 2 = 3 (Color codes: 1 - 7)
Char 3 = Intensified on/off ( 1 or 0 )
Char 4 = Inverse display on/off ( 1 or 0 )
i.e. wa_ekko-line_color = 'C410'
ld_color = ld_color + 1.
Only 7 colours so need to reset color value
if ld_color = 8.
ld_color = 1.
endif.
concatenate 'C' ld_color '10' into wa_ekko-line_color.
wa_ekko-line_color = 'C410'.
modify it_ekko from wa_ekko.
endloop.
endform. " DATA_RETRIEVAL
Regards,
Chandru -
Change the font of particular cell in matrix report
hi experts
i made a report in report 6i. now i want to change a color of particular cell which has shortest value. and
also i want to fill 0 ( zero ) value in blank column.
i have tried it from the property pallate " Value if Null " set to 0 (zero )
But it does not take the value.
Please solve the problem
regards
manojHi,
I think it will be better if you put NVL/DECODE in your main query for this column and also having second option create one placement column and store the value of the column in this placement column based on your condition criteria.
Thanks
Shishu Paul -
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.Rhi,
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 -
Set back ground color to a particular cell in table view
hi,
iam working on a jspDynpage and have a htmlb table view for which i need a way to set back ground color to a particular cell in table view, the color has to be set based on a value..is there a way to do it without using an iterator...well iam using a cellRenderer for the table but cant find a way to set the colors...if anyone does have a way please do reply...regardsYou can mention the color in <b>textview</b> as well as <b>Label as follows:</b>
<htmlb:textView text = "<span style='background-color: #00FF00'>My Textview</span>"
design = "EMPHASIZED" />
<htmlb:label for = "MyLabel"
text = "<span style='background-color: #00FF00'>Label </span>"
encode = "false"/>
Reward each helpful answer
Raja T
Message was edited by:
Raja Thangamani -
How to print the row ,column,and particular cell in separate color
how to print the row ,column,and particular cell in separate color IN ALV GRID
HI,
Here you go good program links
<a href="http://www.sapfans.com/forums/viewtopic.php?t=52107">How to Set Color to a Cell in AVL</a>
<a href="http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm">ALV Grid Coloring</a>
Thanks
Mahesh -
Hi All,
I am working with REUSE_ALV_HIERSEQ_LIST_DISPLAY function module to diaplay hierarchial list. Now my requirement is to color particular cells in the output based on condition. Can any one help me in this regard.
Thanks and Regards,
Srinadh.hi ,
try this..
* FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv, "internal table for field catalog
wa_field TYPE slis_fieldcat_alv. "work area for field catalog
* FOR LAYOUT OF ALV GRID
DATA : wa_layout TYPE slis_layout_alv. "work area for layout design
*& Form SET_LAYOUT
* SUB-ROUTINE SET_LAYOUT IS USED TO SET THE DISPLAY OF THE
* ALV GRID LINES IN ALTERNATIVE COLOURS
FORM set_layout .
wa_layout-zebra = 'X'.
ENDFORM. " SET_LAYOUT
*& Form ALV_DISPLAY
* SUB-ROUTINE ALV_DISPLAY IS USED TO SET THE PARAMETERS
* FOR THE FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
* AND PASS THE INTERNAL TABLE EXISTING THE RECORDS TO BE
* DISPLAYED IN THE GRID FORMAT
FORM alv_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = 'SY-REPID '
* 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 =
is_layout = wa_layout
it_fieldcat = it_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
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_final
* 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. "alv_display
regards
Ritesh J -
Change particular cell color when finised editing and when lost focus
Hi, i want to create a table which its particular cell can change its color automatically to red if the value in cell in column in two is smaller than column cell value in column 1 when user finish typed a value or if the cell has lost focus. I've wrote a code for the renderer but how should I use action, KeyListener or MouseLister or both
* File ColouredCellRenderer.java
import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.DefaultTableCellRenderer;
public class ColouredCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer{
private Object col1Value, col2Value;
public ColouredCellRenderer(Object args1, Object args2){
this.col1Value = args1;
this.col2Value = args2;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
protected void setValue(Object v){
super.setValue(v);
if((col1Value != null) & (col2Value != null)){
int x = Integer.parseInt(col1Value.toString());
int y = Integer.parseInt(col2Value.toString());
if(x > y){
this.setBackground(Color.RED);
else{
this.setBackground(Color.GREEN);
}All you should need is the cell renderer to achieve that effect. Whenever the table needs to render a cell it will call the method
getTableCellRendererComponent(...);This method in turn returns a component showing what the cell should look like. The DefaultTableCellRenderer extends JLabel, so you are meant to customize the label (based on parameters that were passed) and return this* at the end of the method.
public Component getTableCellRendererComponent(...) {
return this;
}This one label is used to render all the cells of all the columns that the cell renderer is assigned to. Since you want some cells too be red, you should call setBackground(Color.red)+ when the conditions are appropriate or null otherwise. -
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.Nhi,
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...
Maybe you are looking for
-
My wife and I have separate Ids but all our music is in one library. How will this work with iCloud? i'm trying to download past purchases from her id, but itunes is saying that I can't because the computer is associated with my apple id. Can I assoc
-
How to stop my screen from flashing
How do I get my 2nd gen I Touch screen from flashing?
-
Error when trying to burn a CD
Is there something wrong with my burner? When I try to burn either music or files i get Error 0x80020060
-
When I connect my 8830 (Sprint) to my computer, the computer no longer recogonizes the phone. However, the phone will charge when connected to the USB Cable. I have tried other cables and downloaded v4.6 of the DTM, but no luck. Has anyone else had t
-
Can I hookup my camcorder to external HD to laptop?
Sorry about the title. Didn't want to use too many words. I just purchased a panasonic gs320 off ebay. Looking to do some simple point and shoot stuff with a decent quality 3 ccd cam. Now here's my question. I have a macbook pro and my laptop only ha