ALV小计项目设定

 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值