REUSE_ALV_GRID_DISPLAY 函数使用

文章目录

1.背景

REUSE_ALV_GRID_DISPLAY 函数使用的demo, 这是一个标准的ALV显示函数,然后只是显示的字段是通过传递实现,以前我做的更多的是直接把字段给写出来.

2.代码
REPORT ZJGLTEST02.
TABLES:t001.
"Types
TYPES:
      BEGIN OF t_1001,
        bukrs TYPE t001-bukrs,
        butxt TYPE t001-butxt,
        ort01 TYPE t001-ort01,
        land1 TYPE t001-land1,
      END OF t_1001.
"Work area
DATA:
      w_t001 TYPE t_1001.
"Internal table
DATA:
      i_t001 TYPE STANDARD TABLE OF t_1001.

*&---------------------------------------------------------------------*
* ALV Declarations
*----------------------------------------------------------------------*
* Types Pools
TYPE-POOLS:
   slis.
* Types
TYPES:
   t_fieldcat         TYPE slis_fieldcat_alv,
   t_events           TYPE slis_alv_event,
   t_layout           TYPE slis_layout_alv.
* Workareas
DATA:
   w_fieldcat         TYPE t_fieldcat,
   w_events           TYPE t_events,
   w_layout           TYPE t_layout.
* Internal Tables
DATA:
   i_fieldcat         TYPE STANDARD TABLE OF t_fieldcat,
   i_events           TYPE STANDARD TABLE OF t_events.
*&---------------------------------------------------------------------*
*&    start of selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM get_data.

*&---------------------------------------------------------------------*
*&    end-of-selection.
*&---------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM build_fieldcatlog.
  PERFORM build_events.
  PERFORM build_layout.
  PERFORM list_display.
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
FORM get_data .

  SELECT bukrs
         butxt
         ort01
         land1
    FROM t001
    INTO TABLE i_t001
    UP TO 30 ROWS.

ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  build_fieldcatlog
*&---------------------------------------------------------------------*
FORM build_fieldcatlog .
  CLEAR:w_fieldcat,i_fieldcat[].

  PERFORM build_fcatalog USING:
           'BUKRS' 'I_T001' 'BUKRS',
           'BUTXT' 'I_T001' 'BUTXT',
           'ORT01' 'I_T001' 'ORT01',
           'LAND1' 'I_T001' 'LAND1'.

ENDFORM.                    "BUILD_FIELDCATLOG
*&---------------------------------------------------------------------*
*&      Form  BUILD_FCATALOG
*&---------------------------------------------------------------------*
FORM build_fcatalog USING l_field l_tab l_text.

  w_fieldcat-fieldname      = l_field.
  w_fieldcat-tabname        = l_tab.
  w_fieldcat-seltext_m      = l_text.

  APPEND w_fieldcat TO i_fieldcat.
  CLEAR w_fieldcat.

ENDFORM.                    " build_fieldcatlog
*&---------------------------------------------------------------------*
*&      Form  build_events
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM build_events.
  CLEAR :
        w_events, i_events[].
  w_events-name = 'TOP_OF_PAGE'."Event Name
  w_events-form = 'TOP_OF_PAGE'."Callback event subroutine
  APPEND w_events TO i_events.
  CLEAR  w_events.

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

  w_layout-colwidth_optimize = 'X'.
  w_layout-zebra             = 'X'.

ENDFORM.                    " build_layout
*&---------------------------------------------------------------------*
*&      Form  list_display
*&---------------------------------------------------------------------*
FORM list_display .
  DATA:
        l_program TYPE sy-repid.
  l_program = sy-repid.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = l_program
      is_layout          = w_layout
      it_fieldcat        = i_fieldcat
      it_events          = i_events
    TABLES
      t_outtab           = i_t001
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    " list_display
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
  DATA :
   li_header TYPE slis_t_listheader,
   w_header  LIKE LINE OF li_header.
  DATA:
        l_date TYPE char10.
  WRITE sy-datum TO l_date.
  w_header-typ  = 'H'.
  CONCATENATE sy-repid ':' 'From Date' l_date INTO w_header-info SEPARATED BY space.
  APPEND w_header TO li_header.
  CLEAR w_header.

  w_header-typ  = 'S'.
  w_header-info = sy-title.
  APPEND w_header TO li_header.
  CLEAR w_header.

  w_header-typ  = 'A'.
  w_header-info = sy-uname.
  APPEND w_header TO li_header.
  CLEAR w_header.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = li_header.

ENDFORM.     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值