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: 

Changing fields color in CL_GUI_ALV_GRID using class

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

former_member195402
Active Contributor
0 Kudos

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


7 REPLIES 7

raymond_giuseppi
Active Contributor
0 Kudos

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

0 Kudos

What is the method sender and how it change my fields color?

0 Kudos

"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

former_member195402
Active Contributor
0 Kudos

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


0 Kudos

Hi Krzysztof,

please check this sample program. You have to upload the report and manually to create screen 1100 in SE51 and GUI status EXIT in SE41 then.

Sorry for the German Hardcopies.

In SE41 all three function codes are EXIT commands:

Settings of screen 1100.

Flow logic of screen 1100:

Layout of screen 1100:

Regards,

Klaus

0 Kudos

Thank you Klaus for your reply,

The problem is that I need to make this using classes.

I tried to make my structure data with LVC_T_SCOL as you wrote,


  • a field of table type LVC_T_SCOL in the structure of your output table

DATA BEGIN OF lt_data

       INCLUDE STRUCTURE sflight.

       DATA cellcolors  TYPE lvc_t_scol .

   DATA END OF lt_data.

TYPES: BEGIN OF mtt_tab.

*         INCLUDE STRUCTURE ZKLST_sflight.  " I get error that I cannot use ref to abap dic

           INCLUDE TYPE ZKSLT_SFLIGHT.

           TYPES: cellcolors  TYPE lvc_t_scol ,

             END OF mtt_tab.


After making type mtt_tab


i declare data   lt_tab                    TYPE STANDARD TABLE OF  mtt_tab.



and when I try to copy table mt_sflight (it is atribut of calss) like below


LOOP AT mt_sflight INTO ls_mt .

*   READ TABLE lt_tab INDEX sy-tabix ASSIGNING <ls_tab>.

*   MOVE-CORRESPONDING <ls_mt> TO <ls_tab>.

*    UPDATE lt_tab FROM TABLE mt_sflight.

     MOVE-CORRESPONDING ls_mt to lt_tab.

   ENDLOOP.


I am getting error "lt_tab is not internal str or table with header"


Can you help me with this? 

0 Kudos

Hi,

you need a workarea, for example

wa_mttab type mttab.

There you can move your data with move-corresponding, after that you can append this workarea to table lt_tab..

Regards,

Klaus