06/08/2010

Colors in REUSE_ALV_GRID_DISPLAY_LVC


REPORT ZRRSAMPLE.

*&---------------------------------------------------------------------*
* type pools
*----------------------------------------------------------------------*
TYPE-POOLS: slis.

*&---------------------------------------------------------------------*
* declarations for alv and internal tables
*----------------------------------------------------------------------*
DATA: it_fieldcat TYPE lvc_t_fcat,
wa_fieldcat TYPE lvc_s_fcat,
wa_layout TYPE lvc_s_layo,
v_position TYPE i ,
ls_cellcolor TYPE lvc_s_scol,
l_index TYPE sy-tabix.

DATA: BEGIN OF it_spfli OCCURS 0,
carrid LIKE spfli-carrid,
connid LIKE spfli-connid,
cellcolor TYPE lvc_t_scol,
END OF it_spfli.

*&---------------------------------------------------------------------*
* start of selection
*----------------------------------------------------------------------*
START-OF-SELECTION .

*---get data from db table
PERFORM get_data .

*---build layout for alv
PERFORM build_layout .

*---build fieldcat for alv
PERFORM build_fieldcat .

*---modify fieldcat for colors in alv
PERFORM modify_fieldcat .

*---display alv
PERFORM display_alv .

*&---------------------------------------------------------------------*
*& Form get_data
*----------------------------------------------------------------------*
FORM get_data .

SELECT carrid
connid
UP TO 25 ROWS
INTO CORRESPONDING FIELDS OF TABLE it_spfli
FROM spfli.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form build_fieldcat
*----------------------------------------------------------------------*
FORM build_fieldcat .

wa_fieldcat-fieldname = 'CARRID'.
wa_fieldcat-reptext = 'CARRID'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'CONNID'.
wa_fieldcat-reptext = 'CONNID'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

ENDFORM. " build_fieldcat
*&---------------------------------------------------------------------*
*& Form build_layout
*----------------------------------------------------------------------*
FORM build_layout .

wa_layout-ctab_fname = 'CELLCOLOR'.
wa_layout-zebra = 'X'.

ENDFORM. " build_layout
*&---------------------------------------------------------------------*
*& Form modify_fieldcat
*----------------------------------------------------------------------*
FORM modify_fieldcat .

LOOP AT it_spfli.

l_index = sy-tabix.

IF l_index = 5 OR l_index = 15.

ls_cellcolor-fname = 'CARRID'.
ls_cellcolor-color-col = '6'.
ls_cellcolor-color-int = '1'.

APPEND ls_cellcolor TO it_spfli-cellcolor.

MODIFY it_spfli INDEX l_index TRANSPORTING cellcolor.

ENDIF.

IF l_index = 10 OR l_index = 20.

ls_cellcolor-fname = 'CONNID'.
ls_cellcolor-color-col = '4'.
ls_cellcolor-color-int = '1'.

APPEND ls_cellcolor TO it_spfli-cellcolor.

MODIFY it_spfli INDEX l_index TRANSPORTING cellcolor.

ENDIF.

IF it_spfli-carrid IS INITIAL .

DELETE it_spfli.

ENDIF.

ENDLOOP.

ENDFORM. " modify_fieldcat
*&---------------------------------------------------------------------*
*& Form display_alv
*----------------------------------------------------------------------*
FORM display_alv .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
is_layout_lvc = wa_layout
it_fieldcat_lvc = it_fieldcat
TABLES
t_outtab = it_spfli.

ENDFORM. " display_alv

Nenhum comentário:

Postar um comentário