2008 Apr 02 9:21 PM
Is there any event in ALV REPORTS to change the colours in the output list.
what is the event.
2008 Apr 02 9:34 PM
There is no standard event for that, but you can create you own button. And upon clicking button you can create some code to change the color of a column, row or even cell.
2008 Apr 02 9:40 PM
i can't understand u r answer.
will plz tell the briefly and what to do.
2008 Apr 03 6:28 AM
check this code...or go to program and select bc*alv and press f4..u will get the sample code
the sample code what i have used is as follows..
...
*&---------------------------------------------------------------------*
*& Report ZIMP1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZIMP4.
*ALV GRID REPORT WITH HEADER AND FOOTER DISPLAY.
TABLES kna1.
TYPE-POOLS SLIS.
*Data Declaration
TYPEs: BEGIN OF t_kna1,
kunnr TYPE kna1-kunnr,
lAND1 TYPE KNA1-LAND1,
NAME1 TYPE NAME1_GP,
ORT01 TYPE ORT01_GP,
LINE_COLOR(4) TYPE C,
END OF t_kna1.
DATA: It_kna1 TYPE STANDARD TABLE OF t_kna1 INITIAL SIZE 0,
wa_kna1 TYPE t_kna1.
*ALV Data Declaration
DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
GD_REPID TYPE SY-REPID,
I_EVENTS TYPE SLIS_T_EVENT,
W_EVENTS LIKE LINE OF I_EVENTS.
DATA: I_COMMENT TYPE SLIS_T_LISTHEADER,
WA_COMMENT TYPE SLIS_LISTHEADER.
START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BLD_FLDCAT.
PERFORM BLD_LAYOUT.
PERFORM CALL_EVENTS.
PERFORM DISPLAY_ALV_REPORT.
*Build Field Catalog for ALV Report
FORM BLD_FLDCAT.
FLDCAT-FIELDNAME = 'KUNNR'.
FLDCAT-SELTEXT_M = 'CUSTOMER NUMBER'.
FLDCAT-COL_POS = 0.
FLDCAT-EMPHASIZE = 'C411'.
FLDCAT-KEY = 'X'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.
FLDCAT-FIELDNAME = 'LAND1'.
FLDCAT-SELTEXT_L = 'COUNTRY'.
FLDCAT-COL_POS = 1.
FLDCAT-KEY = 'X'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.
FLDCAT-FIELDNAME = 'NAME1'.
FLDCAT-SELTEXT_L = 'CUSTOMER NAME'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.
FLDCAT-FIELDNAME = 'ORT01'.
FLDCAT-SELTEXT_M = 'CITY'.
FLDCAT-COL_POS = 3.
FLDCAT-EMPHASIZE = 'C110'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.
ENDFORM.
*Build Layout for ALV Grid Report
FORM BLD_LAYOUT.
GD_LAYOUT-NO_INPUT = 'X'.
GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.
ENDFORM.
*Display report using ALV grid
FORM DISPLAY_ALV_REPORT.
DATA T_EVENT TYPE SLIS_T_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = T_EVENT.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
GD_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = GD_REPID
IS_LAYOUT = GD_LAYOUT
*I_CALLBACK_HTML_TOP_OF_PAGE = 'TOP_OF_PAGE_SPLIT'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
*I_CALLBACK_HTML_END_OF_LIST = 'END_OF_LIST_HTML'
IT_EVENTS = I_EVENTS
IT_FIELDCAT = FLDCAT[]
I_SAVE = 'X'
TABLES
T_OUTTAB = It_kna1
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.
*Retrieve data from kna1 table and populate itab It_kna1
FORM DATA_RETRIEVAL.
DATA LD_COLOR(1) TYPE C.
SELECT *
UP TO 200 ROWS
FROM kna1
INTO CORRESPONDING FIELDS OF TABLE It_kna1.
LOOP AT It_kna1 INTO wa_kna1.
LD_COLOR = LD_COLOR + 1.
IF LD_COLOR = 8.
LD_COLOR = 1.
ENDIF.
CONCATENATE 'C' LD_COLOR '10' INTO wa_kna1-LINE_COLOR.
MODIFY It_kna1 FROM wa_kna1.
ENDLOOP.
ENDFORM.
FORM TOP_OF_PAGE.
WA_COMMENT-TYP = 'H'.
WA_COMMENT-info = 'REACHING TOP'.
APPEND WA_COMMENT TO I_COMMENT.
CLEAR WA_COMMENT.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = I_COMMENT
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM.
FORM CALL_EVENTS.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = I_EVENTS
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.
IF NOT I_EVENTS[] IS INITIAL.
READ TABLE I_EVENTS INTO W_EVENTS WITH KEY NAME = 'END_OF_LIST'.
W_EVENTS-FORM = 'GENERATE_USERCOMMAND_FOOTER'.
MODIFY I_EVENTS FROM W_EVENTS INDEX SY-TABIX.
ENDIF.
ENDFORM.
FORM GENERATE_USERCOMMAND_FOOTER.
CLEAR I_COMMENT[].
WA_COMMENT-TYP = 'H'.
WA_COMMENT-INFO = ' Sas sucess end-of-page'.
APPEND WA_COMMENT TO I_COMMENT.
clear wa_comment.
WA_COMMENT-TYP = 'H'.
WA_COMMENT-INFO = ' die hard end-of-page'.
APPEND WA_COMMENT TO I_COMMENT.
CLEAR wa_COMMENT.
WA_COMMENT-TYP = 'S'.
WA_COMMENT-INFO = SY-PAGNO.
APPEND WA_COMMENT TO I_COMMENT.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = I_COMMENT
I_LOGO = ''
I_END_OF_LIST_GRID = 'X'.
ENDFORM.
....... Check this and let me know u have understnad ot not a..rewards points if usefull
2008 Apr 03 6:22 AM
yus ....when you define fieldcatlog
add one more field
EMPHASIZE = 'X'
2008 Apr 03 6:30 AM
Hi,
For getting colours in ALVS
use in fieldcat the following field
wa_fieldcat-emphasize = 'C311'.
C is to specify color and must be in caps
3 is a color number ....u can use from 1 to 9.
first one for bold on or off.(1 on and 0 off)
another one is for inverse on or off.(1 on and 0 off)
Reward if helpful
Jagadish
2008 Apr 03 6:49 AM
Kanigiri reddy,
Please have a look at this sample program. Comments have been included wherever those are needed.
I hope that it helps u.
Regards,
Venkat.O
report zvenkat_alv_color_row_col.
*&---------------------------------------------------------------------*
" Declaration
" To get color for row
" 1.Define color variable with length 3 type char in the final internal
" which is displayed
" 2.build layout structure type slis_layout_alv by specifying
" info_fieldname = 'COLOR' and pass layout structure thru FM REUSE*ALV*
" 3.Poplate Final internal with color values for the field COLOR.
*----------------------------------------------------------------------*
"types
types:
begin of t_pa0001,
color(3) type c, "1.Declare this
pernr type pa0001-pernr,
ename type pa0001-ename,
end of t_pa0001.
"Work area
data:
w_pa0001 type t_pa0001.
"Internal tables
data:
i_pa0001 type standard table of t_pa0001.
*&---------------------------------------------------------------------*
* ALV Declarations
*----------------------------------------------------------------------*
* Types Pools
type-pools:
slis.
* Types
types:
t_fieldcat type slis_fieldcat_alv,
t_events type slis_alv_event,
t_layout type slis_layout_alv.
* Workareas
data:
w_fieldcat type t_fieldcat,
w_events type t_events,
w_layout type t_layout.
* Internal Tables
data:
i_fieldcat type standard table of t_fieldcat,
i_events type standard table of t_events.
*&---------------------------------------------------------------------*
*&START-OF-SELECTION
*&---------------------------------------------------------------------*
start-of-selection .
perform get_data.
perform color_the_row. "Populate Color like this based on ur conditions
*&---------------------------------------------------------------------*
*&END-OF-SELECTION
*&---------------------------------------------------------------------*
end-of-selection.
perform fieldcat.
perform layout_build.
perform dispaly .
*&---------------------------------------------------------------------*
" Form fieldcat
"emphasize ===== Set this to highlight column in color
" Value range: SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)
" 'X' = The column is highlighted in the default color for color highlighting.
" 'Cxyz' = The column is highlighted in the coded color:
" C: Color (coding must start with C)
" x: Color number
" y: Intensified
" z: Inverse
*&---------------------------------------------------------------------*
form fieldcat .
clear :
w_fieldcat,i_fieldcat[].
w_fieldcat-fieldname = 'PERNR'.
w_fieldcat-tabname = 'I_PA0001'.
w_fieldcat-emphasize = 'C71'.
w_fieldcat-seltext_m = 'Employee No'.
w_fieldcat-no_zero = 'PERNR'.
append w_fieldcat to i_fieldcat.
clear w_fieldcat.
w_fieldcat-fieldname = 'ENAME'.
w_fieldcat-tabname = 'I_PA0001'.
w_fieldcat-seltext_m = 'ENAME'.
append w_fieldcat to i_fieldcat.
clear w_fieldcat.
endform. " fieldcat
*&---------------------------------------------------------------------*
*& Form dispaly
*&---------------------------------------------------------------------*
form dispaly .
data :l_program type sy-repid.
l_program = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = l_program
* i_callback_top_of_page = 'TOP_OF_PAGE'
i_callback_html_top_of_page = 'TOP_OF_PAGE'
is_layout = w_layout
it_events = i_events
it_fieldcat = i_fieldcat
tables
t_outtab = i_pa0001.
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 .
do 20 times.
select pernr ename
from pa0001
appending corresponding fields of table i_pa0001
up to 10 rows.
enddo.
endform. " get_data
*&---------------------------------------------------------------------*
*& Form layout_build
*&---------------------------------------------------------------------*
form layout_build .
w_layout-info_fieldname = 'COLOR'. "Pass COLOR field name like this.
endform. " layout_build
*&---------------------------------------------------------------------*
*& Form color_the_row
*&---------------------------------------------------------------------*
form color_the_row .
loop at i_pa0001 into w_pa0001.
if sy-tabix > 3.
w_pa0001-color = 'C31'.
modify i_pa0001 from w_pa0001 index sy-tabix.
endif.
endloop.
endform. " color_the_row
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
form top_of_page using document type ref to cl_dd_document.
data:
l_text type sdydo_text_element.
l_text = 'xyz'.
call method document->add_text
exporting
text = l_text
sap_emphasis = cl_dd_document=>strong
sap_style = cl_dd_document=>key.
call method document->new_line.
l_text = 'lmn'.
call method document->add_text
exporting
text = l_text
sap_fontsize = cl_dd_document=>medium
sap_color = cl_dd_document=>list_positive
sap_style = cl_dd_document=>key.
call method document->underline.
endform. "top_of_page
2008 Apr 03 8:56 AM