2014 Jun 05 7:05 AM
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.
2014 Jun 05 7:37 AM
Hi Krzysztof,
if you want to change color of a single field in a single line of ALV, then you need
To fill the table use structure LVC_S_SCOL and fill
Regards,
Klaus
2014 Jun 05 7:17 AM
In the handling method
Regards,
Raymond
2014 Jun 05 7:29 AM
2014 Jun 05 7:43 AM
"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
2014 Jun 05 7:37 AM
Hi Krzysztof,
if you want to change color of a single field in a single line of ALV, then you need
To fill the table use structure LVC_S_SCOL and fill
Regards,
Klaus
2014 Jun 05 8:20 AM
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
2014 Jun 05 10:08 AM
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?
2014 Jun 05 10:18 AM
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