Introduction
Class: ZCL_QALV_DISPLAY
- ALV簡化用法(純Display,不可進edit mode)
History
Version | Date | Name | Description |
---|---|---|---|
V001 | 2020/10/13 | Huang Roy | 初版 |
V002 | 2020/11/30 | Huang Roy | Event新增動態call method |
V003 | 2020/12/24 | Huang Roy | 繼承ZCL_QALV method |
V004 | 2021/1/14 | Huang Roy | 新增預設sort & filter |
Public Method
GRID_TABNAME
- ALV Field Catalog from Table Name
- I_ALVID: 預設為 'QALV',一般情況下不需用不同值,但同一程式有多張報表時,記得要區分開(因ALV Variant是以Program Name + ALVID存檔)
- I_TITLE: 預設與SY-TITLE相同,可自行修改
- IS_LAYOUT: 需自訂才使用
- IS_VARIANT: 需自訂才使用
- IT_EXTOOL: 設定不使用的Toolbar function
- I_LEFT/I_TOP/I_RIGHT/I_BOTTOM: 視窗化顯示使用
- IS_EVENT: event register,後面範例再說明
- CT_OUT: 輸出資料
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_TABNAME | Importing | TABNAME | Table Name | |||
I_ALVID | Importing | X | SLIS_HANDL | C_DEFAULT_ALVID | ALV ID | |
I_TITLE | Importing | X | SYTITLE | SY-TITLE | Contents of Title Line | |
IS_LAYOUT | Importing | X | LVC_S_LAYO | ALV control | ||
IS_VARIANT | Importing | X | SLIS_VARI | Layout(HANDLE = ALV ID) | ||
IT_EXTOOL | Importing | X | UI_FUNCTIONS | Exclude ALV Toorbar | ||
IT_SORT | Importing | X | LVC_T_SORT | Default Sort V004 add | ||
IT_FILTER | Importing | X | LVC_T_FILT | Default Filter V004 add | ||
I_LEFT | Importing | X | I | Start Column | ||
I_TOP | Importing | X | I | Start Line | ||
I_RIGHT | Importing | X | I | End Column | ||
I_BOTTOM | Importing | X | I | End Line | ||
IS_EVENT | Importing | X | TY_EVENT | Register Event(FORM: _EVENT_<event name>) | ||
CT_OUT | Changing | STANDARD TABLE | Table for ALV output |
Sample
Click to Expand CodeDATA gt_spfli TYPE TABLE OF spfli.
START-OF-SELECTION.
SELECT *
INTO TABLE gt_spfli
FROM spfli.
zcl_qalv_display=>grid_tabname( EXPORTING i_tabname = 'SPFLI'
CHANGING ct_out = gt_spfli ).
GRID_ALVID
- ALV Field Catalog from table: ZTQALV_FCAT by ALVID
- 參數說明,參考Method: GRID_TABNAME
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_ALVID | Importing | X | SLIS_HANDL | C_DEFAULT_ALVID | ALV ID | |
I_TITLE | Importing | X | SYTITLE | SY-TITLE | Contents of Title Line | |
IS_LAYOUT | Importing | X | LVC_S_LAYO | ALV control | ||
IS_VARIANT | Importing | X | SLIS_VARI | Layout(HANDLE = ALV ID) | ||
IT_EXTOOL | Importing | X | UI_FUNCTIONS | Exclude ALV Toorbar | ||
IT_SORT | Importing | X | LVC_T_SORT | Default Sort V004 add | ||
IT_FILTER | Importing | X | LVC_T_FILT | Default Filter V004 add | ||
I_LEFT | Importing | X | I | Start Column | ||
I_TOP | Importing | X | I | Start Line | ||
I_RIGHT | Importing | X | I | End Column | ||
I_BOTTOM | Importing | X | I | End Line | ||
IS_EVENT | Importing | X | TY_EVENT | Register Event(FORM: _EVENT_<event name>) | ||
CT_OUT | Changing | STANDARD TABLE | Table for ALV output |
Sample
Click to Expand CodeDATA gt_spfli TYPE TABLE OF spfli.
START-OF-SELECTION.
SELECT *
INTO TABLE gt_spfli
FROM spfli.
zcl_qalv_display=>grid_alvid( CHANGING ct_out = gt_spfli ).
GRID_CUST
- Customize ALV Field Catalog
- CT_FCAT: 自訂Field Catalog
- 其他參數說明,參考Method: GRID_TABNAME
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_ALVID | Importing | X | SLIS_HANDL | C_DEFAULT_ALVID | ALV ID | |
I_TITLE | Importing | X | SYTITLE | SY-TITLE | Contents of Title Line | |
IS_LAYOUT | Importing | X | LVC_S_LAYO | ALV control | ||
IS_VARIANT | Importing | X | SLIS_VARI | Layout(HANDLE = ALV ID) | ||
IT_EXTOOL | Importing | X | UI_FUNCTIONS | Exclude ALV Toorbar | ||
IT_SORT | Importing | X | LVC_T_SORT | Default Sort V004 add | ||
IT_FILTER | Importing | X | LVC_T_FILT | Default Filter V004 add | ||
I_LEFT | Importing | X | I | Start Column | ||
I_TOP | Importing | X | I | Start Line | ||
I_RIGHT | Importing | X | I | End Column | ||
I_BOTTOM | Importing | X | I | End Line | ||
IS_EVENT | Importing | X | TY_EVENT | Register Event(FORM: _EVENT_<event name>) | ||
CT_OUT | Changing | STANDARD TABLE | Table for ALV output | |||
CT_FCAT | Changing | LVC_T_FCAT | Field Catalog for List Viewer Control |
Sample
Click to Expand CodeDATA: gt_spfli TYPE TABLE OF spfli,
gw_fcat TYPE lvc_s_fcat,
gt_fcat TYPE lvc_t_fcat.
START-OF-SELECTION.
SELECT *
INTO TABLE gt_spfli
FROM spfli.
gw_fcat-fieldname = 'CARRID'.
gw_fcat-coltext = 'Airline Code'.
APPEND gw_fcat TO gt_fcat.
gw_fcat-fieldname = 'AIRPFROM'.
gw_fcat-coltext = 'Departure airport'.
APPEND gw_fcat TO gt_fcat.
zcl_qalv_display=>grid_cust( CHANGING ct_out = gt_spfli
ct_fcat = gt_fcat ).
GET_VARIANT
- 依ALVID取得ALV Variant Name(Inherit from ZCL_QALV) V003 add
- ※Program使用SY-CPROG
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_ALVID | Importing | X | SLIS_HANDL | C_DEFAULT_ALVID | ALV ID | |
R_VARIANT | Returning | X | SLIS_VARI | ALV variant |
GET_FCAT_TABNAME
- 將Table or Structure轉為ALV Field Catalog(Inherit from ZCL_QALV) V003 add
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_TABNAME | Importing | TABNAME | Table Name | |||
RT_FCAT | Returning | X | LVC_T_FCAT | Field Catalog for List Viewer Control |
GET_FCAT_ALVID
- 依Program + ALVID取得ALV Field Catalog(Inherit from ZCL_QALV) V003 add
- 設定Table: ZTQALV_FCAT
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_PROG | Importing | X | PROGRAM_ID | SY-CPROG | Program Name | |
I_ALVID | Importing | X | SLIS_HANDL | C_DEFAULT_ALVID | ALV ID | |
RT_FCAT | Returning | X | LVC_T_FCAT | Field Catalog for List Viewer Control |
CONTAINER_FACTORY
- 產生Container物件,可忽略,Display沒開放使用(Inherit from ZCL_QALV) V003 add
EVENT
- 只把比較常用的event開放在此:
Event | Description |
---|---|
context_menu_request | 滑鼠右鍵 |
double_click | 雙擊滑鼠左鍵 |
hotspot_click | 點擊hotspot欄位 |
menu_button | 點擊自訂menu toolbar |
onf1 | 點擊F1 |
toolbar | ALV第一次進入,toolbar事件,可在此增加自訂按鈕 |
user_command | 點擊自訂按鈕 |
Sample
- 這裡以GRID_TABNAME執行double click動作說明,其他event使用方式一樣。
- IS_EVENT: 傳入需要註冊事件的清單(ABAP_TRUE)
- Trigger event兩種寫法,一種Class(V002 add), 一種Form(Class優先,不存在則使用Form)
- Local Class: 固定用lcl_grid_event,method使用event name(記得用public static method)
- FORM: 統一在event name前加上g_(GRID)。
- 尋找 Event Parameter: 至Class ZCL_QALV_GRID找到相對應event,即可找到傳入的參數(其實就是alvid加上原始event傳入參數,alvid用以輔助判斷目前trigger event的是哪個alv object)
CLASS
CLASS lcl_grid_event DEFINITION.
PUBLIC SECTION.
CLASS-METHODS double_click IMPORTING i_alvid TYPE any
is_row TYPE lvc_s_row
is_column TYPE lvc_s_col
is_row_no TYPE any.
ENDCLASS.
CLASS lcl_grid_event IMPLEMENTATION.
METHOD double_click.
DATA l_msg TYPE string.
l_msg = |ALVID: { i_alvid }, DoubleClick, Row: { is_row-index },| &&
| Column: { is_column-fieldname }|.
MESSAGE l_msg TYPE 'I'.
ENDMETHOD.
ENDCLASS.
DATA: gt_spfli TYPE TABLE OF spfli,
gw_event TYPE zcl_qalv_display=>ty_event.
START-OF-SELECTION.
SELECT *
INTO TABLE gt_spfli
FROM spfli.
gw_event-double_click = abap_true.
zcl_qalv_display=>grid_tabname( EXPORTING i_tabname = 'SPFLI'
is_event = gw_event
CHANGING ct_out = gt_spfli ).
FORM
DATA: gt_spfli TYPE TABLE OF spfli,
gw_event TYPE zcl_qalv_display=>ty_event.
START-OF-SELECTION.
SELECT *
INTO TABLE gt_spfli
FROM spfli.
gw_event-double_click = abap_true.
zcl_qalv_display=>grid_tabname( EXPORTING i_tabname = 'SPFLI'
is_event = gw_event
CHANGING ct_out = gt_spfli ).
FORM g_double_click USING alvid
e_row TYPE lvc_s_row
e_column TYPE lvc_s_col
es_row_no.
DATA l_msg TYPE string.
l_msg = |ALVID: { alvid }, DoubleClick, Row: { e_row-index },| &&
| Column: { e_column-fieldname }|.
MESSAGE l_msg TYPE 'I'.
ENDFORM.
技術提供: Gitea 版本: 1.15.5 頁面: 430ms 樣板: 0ms 繁體中文(台灣) 授權條款 API 網站 Go1.16.9 标签:event,gt,ZCL,ALVID,spfli,ALV,Importing,QALV,DISPLAY From: https://www.cnblogs.com/TYAING/p/17413562.html