Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

add color in alv

Former Member
0 Kudos

hi

i use CL_SALV_TABLE to show alv.

how i insert color to some texts in top of page.

thanks

have a nice day

6 REPLIES 6

Former Member
0 Kudos

hi,

while writing the text use color statement.

i.e, write <field> color n.

Have a look at this link

http://www.sap-img.com/abap/line-color-in-alv-example.htm

Regards,

Santosh

former_member188685
Active Contributor

venkat_o
Active Contributor
0 Kudos

Hi yossi balan,

<b>1</b>.

You can use to get COLOR on TOP_OF_PAGE using this.

WRITE 'XYZ' COLOR 2.

<b>2</b>.

Define variable COLOR like this in ur final table which u pass to REUSE_ALV_LIST or GRID_DISPLAY.

DATA: BEGIN OF i_mard OCCURS 0,

<b> color(3) TYPE c,</b>

werks TYPE mard-werks,

lgort TYPE mard-lgort,

matnr TYPE mard-matnr,

insme TYPE mard-insme,

einme TYPE mard-einme,

speme TYPE mard-speme,

END OF i_mard.

<b>3</b>.

<b>a</b>.

If u want to change Rows color

LOOP AT i_mard .

IF sy-tabix BETWEEN 10 AND 20 .

i_mard-color = 'C71'.

MODIFY i_mard INDEX sy-tabix.

ENDIF.

ENDLOOP.

<b>b</b>.

If u want to display COLOR for Column

set this for perticular column.

w_fieldcatalog-Emphasize = 'X'.

<b>4</b>.

Declare w_layout TYPE slis_layout_alv.(Should be Global)

w_layout-info_fieldname = 'COLOR'.

and pass structure to REUSE_ALV_LIST or GRID_DISPLAY.

I think u can easily understand.

<b>Thanks,

Venkat.O</b>

Clemenss
Active Contributor
0 Kudos

Hi,

only the last answer shows into the right direction.

Creating your object, there is parameter I_S_LAYOUT. You must pass a structured field of type LVC_S_LAYO. This must be used to store the name of the table field storing color information:

<pre>

  • like this...

data:

LS_LAYOUT type VC_S_LAYO.

LS_LAYOUT-CTAB_FNAME = 'COLORS'.

*...

pass this parameter when creating the CL_SALV_TABLE object.

In your internal table, you need a field named COLORS of type LVC_T_SCOL. This should <b>not</b> be part of the field catalog.

The coloring of specific cells is done like

loop at itab.

PERFORM alv_color

USING lv_fnam col_positive 1 0

CHANGING itab-colors.

modify itab.

endloop." at itab.

where lv_fnam is the name of the field where you set the color. If the name is space, ALV will color the whole line, then comes the color (use TYPE-POOLS col), then intensify and inverse (0 or 1) attributes.

You can still make the above loop better using loop .. assigning ...

The form looks like this:

&----


*& Form alv_color

&----


  • set field color

----


FORM alv_color USING pv_fieldname TYPE fieldname

pv_color TYPE c

pv_intensify TYPE i

pv_inverse TYPE i

CHANGING pt_colors TYPE LVC_T_SCOL.

DATA:

ls_colors TYPE LINE OF LVC_T_SCOL.

READ TABLE pt_colors TRANSPORTING NO FIELDS WITH KEY

fieldname = pv_fieldname

color-col = pv_color

color-int = pv_intensify

color-inv = pv_inverse

BINARY SEARCH.

CHECK sy-subrc <> 0.

ls_colors-fieldname = pv_fieldname.

ls_colors-color-col = pv_color.

ls_colors-color-int = pv_intensify.

ls_colors-color-inv = pv_inverse.

INSERT ls_colors INTO pt_colors INDEX sy-tabix.

ENDFORM. "alv_color

</pre>

By the way: This is first time I see someone uses CL_SALV_TABLE - Usually CL_GUI_ALV_GRID (similar but I think more powerful) is used. Is ther any advantage?

Hope it really helps.

Regards,

Clemens

Former Member
0 Kudos

Hi,

Have a column for colour in your data table, something like this

T_COLOR TYPE LVC_T_SCOL,

Now, you can add a color for each field of each row in this.

Here is a sample code

LOOP AT T_DATA ASSIGNING <FS_DATA> WHERE PRICE > 5000.

LR_COLUMN ?= LR_COLUMNS->GET_COLUMN( 'COLUMN_NAME' ).

LS_COLOR-FNAME = 'COLUMN_NAME'.

LS_COLOR-COLOR-COL = XXXXX.

LS_COLOR-COLOR-INT = 0.

LS_COLOR-COLOR-INV = 0.

APPEND LS_COLOR TO <FS_DATA>-T_COLOR.

CLEAR : LS_COLOR, L_COL_COLOR.

ENDLOOP.

TRY.

LR_COLUMNS->SET_COLOR_COLUMN( 'T_COLOR' ).

CATCH CX_SALV_DATA_ERROR.

ENDTRY.

Regards,

Ravi

0 Kudos

hi

i mean i need color in top of page

my code:

LR_LABEL = LR_GRID_1->CREATE_LABEL(

ROW = 1

COLUMN = 1

TEXT = TEXT-005

TOOLTIP = TEXT-005 ).

***... in the cell [1,2] of the second Grid create a text

LR_TEXT = LR_GRID_1->CREATE_TEXT(

ROW = 1

COLUMN = 2

TEXT = LV_TIME

TOOLTIP = LV_TIME ).

this the way i insert top-of-page

how can i color it?

thanks