How to set the color of a single cell in 'reuse _ alv_grid_display'

Source: Internet
Author: User

When designing an ALV report, you sometimes need to display a specific unit in a specific color based on certain conditions. The specific implementation steps are as follows:

1. Add a new field to the inner table to be displayed. The field type is lvc_t_scol.
2. Set color data based on the conditions;
3. Set the data for the layout-coltab_fieldname to specify the display color field.
The Code is as follows: (pay attention to the red part)
Report z_alv_color.
Type-pools: slis.
Data: Begin of it_flight occurs 0,
Carrid like sflight-carrid,
Connid like sflight-connid,
Fldate like sflight-fldate,
Seatsmax like sflight-seatsmax,
Seatsocc like sflight-seatsocc,
Color type lvc_t_scol,
End of it_flight.
Data: it_fieldcat type slis_t_fieldcat_alv,
Layout type slis_layout_alv.
Call function 'reuse _ alv_fieldcatalog_merge'
Exporting
I _program_name = sy-repid
I _internal_tabname = 'it _ flight'
I _inclname = sy-repid
Changing
Ct_fieldcat = it_fieldcat
Exceptions
Inconsistent_interface = 1
Program_error = 2.

Select carrid
Connid
Fldate
Seatsmax
Seatsocc
From sflight
Into corresponding fields of table it_flight
Up to 20 rows.
Data: Col type lvc_s_scol,
Coltab type lvc_t_scol,
Color type lvc_s_colo.
Color-Col = '6 '.
Color-Int = '0 '.
Color-inv = '0 '.
Loop at it_flight.
 If it_flight-seatsocc EQ 0.
Col-fname = 'seatsocc '.
Col-color = color.
Append Col to coltab.
Clear Col.
It_flight-color = coltab.
Modify it_flight.
Endif.
Endloop.
Layout-coltab_fieldname = 'color '.
Call function 'reuse _ alv_grid_display'
Exporting
I _callback_program = sy-repid
Is_layout = Layout
It_fieldcat = it_fieldcat
Tables
T_outtab = it_flight
Exceptions
Program_error = 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.