在系統標準程序下,有很多屏幕在檢查或過賬時會彈出一個小型的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.
public section.
class-methods:
on_close for event close of cl_gui_dialogbox_container importing sender.
endclass.
class lcl_event_handler implementation.
method on_close.
call method sender->free.
free:
box_container, box_alv.
endmethod.
endclass.
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到屏幕的辦法,以下:oop
(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.