ALV顯示OO實現(摘)
ALV用OO方式實現,似乎沒有function好用,但是可以再一個螢幕上顯示兩個ALV。程式碼例子如下:
全域性資料:
DATA : obj_wcl_container TYPE REF TO cl_gui_custom_container, "控制容器類
lt_f4 TYPE lvc_t_f4,
ls_f4 TYPE lvc_s_f4,
obj_wcl_alv TYPE REF TO cl_gui_alv_grid . "ALV控制類
alv顯示:
FORM. frm_alv_display USING gt_list LIKE gt_list.
DATA : ls_variant TYPE disvariant .
*--- 存放欄位目錄的內表
DATA lt_fieldcat TYPE lvc_t_fcat .
*--- 佈局結構
DATA ls_layout TYPE lvc_s_layo .
DATA: lt_exclude TYPE ui_functions. "alv不需要的圖示按鈕
ls_variant-report = sy-repid.
IF obj_wcl_alv IS INITIAL .
CREATE OBJECT: obj_wcl_container
EXPORTING
container_name = 'OBJ_WCL_CONTAINER'.
“螢幕上要有一個定製的容器,名字必須大寫為OBJ_WCL_CONTAINER
CREATE OBJECT obj_wcl_alv
EXPORTING
i_parent = obj_wcl_container.
*-----分配雙擊事件
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_double_click
FOR obj_wcl_alv.
ENDIF .
*-----消除按鈕
PERFORM. exclude_tb_functions CHANGING lt_exclude.
*-----設定欄位
PERFORM. prepare_field_catalog CHANGING lt_fieldcat .
*-----設定佈局
PERFORM. prepare_layout CHANGING ls_layout .
CALL METHOD obj_wcl_alv->register_f4_for_fields
EXPORTING
it_f4 = lt_f4.
*-----顯示ALV
CALL METHOD obj_wcl_alv->set_table_for_first_display
EXPORTING
is_variant = ls_variant
is_layout = ls_layout
i_save = 'A'
it_toolbar_excluding = lt_exclude
CHANGING
it_outtab = gt_list[]
it_fieldcatalog = lt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM. " FRM_ALV_DISPLAY
消除按鈕:
FORM. exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_check.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
APPEND ls_exclude TO pt_exclude.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
設定欄位:
FORM. prepare_field_catalog CHANGING ct_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat .
REFRESH ct_fieldcat .
CLEAR ls_fcat .
ls_fcat-fieldname = 'SELECTED' .
ls_fcat-coltext = '選擇'.
ls_fcat-outputlen = 2.
ls_fcat-checkbox = 'X' .
ls_fcat-edit = 'X' .
ls_fcat-key = 'X' .
APPEND ls_fcat TO ct_fieldcat .
init ls_fcat 'INFO_TYPE_CODE' ct_fieldcat '金稅發票型別程式碼' 12 'X'.
init ls_fcat 'INFO_NUMBER' ct_fieldcat '金稅發票號碼' 12 'X'.
init ls_fcat 'SERIAL_NUMBER' ct_fieldcat '流水號' 12 'X'.
init ls_fcat 'UPDATE_DATE' ct_fieldcat '發票日期' 8 ''.
init ls_fcat 'CLIENT_NAME' ct_fieldcat '購方名稱' 30 ''.
init ls_fcat 'SELLER_NAME' ct_fieldcat '銷方名稱' 30 ''.
ENDFORM. " PREPARE_FIELD_CATALOG
設定佈局:
FORM. prepare_layout CHANGING cs_layout TYPE lvc_s_layo.
cs_layout-zebra = 'X' .
cs_layout-grid_title = '列印正負銷貨清單' .
cs_layout-smalltitle = 'X' .
cs_layout-edit_mode = 'X' .
cs_layout-edit = '' .
cs_layout-cwidth_opt = 'X' .
ENDFORM. " PREPARE_LAYOUT
在PAI事件中如果有全選可取消全選:
form. FRM_SELECT_ALL .
data: ls_list like line of gt_list .
loop at gt_list into ls_list.
MOVE 'X' TO ls_list-selected.
MODIFY gt_list FROM ls_list INDEX sy-tabix TRANSPORTING selected.
endloop.
* call method obj_wcl_alv->refresh_table_display.
endform. " FRM_SELECT_ALL
如果有雙擊事件需要註冊雙擊事件,和自己寫實現程式碼。
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row.
ENDCLASS. "lcl_event_receiver DEFINITION
*&---------------------------------------------------------------------*
*& 雙擊事件的實現
*&---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_double_click.
DATA wa_bkpf LIKE LINE OF gt_list.
READ TABLE gt_list INTO wa_bkpf INDEX e_row-index. "讀取當前行
"進入發票
SET PARAMETER ID 'VF' FIELD wa_bkpf-vbeln.
CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
ENDMETHOD. "catch_doubleclick
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
常見錯誤:
1.alv在螢幕上不顯示!
一定要在螢幕裡畫上一個custom且名字是容器的名字,要大寫!OBJ_WCL_CONTAINER
2.核取方塊不起作用
核取方塊選擇了全選之後沒有全選,因為在pai之後接著會pbo,我把取數寫進了pbo中這樣核取方塊欄位就被覆蓋更新了。還有一種情況就是欄位名寫錯了,但是系統並沒有報錯。注意還要用下面的方法更新:
form. FRM_RENEW_DATA_1001 .
DATA: l_valid TYPE c .
***更新內表中的選擇標記位
CALL METHOD obj_wcl_alv->check_changed_data
IMPORTING
e_valid = l_valid.
endform.
DEFINE init .
*&1 structure
*&2 fieldname
*&3 tabname
*&4 seletext_m
*&5 outputlen
clear &1 .
&1-fieldname = &2 .
* &1-tabname = &3.
&1-coltext = &4.
&1-outputlen = &5.
&1-no_zero = 'X' .
&1-key = &6 .
append &1 to &3 .
END-OF-DEFINITION .
退出命令,注意要設定為E。
module exit at exit-command.
IF g_ok_code = 'BACK' .
SET SCREEN 0.
LEAVE SCREEN.
endif .
全域性資料:
DATA : obj_wcl_container TYPE REF TO cl_gui_custom_container, "控制容器類
lt_f4 TYPE lvc_t_f4,
ls_f4 TYPE lvc_s_f4,
obj_wcl_alv TYPE REF TO cl_gui_alv_grid . "ALV控制類
alv顯示:
FORM. frm_alv_display USING gt_list LIKE gt_list.
DATA : ls_variant TYPE disvariant .
*--- 存放欄位目錄的內表
DATA lt_fieldcat TYPE lvc_t_fcat .
*--- 佈局結構
DATA ls_layout TYPE lvc_s_layo .
DATA: lt_exclude TYPE ui_functions. "alv不需要的圖示按鈕
ls_variant-report = sy-repid.
IF obj_wcl_alv IS INITIAL .
CREATE OBJECT: obj_wcl_container
EXPORTING
container_name = 'OBJ_WCL_CONTAINER'.
“螢幕上要有一個定製的容器,名字必須大寫為OBJ_WCL_CONTAINER
CREATE OBJECT obj_wcl_alv
EXPORTING
i_parent = obj_wcl_container.
*-----分配雙擊事件
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_double_click
FOR obj_wcl_alv.
ENDIF .
*-----消除按鈕
PERFORM. exclude_tb_functions CHANGING lt_exclude.
*-----設定欄位
PERFORM. prepare_field_catalog CHANGING lt_fieldcat .
*-----設定佈局
PERFORM. prepare_layout CHANGING ls_layout .
CALL METHOD obj_wcl_alv->register_f4_for_fields
EXPORTING
it_f4 = lt_f4.
*-----顯示ALV
CALL METHOD obj_wcl_alv->set_table_for_first_display
EXPORTING
is_variant = ls_variant
is_layout = ls_layout
i_save = 'A'
it_toolbar_excluding = lt_exclude
CHANGING
it_outtab = gt_list[]
it_fieldcatalog = lt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM. " FRM_ALV_DISPLAY
消除按鈕:
FORM. exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_check.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
APPEND ls_exclude TO pt_exclude.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
設定欄位:
FORM. prepare_field_catalog CHANGING ct_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat .
REFRESH ct_fieldcat .
CLEAR ls_fcat .
ls_fcat-fieldname = 'SELECTED' .
ls_fcat-coltext = '選擇'.
ls_fcat-outputlen = 2.
ls_fcat-checkbox = 'X' .
ls_fcat-edit = 'X' .
ls_fcat-key = 'X' .
APPEND ls_fcat TO ct_fieldcat .
init ls_fcat 'INFO_TYPE_CODE' ct_fieldcat '金稅發票型別程式碼' 12 'X'.
init ls_fcat 'INFO_NUMBER' ct_fieldcat '金稅發票號碼' 12 'X'.
init ls_fcat 'SERIAL_NUMBER' ct_fieldcat '流水號' 12 'X'.
init ls_fcat 'UPDATE_DATE' ct_fieldcat '發票日期' 8 ''.
init ls_fcat 'CLIENT_NAME' ct_fieldcat '購方名稱' 30 ''.
init ls_fcat 'SELLER_NAME' ct_fieldcat '銷方名稱' 30 ''.
ENDFORM. " PREPARE_FIELD_CATALOG
設定佈局:
FORM. prepare_layout CHANGING cs_layout TYPE lvc_s_layo.
cs_layout-zebra = 'X' .
cs_layout-grid_title = '列印正負銷貨清單' .
cs_layout-smalltitle = 'X' .
cs_layout-edit_mode = 'X' .
cs_layout-edit = '' .
cs_layout-cwidth_opt = 'X' .
ENDFORM. " PREPARE_LAYOUT
在PAI事件中如果有全選可取消全選:
form. FRM_SELECT_ALL .
data: ls_list like line of gt_list .
loop at gt_list into ls_list.
MOVE 'X' TO ls_list-selected.
MODIFY gt_list FROM ls_list INDEX sy-tabix TRANSPORTING selected.
endloop.
* call method obj_wcl_alv->refresh_table_display.
endform. " FRM_SELECT_ALL
如果有雙擊事件需要註冊雙擊事件,和自己寫實現程式碼。
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row.
ENDCLASS. "lcl_event_receiver DEFINITION
*&---------------------------------------------------------------------*
*& 雙擊事件的實現
*&---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_double_click.
DATA wa_bkpf LIKE LINE OF gt_list.
READ TABLE gt_list INTO wa_bkpf INDEX e_row-index. "讀取當前行
"進入發票
SET PARAMETER ID 'VF' FIELD wa_bkpf-vbeln.
CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
ENDMETHOD. "catch_doubleclick
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
常見錯誤:
1.alv在螢幕上不顯示!
一定要在螢幕裡畫上一個custom且名字是容器的名字,要大寫!OBJ_WCL_CONTAINER
2.核取方塊不起作用
核取方塊選擇了全選之後沒有全選,因為在pai之後接著會pbo,我把取數寫進了pbo中這樣核取方塊欄位就被覆蓋更新了。還有一種情況就是欄位名寫錯了,但是系統並沒有報錯。注意還要用下面的方法更新:
form. FRM_RENEW_DATA_1001 .
DATA: l_valid TYPE c .
***更新內表中的選擇標記位
CALL METHOD obj_wcl_alv->check_changed_data
IMPORTING
e_valid = l_valid.
endform.
DEFINE init .
*&1 structure
*&2 fieldname
*&3 tabname
*&4 seletext_m
*&5 outputlen
clear &1 .
&1-fieldname = &2 .
* &1-tabname = &3.
&1-coltext = &4.
&1-outputlen = &5.
&1-no_zero = 'X' .
&1-key = &6 .
append &1 to &3 .
END-OF-DEFINITION .
退出命令,注意要設定為E。
module exit at exit-command.
IF g_ok_code = 'BACK' .
SET SCREEN 0.
LEAVE SCREEN.
endif .
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16794144/viewspace-623625/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 動態的實現任意表的ALV顯示02
- 動態的實現任意表的ALV顯示01
- function ALV 獲取OO ALV event IDFunction
- alv動態顯示列
- ALV1:使用函式顯示ALV格式報表函式
- OO ALV 訪問保護類方法 實現欄位報錯紅框定位
- SAP ABAP 動態內表實現 ALV橫向按月份動態顯示資料
- 【轉載】ALV的Excel方式顯示缺少模板Excel
- OO ALV 強制觸發 data_change事件事件
- 動態內表及動態ALV顯示(轉)
- Geoserver + MySQL實現圖層顯示和文字顯示ServerMySql
- CSS實現限制顯示的字數,超出顯示"..."CSS
- function模式設定ALV用彈出視窗顯示Function模式
- ALV報表不能正確顯示資料問題
- SAP ALV小數點後面如果為0不顯示
- ALV示例---Dyoprn實現,一個容器中嵌入ALV報表
- jQuery 實現顯示與隱藏效果jQuery
- ExpandableListView實現二級列表的顯示View
- 如何在 SAPGUI 的同一個螢幕顯示兩個 ALV listGUI
- php怎麼實現定位地圖顯示PHP地圖
- PLSQL實現顯示當天是星期幾SQL
- 如何實現網頁文字原格式顯示網頁
- java web實現分頁顯示資料JavaWeb
- 八、Qt Creator實現狀態列顯示QT
- 關於逐步顯示資料如何實現
- 程式介面多模式顯示的實現 (轉)模式
- Layer.js實現表格溢位內容省略號顯示,懸停顯示全部JS
- 直播系統開發,實現在進度條中顯示文字顯示進度
- QLabel顯示圖片 ,並實現縮放
- django 實現圖片上傳和顯示操作Django
- 手機實現1畫素邊框顯示
- QT實現動態顯示系統時間QT
- css3實現多個元素依次顯示CSSS3
- CSS實現超出文字以省略號顯示CSS
- Qt 實現 Logger 日誌的顯示QT
- 超越現實 虛擬現實頭戴顯示器是如何工作的
- css 實現div內顯示兩行或三行,超出部分用省略號顯示CSS
- [安卓] 16、ListView和GridView結合顯示單元實現自定義列表顯示效果安卓View