2006 Sep 01 2:06 PM
please tell me how to add colour to a field in an alv reporting along with code.
thanking u,
shalini.
please tell me how to add colour to a field in an alv reporting along with code.
thanking u,
shalini.
2006 Sep 01 2:12 PM
hi,
You can customise field catalog properties for chaning the color.
EMPHASIZE in field catalog
If the field is set to 'X', the ALV uses a predefined
color for highlighting the column. If the character field begins with 'C' (color code), the remaining numbers have the following meaning:
x: color number
y: intensified display on/off
y: inverse display on/off
For more information on color coding, see the
F1 help on the FORMAT statement.
SPACE, 'X' or 'Cxyz' (x:'1'- '9'; y,z: '0'=off '1'=on)
Regards,
Sailaja.
Message was edited by: Sailaja N.L.
2006 Sep 01 2:14 PM
Hi,
1.Declare a internal table of type
<b>data color type slis_t_specialcol_alv with header line</b>
2.Add one column in the output table of ALV(IT_ALVDATA) of type slis_t_specialcol_alv .
3. Declare a layout variable of type SLIS_LAYOUT_ALV and set the variable <b>ST_LAYOUT-COLTAB_FIELDNAME= 'COLOR'</b> and pass this structure to the Function module reuse_alv_grid_display.
The following code will highlight the posnr field in my output table.
loop at it_alv_data.
if sy-tabix = 2.
color-fieldname = 'POSNR'.
COLOR-COLOR-COL = 6.
color-color-int = 0.
append color.
IT_ALV_DATA-COLOR = COLOR[].
ls_style-fieldname = 'WERKS'.
ls_style-style = cl_gui_alv_grid=>mc_style_enabled.
append ls_style.
it_alv_data-style = ls_style[].
modify it_alv_data.
endif.
endloop.
Hope this helps.
Message was edited by: Imtiaz Ahmed
2006 Sep 01 2:16 PM
hi Shalini,
do this way ..
IF p_deta = 'X'.
<b> FORMAT COLOR COL_TOTAL .</b>
LOOP AT it_detail.
* AT NEW OWN_NO.
* OWNER_COUNT = OWNER_COUNT + 1.
* ENDAT.
AT LAST.
SUM.
v_tot = it_detail-gl_trans_am.
ENDAT.
MOVE-CORRESPONDING it_detail TO t_temp_det.
APPEND t_temp_det.
CLEAR t_temp_det.
ENDLOOP.
2006 Sep 01 2:24 PM
Hi shalini,
1. Not only the full row color,
we can also manipulate the color in each cell.
2.
IMPORTANT THINGS
a. Extra field in internal table
clr TYPE slis_t_specialcol_alv,
(this field will contain the colour codes)
b. assign fieldname to alv layout
alvly-coltab_fieldname = 'CLR'
c. work area for colour
DATA : clrwa TYPE slis_specialcol_alv.
d. Populating the color
Once again
Loop at ITAB.
*********logic
if itab-field < 0 "---negative
clrwa-fieldname = 'FIELDNAME'. "<--- FIELDNAME FOR COLOR
clrwa-color-col = 6. <------- COLOUR 0-9
APPEND clrwa TO itab-clr.
MODIFY ITAB.
endif.
ENDLOOP.
*----
5. just copy paste in new program
6.
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
.
*
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 Sep 01 2:29 PM
Hi Shalini,
*Type Declarations for Layout Design
DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
PERFORM GENERATE_LAYOUT.
FORM GENERATE_LAYOUT .
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "OPTIMIZING FIELD WIDTH
WA_LAYOUT-ZEBRA = 'X'. "PUTTING ZEBRA COLORS
WA_LAYOUT-CONFIRMATION_PROMPT = 'X'. "DISPLAYS CONFIRMATION DIALOG
WA_LAYOUT-FLEXIBLE_KEY = 'X'. "KEY COLUMN IS MOVABLE
WA_LAYOUT-TOTALS_TEXT = 'Totals'(015). "DISPLAYS TOTALS TEXT
WA_LAYOUT-SUBTOTALS_TEXT = 'Sub Totals'(016)."DISPLAYS SUB TOTALS TEXT
<b> WA_LAYOUT-INFO_FIELDNAME = 'COLOR'(017). "APPLYING COLORS TO ROWS</b>
Thanks
Vikranth Khimavath
2006 Sep 01 2:33 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |