09-22-2008 3:19 PM
Hi,
for a new report i´m planing to use the "new" ALV object model to create the ALV list. Now I´ve got two questions concerning this topic:
- is it possible to switch the ALV into the edit mode like it´s possible if the "old" CL_GUI_ALV_GRID class
is used?
- how I can encolor specific cells?
I couldn´t find any hints or demo programms for these questions
Regards,
Andy
09-22-2008 3:45 PM
It is not possible to do an editable ALV with the ALV object model. You can color a line or a cell like this.
REPORT zrich_0001.
TYPE-POOLS: icon, col.
TYPES: BEGIN OF t_t000.
INCLUDE STRUCTURE t000.
TYPES: lt_colors TYPE lvc_t_scol.
TYPES: END OF t_t000.
DATA: lt_t000 TYPE TABLE OF t_t000.
DATA: ls_t000 LIKE LINE OF lt_t000.
DATA: ls_colors LIKE LINE OF ls_t000-lt_colors.
DATA: gr_alv TYPE REF TO cl_salv_table.
DATA: gr_columns TYPE REF TO cl_salv_columns_table.
START-OF-SELECTION.
* retrieve data into internal table
SELECT * FROM t000
INTO CORRESPONDING FIELDS OF TABLE lt_t000.
* Color a line
LOOP AT lt_t000 INTO ls_t000.
IF sy-tabix = 1.
CLEAR ls_colors.
*Leave FNAME blank, it will color the line, give a field name like MANDT, *it will color that cell of the line only.
ls_colors-fname = ''. "'MANDT'.
ls_colors-color-col = col_positive.
ls_colors-color-int = 1.
APPEND ls_colors TO ls_t000-lt_colors.
ENDIF.
MODIFY lt_t000 FROM ls_t000.
ENDLOOP.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_alv
CHANGING
t_table = lt_t000 ).
gr_columns = gr_alv->get_columns( ).
gr_columns->set_color_column( value = 'LT_COLORS' ).
gr_alv->display( ).
Regards,.
Rich Heilman
09-22-2008 3:45 PM
It is not possible to do an editable ALV with the ALV object model. You can color a line or a cell like this.
REPORT zrich_0001.
TYPE-POOLS: icon, col.
TYPES: BEGIN OF t_t000.
INCLUDE STRUCTURE t000.
TYPES: lt_colors TYPE lvc_t_scol.
TYPES: END OF t_t000.
DATA: lt_t000 TYPE TABLE OF t_t000.
DATA: ls_t000 LIKE LINE OF lt_t000.
DATA: ls_colors LIKE LINE OF ls_t000-lt_colors.
DATA: gr_alv TYPE REF TO cl_salv_table.
DATA: gr_columns TYPE REF TO cl_salv_columns_table.
START-OF-SELECTION.
* retrieve data into internal table
SELECT * FROM t000
INTO CORRESPONDING FIELDS OF TABLE lt_t000.
* Color a line
LOOP AT lt_t000 INTO ls_t000.
IF sy-tabix = 1.
CLEAR ls_colors.
*Leave FNAME blank, it will color the line, give a field name like MANDT, *it will color that cell of the line only.
ls_colors-fname = ''. "'MANDT'.
ls_colors-color-col = col_positive.
ls_colors-color-int = 1.
APPEND ls_colors TO ls_t000-lt_colors.
ENDIF.
MODIFY lt_t000 FROM ls_t000.
ENDLOOP.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_alv
CHANGING
t_table = lt_t000 ).
gr_columns = gr_alv->get_columns( ).
gr_columns->set_color_column( value = 'LT_COLORS' ).
gr_alv->display( ).
Regards,.
Rich Heilman
09-22-2008 3:56 PM
it is not possible to Edit the ALV using Object Model.
For coloring...check this code.
DATA: alv TYPE REF TO cl_salv_table.
TYPES: BEGIN OF ty_tab,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
color TYPE lvc_t_scol,
END OF ty_tab.
DATA: wt_color TYPE lvc_t_scol,
wa_color TYPE lvc_s_scol,
w_color TYPE lvc_s_colo.
DATA: wa_flight TYPE ty_tab.
DATA: column_tab TYPE REF TO cl_salv_columns_table,
column TYPE REF TO cl_salv_column_table.
DATA: column_ref TYPE salv_t_column_ref,
wa LIKE LINE OF column_ref.
DATA: it_flight TYPE STANDARD TABLE OF ty_tab.
SELECT carrid connid FROM sflight
INTO CORRESPONDING FIELDS OF TABLE it_flight
UP TO 10 ROWS.
*
w_color-col = 4.
w_color-int = 0.
w_color-inv = 0.
LOOP AT it_flight INTO wa_flight.
w_color-col = 4.
wa_color-fname = 'CARRID'.
wa_color-color = w_color.
APPEND wa_color TO wt_color.
w_color-col = 6.
wa_color-fname = 'CONNID'.
wa_color-color = w_color.
APPEND wa_color TO wt_color.
wa_flight-color = wt_color.
MODIFY it_flight FROM wa_flight.
ENDLOOP.
cl_salv_table=>factory(
IMPORTING
r_salv_table = alv
CHANGING
t_table = it_flight
).
"get all the columns
column_tab = alv->get_columns( ).
column_tab->set_color_column( value = 'COLOR' ).
column_ref = column_tab->get( ).
"loop each column
LOOP AT column_ref INTO wa.
"Conditionally set the column type as key or non key
IF wa-columnname = 'CARRID'.
column ?= wa-r_column.
column->set_key( abap_true ).
ENDIF.
ENDLOOP.
alv->display( ).
09-23-2008 7:26 AM
Hi guys,
thanks for your responses. I´m wondering why SAP doesn´t support the editing functionality with the ALV Object Model, but ok. It is like it is.
Regards,
Andy