07-22-2009 7:57 AM
Hi!
I'm using the REUSE_ALV_GRID_DISPLAY FM and I have to display the line wich have c in a field in red and the other lines in green.
I'm displaying a Log table and I want to display errors in red and the other lines in GREEN.
I have a field in wich there is a letter to differenciate if the line has error or not.
Do someone know how can I do that?
Thanks.
Jorgelina.
07-22-2009 8:07 AM
Hi Ina,
Pls go through this program,
type-pools : slis.
types : begin of g_ty_data ,
matnr type matnr ,
werks type werks_d ,
color(4) type c,
End of g_ty_data.
Data : g_t_data type table of g_ty_data WITH HEADER LINE ,
g_t_cat type slis_t_fieldcat_alv WITH HEADER LINE,
g_r_layo type slis_layout_alv.
start-of-selection.
select matnr werks
into table g_t_data
from mard.
g_t_cat-fieldname = 'MATNR'.
append g_t_cat.
g_t_cat-fieldname = 'WERKS'.
append g_t_cat.
*----> Here you specify the field in the table containg the color code
g_r_layo-info_fieldname = 'COLOR'.
*--> Loop and assign color
LOOP AT g_t_data.
g_t_data-color = 'C600'.
modify g_t_data.
endloop.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
Regards
07-22-2009 8:02 AM
07-22-2009 8:02 AM
hello frn '
below is the working code for coloring alv rows ...try this
ROW COLOR OF ALV
Purpose of the Report: This report gives an idea about coloring a row of the ALV .
Concept: Make the final internal table with field col (here you pass the color code) table which you pass in the display ALV function module.
Make a layout of type LVC_S_LAYO and pass the field name inside the layout.
LAYOUT-INFO_FNAME = u2018COLu2019.
The report is coloring the last row of the alv with color red .
REPORT ZPRI_ALV_ROW_COLOR.
TABLES: MARA , MAKT .
DATA: LAYOUT TYPE LVC_S_LAYO . (layout)
DATA: CONT1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER .
DATA: GRID1 TYPE REF TO CL_GUI_ALV_GRID .
DATA: FCAT1 TYPE LVC_T_FCAT .
DATA: WA_FCAT1 LIKE LINE OF FCAT1 .
TYPES : BEGIN OF TYPE_ITAB1 ,
MATNR LIKE MARA-MATNR ,
MTART LIKE MARA-MTART,
MATKL LIKE MARA-MATKL ,
MAKTX LIKE MAKT-MAKTX ,
COL(4) TYPE C , (add this field for coloring purpose)
END OF TYPE_ITAB1 .
DATA: IT_ITAB1 TYPE STANDARD TABLE OF TYPE_ITAB1 WITH HEADER LINE .
DATA: LEN TYPE I.
LAYOUT-INFO_FNAME = 'COL' . (pass field name in layout )
WA_FCAT1-TABNAME = 'IT_ITAB1' .
WA_FCAT1-FIELDNAME = 'MATNR' .
WA_FCAT1-COLTEXT = 'Material' .
WA_FCAT1-OUTPUTLEN = 18 .
APPEND WA_FCAT1 TO FCAT1 .
CLEAR WA_FCAT1 .
WA_FCAT1-TABNAME = 'IT_ITAB1' .
WA_FCAT1-FIELDNAME = 'MTART' .
WA_FCAT1-COLTEXT = 'Material Type' .
WA_FCAT1-OUTPUTLEN = 15 .
APPEND WA_FCAT1 TO FCAT1 .
CLEAR WA_FCAT1 .
WA_FCAT1-TABNAME = 'IT_ITAB1' .
WA_FCAT1-FIELDNAME = 'MATKL' .
WA_FCAT1-COLTEXT = 'Material Group' .
WA_FCAT1-OUTPUTLEN = 15 .
APPEND WA_FCAT1 TO FCAT1 .
CLEAR WA_FCAT1 .
WA_FCAT1-TABNAME = 'IT_ITAB1' .
WA_FCAT1-FIELDNAME = 'MAKTX' .
WA_FCAT1-COLTEXT = 'Description' .
WA_FCAT1-OUTPUTLEN = 25 .
APPEND WA_FCAT1 TO FCAT1 .
CLEAR WA_FCAT1 .
SELECT AMATNR AMTART AMATKL BMAKTX INTO TABLE IT_ITAB1 FROM MARA AS A INNER JOIN MAKT AS B ON AMATNR = BMATNR .
DESCRIBE TABLE IT_ITAB1 LINES LEN .
LEN = LEN .
IT_ITAB1-COL = 'C601' . ( color code )
MODIFY IT_ITAB1 INDEX LEN FROM IT_ITAB1
TRANSPORTING COL .
CALL SCREEN 100 .
module SHOWALV output.
CREATE OBJECT cont1
EXPORTING
PARENT =
container_name = 'CUSTOM'
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 grid1
EXPORTING
I_SHELLSTYLE = 0
I_LIFETIME =
i_parent = CONT1
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.
CALL METHOD grid1->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 = LAYOUT
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
it_outtab = IT_ITAB1[]
IT_FIELDCATALOG = FCAT1
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.
endmodule. " SHOWALV OUTPUT
Thanks
Priyank
07-22-2009 8:03 AM
there must be at least 500 example about this. You should first try to search forum before posting.
07-22-2009 8:04 AM
Hi,
The follow program demonstrates how to change the colour of individual rows of an ALV grid. Changes required
from a basic ALV grid include adding a new field to ALV grid data table(it_ekko), Populating this field with color
attribute and adding an entry to layout control table.
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
peinh TYPE ekpo-peinh,
line_color(4) type c, "Used to store row color attributes
END OF t_ekko.
pass line_color in Layout.
gd_layout-info_fieldname = 'LINE_COLOR'. * Set layout field for row attributes(i.e. color)
At data_retrieval.
data: ld_color(1) type c.
select ebeln ebelp statu 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.
Thanks & regards
Edited by: ShreeMohan Pugalia on Jul 22, 2009 9:04 AM
07-22-2009 8:51 AM
Hi,
Add a character field in the final internal. check the records having error values if its present then update this field in the internal table
while creating layout
I_LAYOUT-INFO_FIELDNAME = 'Fieldname for colour'.
Thanks & Regards,
John Victor
07-22-2009 8:07 AM
Hi Ina,
Pls go through this program,
type-pools : slis.
types : begin of g_ty_data ,
matnr type matnr ,
werks type werks_d ,
color(4) type c,
End of g_ty_data.
Data : g_t_data type table of g_ty_data WITH HEADER LINE ,
g_t_cat type slis_t_fieldcat_alv WITH HEADER LINE,
g_r_layo type slis_layout_alv.
start-of-selection.
select matnr werks
into table g_t_data
from mard.
g_t_cat-fieldname = 'MATNR'.
append g_t_cat.
g_t_cat-fieldname = 'WERKS'.
append g_t_cat.
*----> Here you specify the field in the table containg the color code
g_r_layo-info_fieldname = 'COLOR'.
*--> Loop and assign color
LOOP AT g_t_data.
g_t_data-color = 'C600'.
modify g_t_data.
endloop.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
Regards