‎2007 May 14 2:07 PM
How to set the color for particular column in ALV?
How to set the color for particular row in ALV?
‎2007 May 14 2:31 PM
HEllo,
Check this sample report.
REPORT ZV_ALV_COLOR .
*&---------------------------------------------------------------------*
*& 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
If useful reward.
Vasanth
‎2007 May 14 2:09 PM
hi,,
For particular column,
add a field in field cat
i.e
FC-emphasize = 'C100'
regards,
kannan
‎2007 May 14 2:09 PM
‎2007 May 14 2:22 PM
Hi,
for coloring rows
*********************************
REPORT ZBHALV_GRID_DISPLAY.
TABLES:LFA1.
SELECT-OPTIONS:LIFNR FOR LFA1-LIFNR.
DATA:BEGIN OF ITAB OCCURS 0,
LIFNR LIKE LFA1-LIFNR,
NAME1 LIKE LFA1-NAME1,
LAND1 LIKE LFA1-LAND1,
ORT01 LIKE LFA1-ORT01,
REGIO LIKE LFA1-REGIO,
SORTL LIKE LFA1-SORTL,
CFIELD(4) TYPE C,
END OF ITAB.
SELECT * FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE LIFNR
IN LIFNR.
LOOP AT ITAB.
ITAB-CFIELD = 'C410'.
MODIFY ITAB.
ENDLOOP.
TYPE-POOLS:SLIS.
DATA:FCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA:LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA:HEAD TYPE SLIS_T_LISTHEADER WITH HEADER LINE.
DATA:SORT TYPE slis_t_sortinfo_alv WITH HEADER LINE.
LAYOUT-ZEBRA = 'X'.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
LAYOUT-WINDOW_TITLEBAR = 'VENDORS DETAILS SCREEN'.
LAYOUT-EDIT = 'X'.
LAYOUT-info_fieldname = 'CFIELD'.
SORT-UP = 'X'.
SORT-SPOS = 1.
SORT-FIELDNAME = 'LAND1'.
SORT-tabname = 'LFA1'.
APPEND SORT.
SORT-SPOS = 2.
SORT-FIELDNAME = 'NAME1'.
SORT-tabname = 'LFA1'.
APPEND SORT.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'ITAB'
I_STRUCTURE_NAME =
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = SY-REPID
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = FCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_TOP_OF_PAGE = 'TOPOFPAGE'
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID =
I_GRID_TITLE = 'VENDOR DETAILS'
I_GRID_SETTINGS =
IS_LAYOUT = LAYOUT
IT_FIELDCAT = FCAT
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT = 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 = 5
I_SCREEN_START_LINE = 5
I_SCREEN_END_COLUMN = 120
I_SCREEN_END_LINE = 25
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 = 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.
FORM TOPOFPAGE.
REFRESH HEAD.
HEAD-TYP = 'H'.
HEAD-INFO = 'VENDORS DETAILS TOP OF PAGE'.
APPEND HEAD.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEAD[]
.
ENDFORM.
for coloring columns
*********************************
REPORT ZBHCOLOR_COLS.
TABLES:LFA1.
SELECT-OPTIONS:C_LIFNR FOR LFA1-LIFNR. " FOR GRID ONLY
PARAMETERS:LIST RADIOBUTTON GROUP ALV DEFAULT 'X',
GRID RADIOBUTTON GROUP ALV.
DATA:BEGIN OF ITAB OCCURS 0,
LIFNR LIKE LFA1-LIFNR,
NAME1 LIKE LFA1-NAME1,
LAND1 LIKE LFA1-LAND1,
ORT01 LIKE LFA1-ORT01,
SORTL LIKE LFA1-SORTL,
REGIO LIKE LFA1-REGIO,
COL TYPE LVC_T_SCOL,
END OF ITAB.
DATA:COLR TYPE LVC_S_SCOL.
SELECT * FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE ITAB.
LOOP AT ITAB.
IF ITAB-LIFNR IN C_LIFNR.
COLR-FNAME = 'NAME1'.
COLR-COLOR-COL = '5'.
COLR-COLOR-INT = '1'.
COLR-COLOR-INV = '0'.
COLR-NOKEYCOL = 'X'.
APPEND COLR TO ITAB-COL.
COLR-FNAME = 'LIFNR'.
APPEND COLR TO ITAB-COL.
MODIFY ITAB.
ENDIF.
ENDLOOP.
TYPE-POOLS:SLIS.
DATA:FCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA:LAYOUT TYPE SLIS_LAYOUT_ALV.
LAYOUT-ZEBRA = 'X'.
layout-coltab_fieldname = 'COL'.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'ITAB'
I_STRUCTURE_NAME =
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = SY-REPID
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = FCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF LIST = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_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_STRUCTURE_NAME =
IS_LAYOUT = LAYOUT
IT_FIELDCAT = FCAT
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
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
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.
ELSEIF GRID = 'X'.
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 = LAYOUT
IT_FIELDCAT = FCAT
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 = 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.
ENDIF.
rgds,
bharat.
‎2007 May 14 2:22 PM
see mr koti,
to give color to particular row..first declare datatype in internal table which ur pasing into function module alv ex: u r using itab as internal table to passs into the fm alv grid...declare color (4) type c in itab also..to refer as itab-color...
and declare onle layout name also..in fm..alv..
now after select statement write loop for itab..
loop at itab.
if sy-tabix = 5
itab-color = 'cxy'.
c-> its constant.
x--> color number..
y--> intensify on off...
modify itab.
endif.
now deccalre data t_layout .
t_layout-info_fieldname = 'color'.
that it u will get the answer defiently if any querries reach me back..
bye reward points bec..it is the corret answer..haaa.
‎2007 May 14 2:24 PM
Hi,
b]Coloring an Entire Column:</b>
To make an entire column be painted with the color you want, you can
use the emphasize option of the field catalog. Simply assign a
color code to this field of the row added for your column. Color codes are
constructed as follows:
<i>Cxyz
x:Colornumbers
y:1/0:inverseon/off
z:1/0:intensifiedon/off</i>
<i>Color numbers are:
x color intended for
1 gray-blue headers
2 light gray list bodies
3 yellow totals
4 blue-green key columns
5 green positive threshold value
6 red negative threshold value
7 orange Control levels</i>
The key setting made via the field key of the field catalog
overrides this setting. So if you want this color to be colored
different than the key color, you should set the key field to space
while generating the field catalog. However, then there may be some side
effects on column orders. You can set the column order as you want at the
frontend. But if this is not suitable for you, then unset all key
settings and do all coloring and ordering as you want. Be careful that the
function module generating the field catalog will always set the key
properties of key fields.
<b>Coloring an Entire Row</b>
Coloring a row is a bit (really a bit) more complicated. To enable row
coloring, you should add an additional field to your list data table.
It should be of character type and length at least 4. This field will
contain the color code for the row. Sample Declaration of our list data
table gt_list.
<b><i>DATA BEGIN OF gt_list OCCURS 0 .
INCLUDE STRUCTURE SFLIGHT .
DATA rowcolor(4) TYPE c .
DATA END OF gt_list .</i></b>
As you guess, you should fill the color code to this field. Its format
will be explained below But how will ALV Grid know that you have loaded
the color data for the row to this field. So, you make it know this by
passing the name of the field containing color codes to the field
INFO_FNAME of the layout structure.
<i><b>ps_layout-info_fname = <field_name_containing_color_codes>.
e.g. ROWCOLOR</b></i>
You can fill that field anytime during execution. But, of course, due
to the flow logic of screens, it will be reflected to your list display
as soon as an ALV refresh occurs.
You can color an entire row as described in the next section. However,
this method is less time consuming.
<i><b>Coloring Individual Cells</b></i>
This is the last point about coloring procedures for the ALV Grid. The
procedure is similar to coloring an entire row. However, since an
individual cell can be addressed with two parameters we will need something
more. What is meant by more is a table type structure to be
included into the structure of the list data table. It seems strange,
because including it will make our list data structure deep. But anyhow ALV
Grid control handles this.
The structure that should be included must be of type LVC_T_SCOL.
If you want to color the entire row, this inner table should contain
only one row with field fname is set to space, some color value at
field col, 0 or 1 at fields int (intensified)
and inv (inverse).
If you want to color individual cells, then for each cell column,
append a line to this inner table which also contains the column name at
field fname. It is obvious that you can color an entire column by
filling this inner table with a row for that column for each row in the
list data table. But, it is also obvious that, this will be more time
consuming than the method at section C.6.1.
Again key field coloring will override your settings. Thats why, we
have another field in this inner table called nokeycol. For each
field represented in the inner table, set this field to X to
prevent overriding of key color settings.
In this procedure, again we must tell the control the name of the inner
table containing color data. The field CTAB_FNAME of the layout
structure is used for this purpose.
<i><b>*--- Internal table holding list data
DATA BEGIN OF gt_list OCCURS 0 .
INCLUDE STRUCTURE SFLIGHT .
DATA rowcolor(4) TYPE c .
DATA cellcolors TYPE lvc_t_scol .
DATA END OF gt_list .
Code Part 15 A sample code to make the cell at row 5 and column
SEATSOCC colored
DATA ls_cellcolor TYPE lvc_s_scol .
...
READ TABLE gt_list INDEX 5 .
ls_cellcolor-fname = 'SEATSOCC' .
ls_cellcolor-color-col = '7' .
ls_cellcolor-color-int = '1' .
APPEND ls_cellcolor TO gt_list-cellcolors .
MODIFY gt_list INDEX 5 .</b></i>
Hope this helps.
Reward if helpful.
Regards,
Sipra
‎2007 May 14 2:31 PM
HEllo,
Check this sample report.
REPORT ZV_ALV_COLOR .
*&---------------------------------------------------------------------*
*& 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
If useful reward.
Vasanth