Research on ALV object-oriented method: Set the color of cells meeting the condition (4)

Source: Internet
Author: User

Continue this topic.

This article explains how to set the color of cells that meet the conditions. For example, in a report, set the cells with scores less than 60 to red. This function is common!

1. First, remember to add a column color when defining the internal mark:

....
CELLCOLOR TYPE LVC_T_SCOL,
...

2. When modifying the internal table, add the following content to the column:

DATA: W_CELLCOLOR TYPE LVC_S_SCOL.

IF IT_SFLIGHT-PRICE <= 1000. "Red less than 1000
CLEAR IT_SFLIGHT-COLOR.
W_CELLCOLOR-FNAME = 'price'. "Color Bar
W_CELLCOLOR-COLOR-COL = '6'. "Red
W_CELLCOLOR-COLOR-INT = '1'. "color deepening 0 means not deepening
APPEND W_CELLCOLOR TO IT_SFLIGHT-CELLCOLOR.
ENDIF.

3. When setting ALV format:

*&---------------------------------------------------------------------*
* & FORM PREPARE_LAYOUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> PS_LAYOUT TEXT
*----------------------------------------------------------------------*
FORM PREPARE_LAYOUT CHANGING PS_LAYOUT TYPE LVC_S_LAYO.
PS_LAYOUT-ZEBRA = 'x '.
PS_LAYOUT-GRID_TITLE = TITLE.
PS_LAYOUT-SMALLTITLE = 'x '.
PS_LAYOUT-SEL_MODE = 'A '.
PS_LAYOUT-INFO_FNAME = 'color '.
PS_LAYOUT-CTAB_FNAME = 'cellcolor'. "Must be capitalized
PS_LAYOUT-CWIDTH_OPT = 'x '.
PS_LAYOUT-DETAILINIT = 'x '.
ENDFORM. "PREPARE_LAYOUT

The effect is as follows:

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.