在系统标准程序下,有不少屏幕在检查或过帐时会弹出一个小型的ALV窗口,上面记录着错误信息,这种ALV弹出式窗口可通过以下方法做成:
(1)定义ALVBOX
DATA:box_container TYPE REF TO cl_gui_dialogbox_container,
box_alv TYPE REF TO cl_gui_alv_grid.
*-------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*-------------------------------------------------------------------*
*
*-------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: on_close FOR EVENT close OF
cl_gui_dialogbox_container IMPORTING sender.
ENDCLASS. "lcl_event_handler DEFINITION
*-------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*-------------------------------------------------------------------*
*
*-------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_close.
CALL METHOD sender->free.
FREE: box_container, box_alv.
ENDMETHOD. "on_close
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA: ls_fcat TYPE lvc_s_fcat, "ALV的fieldcat属性行
lt_fieldcat TYPE lvc_t_fcat. "ALV的fieldcat属性内表
DATA: ls_layout TYPE lvc_s_layo. " ALV的layout属性内表
可双击父类lvc_t_fcat、lvc_s_layo来查看所包含的属性
(2)建立ALV对象
CREATE OBJECT box_container
EXPORTING
width = 600 "窗口大小
height = 200
top = 120
left = 120
caption = '提示信息' "弹出窗口标题
EXCEPTIONS
OTHERS = 1.
SET HANDLER lcl_event_handler=>on_close FOR box_container.
CREATE OBJECT box_alv
EXPORTING
i_parent = box_container
EXCEPTIONS
OTHERS = 1.
(3)输出ALV的fieldcat属性和layout属性
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZSTAB' "输出格式对应的结构
CHANGING
ct_fieldcat = lt_fieldcat "ALV的fieldcat属性内表
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
注:要事先在se11创建一个和ALV输出字段一致的结构ZSTAB;
"写入fieldcat的属性
LOOP AT lt_fieldcat INTO ls_fcat.
ls_fcat-icon = 'X'.
...
MODIFY lt_fieldcat FROM ls_fcat.
ENDLOOP.
"写入layout属性
ls_layout-cwidth_opt = 'X'.
...
(4)调用方法显示ALV窗口
CALL METHOD box_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'ZBGER' "输出格式对应的结构
is_layout = ls_layout "layout属性
i_default = 'X'
CHANGING
it_outtab = itab "内表
it_fieldcatalog = lt_fieldcat "fieldcat属性
EXCEPTIONS
OTHERS = 1.
弹出式窗口另外做法:可使用write到屏幕的办法,如下:
(1)在程序中创建一个screen type 为“方式对话框”的屏幕;
(2)在屏幕输出前,write要输出的数据:
process before output.
modiule frm_write_out.
(3)在module里写输出到屏幕的代码
MODULE frm_write_out OUTPUT.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
NEW-PAGE NO-TITLE.
WRITE ...
LEAVE SCREEN.
ENDMODULE. "frm_write_out OUTPUT