[OO ALV] OO ALV 基础显示
程序代码
REPORT z437_test_2025.
DATA gt_spfli TYPE STANDARD TABLE OF spfli. " 内表
DATA go_alv TYPE REF TO cl_gui_alv_grid. " 创建和管理ALV表格
DATA gs_layout TYPE lvc_s_layo. " 存储ALV表格的布局信息
*----------------------------------------------------------------------*
* DESC: INITIALIZATION 事件
*----------------------------------------------------------------------*
INITIALIZATION.
sy-title = 'OO ALV 基础显示'. " 设置报表标题
*----------------------------------------------------------------------*
* DESC: AT SELECTION-SCREEN OUTPUT 事件
*----------------------------------------------------------------------*
START-OF-SELECTION.
SELECT * FROM spfli
INTO TABLE gt_spfli
UP TO 30 ROWS.
CREATE OBJECT go_alv
EXPORTING
i_parent = cl_gui_container=>default_screen. " 默认屏幕
CLEAR gs_layout.
gs_layout-zebra = 'X'. " 斑马线
gs_layout-cwidth_opt = 'X'. " 自适应列宽
" 将内表gt_spfli中的数据显示在ALV表格中
CALL METHOD go_alv->set_table_for_first_display
EXPORTING
is_layout = gs_layout
i_structure_name = 'SPFLI'
CHANGING
it_outtab = gt_spfli.
cl_abap_list_layout=>suppress_toolbar( ). " 隐藏标准的工具栏
WRITE space.
呈现结果: