‎2006 Mar 13 1:53 PM - last edited on ‎2024 Feb 03 5:10 PM by postmig_api_4
Hi all,
How to give color for a particular cell in a table control, not in the entire col or row.
The same thing in ALV as well.
What type of files can we upload for logos in ALV
Thanks in Advance,
K P
‎2006 Mar 13 1:59 PM
Hi kp,
1. coloring cell in alv
is a little tricky and complicated.
2. to get a taste of it,
just copy paste in new program
3. it will show T001
table with 3rd row , 2nd column CELL in PINK Color.
4.
REPORT abc .
*----
NECESSARY / MUST
TYPE-POOLS : slis.
DATA : alvfc TYPE slis_t_fieldcat_alv.
DATA : alvly TYPE slis_layout_alv.
*----
ITAB DECLARATION
DATA : prg TYPE sy-repid.
DATA : BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE t001.
DATA : clname(3) TYPE c,
clr TYPE slis_t_specialcol_alv,
END OF itab.
DATA : clrwa TYPE slis_specialcol_alv.
PARAMETERS : a TYPE c.
DATA : flname TYPE slis_fieldname.
*----
SELECT
START-OF-SELECTION.
SELECT * FROM t001
INTO CORRESPONDING FIELDS OF TABLE itab..
LOOP AT itab..
IF SY-TABIX <= 5.
itab-clname = 'C50'.
ELSE.
itab-clname = 'C30'.
ENDIF.
MODIFY itab.
ENDLOOP.
LOOP AT ITAB.
check itab-bukrs = '1000'
.
clrwa-fieldname = 'BUTXT'.
clrwa-color-col = 6.
APPEND clrwa TO itab-clr.
MODIFY ITAB.
clrwa-fieldname = 'LAND1'.
clrwa-color-col = 4.
APPEND clrwa TO itab-clr.
MODIFY ITAB.
ENDLOOP.
prg = sy-repid.
flname = 'CLNAME'.
alvly-info_fieldname = 'CLNAME'.
alvly-coltab_fieldname = 'CLR'.
LOOP AT ITAB.
if sy-tabix = 3.
clrwa-fieldname = 'BUTXT'.
clrwa-color-col = 6.
APPEND clrwa TO itab-clr.
MODIFY ITAB.
clrwa-fieldname = 'LAND1'.
clrwa-color-col = 1.
APPEND clrwa TO itab-clr.
MODIFY ITAB.
endif.
ENDLOOP
.
loop at itab.
*collect itab.
endloop.
*
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = prg
i_internal_tabname = 'ITAB'
i_inclname = prg
CHANGING
ct_fieldcat = alvfc
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
*----
minimum
*CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = alvfc
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2
*.
*----
extra
sy-uname = 'XYZAB'.
prg = sy-repid.
*----
Excluding
DATA : excl TYPE slis_t_extab.
DATA : exclwa TYPE slis_extab.
exclwa = '&OUP'.
APPEND exclwa TO excl.
exclwa = '&ODN'.
APPEND exclwa TO excl.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = alvfc
i_callback_program = sy-repid
is_layout = alvly
i_callback_user_command = 'ITAB_USER_COMMAND'
it_excluding =
excl
i_save = 'A'
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
&----
*& Form itab_user_command
&----
text
----
-->WHATCOMM text
-->WHATROW text
----
FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE
slis_selfield.
BREAK-POINT.
ENDFORM. "itab_user_command
regards,
amit m.
‎2006 Mar 13 2:04 PM
Sample code to color 2 cells in an ALV grid:
REPORT ZR_Colors.
data: begin of i_vbak2 occurs 0.
include structure vbak.
data: end of i_vbak2.
data: begin of i_vbak occurs 0.
include structure vbak.
data: cellcolors type lvc_t_scol. " note that is an int table within
data: end of i_vbak. " an int table !!!
types: begin of r_vbak.
include structure vbak.
types: cellcolors type lvc_t_scol.
types: end of r_vbak.
data: i_vbak_out type table of r_vbak.
data: cellcolor type lvc_s_scol.
data: layout type LVC_S_LAYO.
data: grid1 type ref to cl_gui_alv_grid,
field_catalog type lvc_t_fcat,
grid1_container type ref to cl_gui_custom_container.
data: lt_fieldcat type LVC_T_FCAT.
data: wa_fieldcat type LVC_s_FCAT.
start-of-selection.
select * from vbak into table i_vbak2
where erdat > '20041201'
and erdat < '20041216'.
loop at i_vbak2.
move-corresponding i_vbak2 to i_vbak.
append i_vbak.
endloop.
layout-zebra = 'X'.
layout-cwidth_opt = 'X'.
Set first cell in Net value column.
read table i_vbak index 2.
cellcolor-fname = 'NETWR'.
cellcolor-color-col = '3'.
cellcolor-color-int = '1'.
cellcolor-NOKEYCOL = 'X'.
append cellcolor to i_vbak-cellcolors.
modify i_vbak index 2.
Set 2nd cell in Net value column.
read table i_vbak index 4.
cellcolor-fname = 'NETWR'.
cellcolor-color-col = '6'.
cellcolor-color-int = '1'.
cellcolor-NOKEYCOL = 'X'.
append cellcolor to i_vbak-cellcolors.
modify i_vbak index 4.
Identify the internal table name with the colors reference.
layout-CTAB_FNAME = 'CELLCOLORS'.
Instantiate the grid container.
create object grid1_container
exporting
container_name = 'CUSTOM_GRID_CONTAINER'.
Instantiate the grid itself within the container.
create object grid1
exporting
i_parent = grid1_container
i_appl_events = 'X'.
i_vbak_out[] = i_vbak[].
Call method of grid1 class object to build/display the grid.
call method grid1->set_table_for_first_display
EXPORTING i_structure_name = 'VBAK'
is_layout = layout
changing
it_outtab = i_vbak_out.
it_fieldcatalog = lt_fieldcat.
call screen '0100'.
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'E100'.
SET TITLEBAR '100'.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
MODULE USER_COMMAND_0100 INPUT.
case sy-ucomm.
when 'EXIT' or 'BACK' or 'CANCEL'.
leave program.
endcase.
ENDMODULE. " USER_COMMAND_0100 INPUT
Reward points accordingly.