REPORT ZHANGTEST.
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_data,
key(10),
n TYPE i,
text TYPE c LENGTH 50,
color_cell TYPE slis_t_specialcol_alv, " Cell color
END OF ty_data.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
gt_sort TYPE slis_t_sortinfo_alv,
gs_layout TYPE slis_layout_alv.
DATA: gt_data TYPE TABLE OF ty_data WITH KEY key WITH HEADER LINE.
*---------------------------------------------------------------------*
INITIALIZATION.
PERFORM e01_fieldcat_init CHANGING gt_fieldcat[].
PERFORM e02_layout_sort_build CHANGING gt_sort.
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM selection.
*---------------------------------------------------------------------*
END-OF-SELECTION.
gs_layout-zebra = 'X'.
* gs_layout-COLWIDTH_OPTIMIZE = 'X'.
gs_layout-coltab_fieldname = 'COLOR_CELL'.
gs_layout-subtotals_text = '小計:'.
* CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
it_sort = gt_sort[]
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
*---------------------------------------------------------------------*
* --> E01_LT_FIELDCAT *
*---------------------------------------------------------------------*
FORM e01_fieldcat_init CHANGING e01_lt_fieldcat TYPE slis_t_fieldcat_alv
.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
* Key
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'KEY'.
ls_fieldcat-tabname = 'GT_DATA'.
ls_fieldcat-reptext_ddic = 'KEY'.
ls_fieldcat-outputlen = 10.
APPEND ls_fieldcat TO e01_lt_fieldcat.
* Test number
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'N'.
ls_fieldcat-tabname = 'GT_DATA'.
ls_fieldcat-reptext_ddic = 'Num#'.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-outputlen = 10.
APPEND ls_fieldcat TO e01_lt_fieldcat.
* Text
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TEXT'.
ls_fieldcat-tabname = 'GT_DATA'.
ls_fieldcat-reptext_ddic = 'Text'.
ls_fieldcat-outputlen = 40.
APPEND ls_fieldcat TO e01_lt_fieldcat.
ENDFORM. "e01_fieldcat_init
*&---------------------------------------------------------------------*
*& Form e02layout_sort_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->LT_SORT text
*----------------------------------------------------------------------*
FORM e02_layout_sort_build CHANGING lt_sort TYPE slis_t_sortinfo_alv.
DATA ls_sort TYPE slis_sortinfo_alv.
* Key
CLEAR ls_sort.
ls_sort-fieldname = 'KEY'.
ls_sort-spos = 1.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO lt_sort.
* CLEAR ls_sort.
* ls_sort-fieldname = 'N'.
* ls_sort-spos = 1.
* ls_sort-up = 'X'.
* ls_sort-subtot = 'X'.
* APPEND ls_sort TO lt_sort.
ENDFORM. " e02_LAYOUT_sort_build
*---------------------------------------------------------------------*
* FORM SELECTION *
*---------------------------------------------------------------------*
* *
*---------------------------------------------------------------------*
FORM selection.
gt_data-key = 'Group 1'. gt_data-n = 19734. gt_data-text = 'Mat 1'.
APPEND gt_data.
gt_data-key = 'Group 2'. gt_data-n = 20001. gt_data-text = 'Mat 2'.
APPEND gt_data.
gt_data-key = 'Group 1'. gt_data-n = 22001. gt_data-text = 'Mat 3'.
APPEND gt_data.
gt_data-key = 'Group 1'. gt_data-n = 2200. gt_data-text = 'Mat 4'.
APPEND gt_data.
gt_data-key = 'Group 2'. gt_data-n = 10001. gt_data-text = 'MAt 5'.
APPEND gt_data.
* FIELD-SYMBOLS <data> LIKE LINE OF gt_data.
* DATA: ls_color TYPE slis_specialcol_alv,
* red_color TYPE slis_t_specialcol_alv,
* green_color TYPE slis_t_specialcol_alv.
*
* ls_color-fieldname = 'N'. ls_color-color-int = '0'.
* ls_color-color-inv = '1'.
* ls_color-color-col = '6'. APPEND ls_color TO red_color.
* ls_color-color-col = '5'. APPEND ls_color TO green_color.
ENDFORM. "selection