ALV式的彈出視窗
阿新 • • 發佈:2019-01-08
在系統標準程式下,有不少螢幕在檢查或過帳時會彈出一個小型的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到螢幕的辦法,如下:
(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.