Skip to Content
author's profile photo Former Member
Former Member

Changing fields color in CL_GUI_ALV_GRID using class

Hi,

I've written a lot of posts but still I have problem with changing color for CL_GUI_ALV_GRID.

I have class ZKSL_CL_4_17_ALV_GRID_OO with 3 methods : SELECT, HANDLE_DBL_CLICK AND DISPLAY_ALV

I want to change fields color every time I double click on IT.

METHOD SELECT.

DATA:

lt_sflight TYPE TABLE OF zkslt_sflight,

ls_layout TYPE lvc_s_layo,

lr_custom_container TYPE REF TO cl_gui_custom_container,

lr_my_class TYPE REF TO zksl_cl_4_17_alv_grid_oo.

SELECT * FROM zkslt_sflight INTO TABLE mt_sflight

WHERE carrid = iv_carrid AND

( fldate IN it_date OR

price IN it_price OR

planetype IN it_type )

.

CALL FUNCTION 'Z_KSL_SCREEN'.

ENDMETHOD.

from FM z_ksl_screen i call screen 400 and from status_400 output I call method DISPLAY_ALV

METHOD display_alv.

DATA:

lr_custom_container TYPE REF TO cl_gui_custom_container,

lt_sflight TYPE TABLE OF zkslt_sflight,

lt_catalog TYPE STANDARD TABLE OF lvc_s_fcat,

ls_catalog LIKE LINE OF lt_catalog,

ls_layout type slis_layout_alv,

lr_my_class TYPE REF TO zksl_cl_4_17_alv_grid_oo.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'ZKSLT_SFLIGHT'

CHANGING

ct_fieldcat = lt_catalog[].

*******************************************************

************BULID LAYOUT

********************************************************

ls_layout-no_input = 'X'.

ls_layout-colwidth_optimize = 'X'.

ls_layout-totals_text = 'Totals(201)'.

ls_layout-info_fieldname = 'LINE_COLOR'.

********************************************************

IF mr_gui_alv_grid IS INITIAL. "-----------------------------------if----------------------&

CREATE OBJECT: lr_custom_container

EXPORTING

container_name = 'DISPLAY',

lr_my_class.

CREATE OBJECT mr_gui_alv_grid

EXPORTING

i_parent = lr_custom_container.

SET HANDLER lr_my_class->handle_dbl_click FOR mr_gui_alv_grid.

CALL METHOD mr_gui_alv_grid->set_table_for_first_display

EXPORTING

i_structure_name = 'ZKSLT_SFLIGHT'

is_layout = ls_layout

i_save = 'A'

CHANGING

it_outtab = Mt_sflight

it_fieldcatalog = lt_catalog.

ELSE. "-------------------------------------------------ELSE---------------------&

mr_gui_alv_grid->refresh_table_display( ) .

ENDIF.

ENDMETHOD.

In handler i am trying to change fields color and call method display sending new out_table

CALL METHOD me->display_alv

CHANGING

ct_fieldcat = lt_fieldcat.

Please give me some easy advice how to do that.

thank you in advice.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jun 05, 2014 at 06:37 AM

    Hi Krzysztof,

    if you want to change color of a single field in a single line of ALV, then you need

    • a field of table type LVC_T_SCOL in the structure of your output table
    • pass this fieldname to LS_LAYOUT-CTAB_FNAME
    • mark this field as TECH = X in your field catalogue

    To fill the table use structure LVC_S_SCOL and fill

    • field FNAME with the name of the field in this line, where you wnt to set the color
    • field COLOR-COL with values 0 to 9
    • field COLOR-INT with 0 (optionally also with 1 or 2)
    • field COLOR-INV with 0 (optionally also with 1 or 2)

    Regards,

    Klaus


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 05, 2014 at 06:17 AM

    In the handling method

    • Change LINE_COLOR value for the selected record in internal table (index es_row_no-row_id )
    • Use method sender->refresh_table_display

    Regards,

    Raymond

    Add a comment
    10|10000 characters needed characters exceeded

    • "sender" is not a method, it will receive your "mr_gui_alv_grid" instance, this parameter is available for every event, and is useful when you manage multiple occurence sof a class (e.g. 2 grids) You can use your "mr_gui_alv_grid" too as long as you don't share hander between two occurences of the same class.

      Also read your own program, you filled the is_layour subfield INFO_FNAME with a field of the internal table which contain a color code (ref coloring rows) so read again the first task in my previous answer.

      Regards,

      Raymond

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.